Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you autoload a directory in Silex

Tags:

php

silex

If I have a directory of class files in /src/lib and I want them autoloaded, how do I do this with the latest version of Silex.

I don't really see any good documention other that loading services.

like image 807
Justin Avatar asked Feb 19 '23 05:02

Justin


1 Answers

The autoloading of silex is handled by composer. The composer documentation on autoloading goes into detail on what kinds of autoloading are possible.

It is recommended that you use a psr-0 naming scheme for your files. But if you don't want to do that, you can also use classmap autoloading.

Here's an example with PSR-0, assuming the class Foo\Bar is in src/Foo/Bar.php:

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

For classmap, refer to the documentation linked above.

like image 77
igorw Avatar answered Feb 21 '23 18:02

igorw