Here is my current structure
plugins/
|—init.php
|—/plugin1/lib/
|—/plugin2/lib/
|—/Symfony/
I have my code like this:
set_include_path(DIR_FS_CATALOG.'plugins');
require_once(DIR_FS_CATALOG.'plugins/Symfony/Component/ClassLoader/UniversalClassLoader.php');
// load the class loader and dependency injection component
$loader = new Symfony\Component\ClassLoader\UniversalClassLoader();
$loader->registerNamespaces(array('plugins\\plugin1' => __DIR__.'/plugins/plugin1/lib', 'plugins' => DIR_FS_CATALOG.'plugins'));
$loader->registerNamespace('Symfony',__DIR__.'/plugins');
$loader->register();
use plugins\plugin1\MyClass;
MyClass::init();
Fatal error: Class ‘plugins\plugin1\MyClass’ not found
I wonder what did I do wrong? Any help would be much appreciated.
The Symfony2 class loader is PSR-0 compliant (https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) which means, that your namespaces must reflect your file system structure.