Autoloader with Composer ========== * [Home](help) * [Developer Intro](help/Developers-Intro) Friendica uses [Composer](https://getcomposer.org) to manage dependencies libraries and the class autoloader both for libraries and namespaced Friendica classes. It's a command-line tool that downloads required libraries into the `vendor` folder and makes any namespaced class in `src` available through the whole application through `boot.php`. * [Using Composer](help/Composer) ## A quick introduction to class autoloading The autoloader dynamically includes the file defining a class when it is first referenced, either by instantiating an object or simply making sure that it is available, without the need to explicitly use "require_once". Once it is set up you don't have to directly use it, you can directly use any class that is covered by the autoloader (currently `vendor` and `src`) Under the hood, Composer registers a callback with [`spl_autoload_register()`](http://php.net/manual/en/function.spl-autoload-register.php) that receives a class name as an argument and includes the corresponding class definition file. For more info about PHP autoloading, please refer to the [official PHP documentation](http://php.net/manual/en/language.oop5.autoload.php). ### Example Let's say you have a PHP file in `src/` that define a very useful class: ```php // src/ItemsManager.php getAll(); // pass $items to template // return result } ``` That's a quite simple example, but look: no `require()`! If you need to use a class, you can simply use it and you don't need to do anything else. Going further: now we have a bunch of `*Manager` classes that cause some code duplication. Let's define a `BaseManager` class, where we move all common code between all managers: ```php // src/BaseManager.php