- 1 year ago 82
PHP Question

Class 'AWeberAPI' not found

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

php code:

new PHPExcel;
new AWeberAPI;


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

Answer Source

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:

// 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';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download