This post is dedicated to the easy solution that seems to exist to add your own namespaces, the solution with the loader in app/autoload.php.
There is a lot of documentations talking about the magic methods like registerNamespace or registerPrefix.
The problem is that those methods exist for a UniversalClassLoader object.
I downloaded the Symfony standard edition 2.2, and the app/autoload.php looks more like that (pretty much the same with Symfony standard edition 2.1) :
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
return $loader;
the loader used in fact is the composer loader. The only method you could use is the 'add' method like this if you hope to add 'seculibs/collections' namespace for example:
$loader->add("seculibs\\collections", __DIR__.'/../vendor/seculibs/collections/');
But it does not seem to work : when I execute programm I have the same classNotFound for /seculibs/collections/xx.php
So I changed the autoload.php like that :
require_once ('/../vendor/symfony/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php');
use Doctrine\Common\Annotations\AnnotationRegistry;
use Symfony\Component\ClassLoader\UniversalClassLoader;
$loader = require __DIR__.'/../vendor/autoload.php';
$universalLoader = new UniversalClassLoader();
$universalLoader->registerNamespace("seculibs\\collections", __DIR__.'/../vendor/seculibs/collections/');
$universalLoader->register();
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
return $loader;
Nothing...
But obviously it works for a lot of persons so.. what am I doing wrong ? Do they have some other Symfony version that would be found on secret websites ?
one of the classes is like that :
namespace seculibs\collections;
class LinkedMap {
private $items;
public function __construct() {
$this->items = array();
}
public function __destruct() {
unset($this->items);
}
....