문제

The Symfony 2.0 Autoloader expects that the libraries it can handle follow the PSR0 or PEAR standard when auto-loading files. If you have an old library which does not follow any of these two standards (in my case, class files are named like name.class.php), how would you handle auto-loading of these libraries?

In Symfony 2.1 this is easy as composer supports classmaps and can load this type of libraries, but how would you do it in Symfony 2.0.x?

도움이 되었습니까?

해결책

Inside app/autoload.php, create an instance of MapClassLoader:

use Symfony\Component\ClassLoader\MapClassLoader;
use Symfony\Component\ClassLoader\UniversalClassLoader;

// Create default PSR-0 autoloader
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
    'Symfony' => array(__DIR__.'/../vendor/symfony/src', __DIR__.'/../vendor/bundles'),
    // ...
));

// Create map autoloader
$mapLoader = new MapClassLoader(array(
    'MyComponent' => __DIR__.'/../library/mycomponent.class.php',
    // ...
));

// Other configurations
// ...

// Register autoloaders
$loader->register();
$mapLoader->register();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top