am.am.coding am.am.coding - 3 months ago 23
PHP Question

Class 'AWeberAPI' not found

I got no clue why AWeberAPI is not found. Any help is appreciated.

php code:

require('vendor/autoload.php');
new PHPExcel;
new AWeberAPI;


composer.json:

{
"require": {
"aweber/aweber": "^1.1",
"phpoffice/phpexcel": "^1.8"
}
}

Answer

The problem

The module doesn't appear to be properly configured for use/autoloading with composer. They may have just added the composer configuration to allow you to easily install it, but not to use it within the composer autoloader.

The generic convention for it is that AWeberAPI should match the package's PSR-4 autoloader format, which says "look in aweber_api", then it will look for a class named AWeberAPI.php. You can test this behaviour is correct by adding this file:

<?php
// File: vendor/aweber/aweber/aweber_api/AWeberAPI.php
class AWeberAPI {
    public function __construct() {
        die('yeah, it works now...');
    }
}

Then try your script again, the class will exist now.


What can I do?

Well - you could submit a pull request to their repository to fix it, but it looks like it would involve renaming the classes and filenames which would be a breaking change so I probably wouldn't bother.

You can get it to work by requiring the actual source of the API library instead of the composer autoloader in this case:

require_once 'vendor/aweber/aweber/aweber_api/aweber_api.php';