Reputation: 137
I am trying to autoload a file and my PSR-4 autoloading worked fine locally however now that I am deploying to a baremetal server. It is not working and PHP states that it can't find the autoloaded file. This is the current error:
Fatal error: Class 'Metabase\Models\Cron' not found in /usr/www/users/metabase/src/commands/ArticleFetchCron.php on line 25
My composer.json is as follows:
{
"require": {
"vlucas/phpdotenv": "^2.4",
"guzzlehttp/guzzle": "6.3",
"monolog/monolog": "^1.23",
"illuminate/http": "^5.7@dev"
},
"autoload": {
"psr-4": {"Metabase\\": "src/"}
}
}
The file that is having an issue is including the namespaces correctly as far as I know:
<?php
namespace Metabase\Commands;
// autoload composer
require_once(__DIR__ . '/../../vendor/autoload.php');
/**
* Class ArticleFetchCron
* @package Metabase\Commands
*/
use Metabase\Api\Requests\ArticleRequest;
use Metabase\Models\Cron;
use Metabase\Models\CronInterface;
use Metabase\Models\DatabaseAdapter;
class ArticleFetchCron extends Cron
implements CronInterface
I am just wondering if I have perhaps made a mistake with my composer.json file?
Upvotes: 3
Views: 1802
Reputation: 146588
The PSR-4 based class autoloader implemented by Composer, when asked to find Metabase\Models\Cron
, looks for a file called src\Models\Cron.php
. If your actual files are using a different case anywhere on the path such as src\models\Cron.php
you'll get different results depending on whether the underlying file system is case sensitive or not. The reason is simple:
If the file system is case sensitive it can physically contain two directories called src\models
and src\Models
and you're loading the wrong one.
If it isn't, both paths are actually identical to all effects.
Double-check file names and rebuild the autoloader with composer dump-autoload
.
Upvotes: 5