Reputation: 873
I have external repository written in vanilla PHP which I want to use in my Symfony project the 'composer require' call works fine and all the files are loaded into the vendor directory. At run time I keep getting the following error.
Attempted to load class "FM" from namespace "MyRepo1\Src\Vendors\FM".
Did you forget a "use" statement for another namespace?
I thing it may be the composer.json of the PHP repository, included below.
{
"name" : "myUserName/MyRepo1",
"minimum-stability" : "dev",
"repositories" : [{
"type" : "git",
"url" : "https://github.com/myUserName/MyRepo2"
}
],
"require" : {
"myUserName/MyRepo2" : "*",
"php" : "^7.0"
},
"version" : "1.0.2",
"require-dev" : {
"phpunit/phpunit" : "5.5.*",
"squizlabs/php_codesniffer" : "2.*",
"mayflower/php-codebrowser" : "~1.1"
}
}
below is the FM class which is in the directory vendor/myUserName/MyRepo1/src/vendors tracking.interface and tracking.class are in the same directory
<?php
namespace MyRepo1\Src\Vendors\FM;
// : Includes
include_once (dirname(realpath(__FILE__)) . DIRECTORY_SEPARATOR . 'tracking.interface');
include_once (dirname(realpath(__FILE__)) . DIRECTORY_SEPARATOR . 'tracking.class');
// : End
use MyRepo1\Src\Vendors\Vendors as Vendors;
use MyRepo1\Src\Vendors\TrackingInterface as TrackingInterface;
class FM extends Vendors\Vendors implements TrackingInterface\TrackingInterface
{
}
Are there any changes that I need to make to the composer.json file so that the classes will be autoloaded correctly with a composer update
.
Upvotes: 0
Views: 1421
Reputation: 873
we eventually solved this by adding
"autoload" : {
"psr-4" : {
"Vendors\\" : "src/"
}
},
to the composer.json and changed the namespace of the classes to namespace Vendors;
so that it would be the same as the directory.
Upvotes: 1
Reputation: 103
Based on the way your namespace is written your file should be located in
MyRepo1\Src\Vendors\FM\FM.php;
Upvotes: 0