Reputation: 3424
I've read a bit about namespaces in PHP and how compser handles the autoloading of namespaces. I cannot figure out why my class cannot be found. Can someone help?
I'm using Laravel and here are the relevant bits:
composer.json
relevant content:
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php",
"app/libraries"
],
"psr-0": {
"Facebook\\":"vendor/facebook/php-sdk-v4/src/"
}
}
doing a composer dump-autoload
gives me the following line in vendor/composer/autoload_namespaces.php
:
'Facebook\\' => array($vendorDir . '/facebook/php-sdk-v4/src'),
And my vendor folder structure re: Facebook is:
vendor
|__ facebook
|__ php-sdk-v4
|__ src
|__ Facebook
|__ ..
|__ Facebook.php
|__ ..
Trying $facebook = new Facebook($config)
gives me
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN) Class 'Facebook' not found
What am I doing wrong?!
Upvotes: 0
Views: 884
Reputation: 376
Anything from the vendor folder should be loaded automatically so there is no point for using these lines
"psr-0": {
"Facebook\\":"vendor/facebook/php-sdk-v4/src/"
}
Have you added these lines to your composer.json and installed the library the usual composer way?
"require": {
"facebook/php-sdk-v4": "~5.0"
}
Upvotes: 2
Reputation: 10882
Facebook
is the name of the class, but Facebook
seems to also be the name of your namespace.
In that case, you instance it like this:
$facebook = new \Facebook\Facebook($config);
Upvotes: 1