How to use a custom class with silex ServiceProvider How to use a custom class with silex ServiceProvider symfony symfony

How to use a custom class with silex ServiceProvider


Seems to me like you are having issues with class loading. This is something that used to be handled by the autoload service in silex. That service was removed however, in favour of composer's autoloading.

You were on the right track with specifying the autoloading in composer.json. In case you're not familiar with composer, read the introduction. For details on how the autoloading works, see the autoloading section of the basic usage chapter.

I will give you the short version here. Make sure your filenames comply with the PSR-0 naming standard. Add this to your composer.json:

{    "autoload": {        "psr-0": {"Acme": "src/"}    }}

You need to replace Acme with your namespace and src with the base directory for your classes. For example, the class Acme\Foo\Bar would be located in src/Acme/Foo/Bar.php.

Then run php composer.phar update to get the autoload files re-dumped and you should be able to access your classes.