I'm trying to setup symfony class loader component for one of my projects. When I try to create a new object from the Logger class I get
Fatal error: Class 'MyPrefix\Log\Logger' not found in /usr/htdocs/sf/index.php on line 12
Here is the structure of the project
/
lib
MyPrefix
Log
Logger.php
vendor/
index.php
Here is the content of index.php file
<?php
require_once 'vendor/autoload.php';
use Symfony\Component\ClassLoader\ClassLoader;
$loader = new ClassLoader();
$loader->addPrefix('MyPrefix', __DIR__ .'/lib/MyPrefix/');
$loader->register();
use MyPrefix\Log\Logger;
$logger = new Logger();
What I'm doing wrong?
When you add new prefix for namespace, you should give parent directory.
So for
MyPrefix
it is__DIR__ . '/lib/'