Currently I am working on one of my projects. For this project I am using Silex micro PHP framework, because its small fast and has all tools required for my project and uses some great libraries from Symfony2 framework.
Anyway to have reusable code I wanted to create some code on my namespace. All examples on the Internet shows to use
$app['autoloader']->registerNamespace... but this functionality is deprecated and suggestion is to use Composer (composer.json). But I really didn’t wanted to use it. In fact I think micro framework should be able to setup fast without additional stuff like Composer.
Some time spent on searching found a solution. What I needed is to change first file in my controllers file to this:
//before was //require_once __DIR__.'/../vendor/autoload.php'; $loader = require_once __DIR__.'/../vendor/autoload.php';
And then add some namespaces paths to loader itself:
$loader->add('Irmantas', __DIR__ . '/../src/'); $loader->add('OtherNamespace', __DIR__ . '/../libs/other/');
Thats it and I have fully working namespace autoloader.