client-php icon indicating copy to clipboard operation
client-php copied to clipboard

composer fails to autoload the class

Open javorszky opened this issue 10 years ago • 2 comments

I'm using (or rather trying to) implement everything that client-cli does, except... well, without the cli part.

I have pretty much everything working. Here's my composer.json file:

{
    "name": "javorszky/wp-oauth1",
    "description": "My feeble attempt at an oauth1 client",
    "require": {
        "wp-api/client": "dev-master",
        "rmccue/requests": "~1.6",
        "justinrainbow/json-schema": "dev-master",
        "markjaquith/wp-tlc-transients": "*"
    }
}

Everything installs fine. I'm trying to instantiate a new WPAPI;, but I get the error Fatal error: Class 'WPAPI' not found in /file.php line 1

The path to the file is: vendor/wp-api/client/library/WPAPI.php.

I tried to follow the flow in vendor/composer/ClassLoader.php, and while WPAPI is getting passed there, none of the tries match the file it would be in.

I'm not even sure this is an issue of WPAPI or composer, or a combination of, or I'm doing it wrong(:tm:)

Where do I start to debug this?

javorszky avatar Sep 16 '14 23:09 javorszky

This is the reduced test case: https://github.com/javorszky/composer-vs-wpapi

javorszky avatar Sep 17 '14 12:09 javorszky

Solved. I think.

In my composer.json file, this is needed:

"autoload": {
    "psr-0": {
        "": "vendor/wp-api/client/library"
    }
}

or alternatively this:

"autoload": {
    "classmap": ["vendor/wp-api/client/library"]
}

Doesn't seem to matter which one. The question is: why does WPAPI work with https://github.com/WP-API/client-cli given that there's no autoload prop in that composer.json file?

(Not closing this as I'd like some eyes on this whether this is indeed the solution, or I just happened to make it work for the time being with the help of others.)

javorszky avatar Sep 17 '14 13:09 javorszky