X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=doc%2Fautoloader.md;h=29d3a005fdb0c1fc9f2aa9cf678353e2098d68cb;hb=b7bf335e94660a1fc808d82fcaaf5c31155092fb;hp=83f1010440694cf0fb2109afcf86a11dedcc38ce;hpb=ee293f2ce28270e1f8e05ce38991977d41e40c27;p=friendica.git diff --git a/doc/autoloader.md b/doc/autoloader.md index 83f1010440..29d3a005fd 100644 --- a/doc/autoloader.md +++ b/doc/autoloader.md @@ -1,192 +1,199 @@ -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 - 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 +