Silex autoload namespaces without Composer

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.

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.
This entry was posted in Programming and tagged , , , . Bookmark the permalink.

4 Responses to Silex autoload namespaces without Composer

  1. games says:

    Iam with you in this i think micro framework must be supper fast and not complex but i think you must write your own framework it’s will be what you need anyway thank you

  2. Marcaum54 says:

    Nice dude, i try load with composer but, dont work.. and lost much time…

    Ty for this method 😉

  3. Pingback: Silex $app['autoloader']->registerNamespace() deprecated |

  4. VS says:


Leave a Reply

Your email address will not be published. Required fields are marked *