简体   繁体   中英

class not found exception on Lumen project in shared hosting

I have developed API using Lumen framework and using separately created composer package which I'm planning to use both on Lumen (API) and Laravel (Web site).

However I get:

Class 'Author\\Package\\Models\\ProductItem' not found

Locally everything is working (using same Apache and PHP version). My directory structure is:

|
\_ api (Lumen code)
|
\_ model\
|  \_ src\
|  |  \_ migrations\
|  |  |
|  |  \_ models\
|  |  | \_ ProductItem.php
|  |  |...
|  |
|  \_ composer.json
|
\_ www (Laravel code)

in api\\composer.json I have:

...
"autoload": {
    "psr-4": {
        "App\\": "app/",
        "Author\\Package\\": "../model/src"
    }
},
...

Only difference between local and hosting configuration is version of Composer (local is 1.5.2 and remote is 1.4.2).

Your namespace or your PSR-4 mapping is incorrect.

When your class contains Models with uppercase M in its namespace Author\\Package\\Models\\ProductItem it should be located in ./model/src/Models/ProductItem.php (also uppercase M). So both namespace and folder name must match exactly. On Windows/Mac this is usually not a problem, because the filesystem is case-insensitive, but on a Linux-based host this will cause problems.

Alternatively you can change your PSR-4 autoloader:

"autoload": {
    "psr-4": {
        "Author\\Package\\Models\\": "../model/src/models"
    }
}

You would have to do that for every directory that does not match your namespace.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM