From 939c745a9a3e65d6606aaecba56b4e73d2bd8088 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 27 Apr 2012 10:01:01 +0200 Subject: [PATCH] Improvements to autoload docs --- doc/04-schema.md | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/doc/04-schema.md b/doc/04-schema.md index 7c0b03acc..b9552061e 100644 --- a/doc/04-schema.md +++ b/doc/04-schema.md @@ -215,21 +215,26 @@ Example: Autoload mapping for a PHP autoloader. Currently [PSR-0](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) -autoloading and classmap generation are supported. +autoloading and classmap generation are supported. PSR-0 is the recommended way though +since it offers greater flexibility (no need to regenerate the autoloader when you add +classes). Under the `psr-0` key you define a mapping from namespaces to paths, relative to the -package root. +package root. Note that this also supports the PEAR-style convention. Example: { "autoload": { - "psr-0": { "Monolog": "src/" } + "psr-0": { + "Monolog": "src/", + "Vendor\\Namespace": "src/", + "Pear_Style": "src/" + } } } -Optional, but it is highly recommended that you follow PSR-0 and use this. -If you need to search for a same namespace prefix in multiple directories, +If you need to search for a same prefix in multiple directories, you can specify them as an array as such: { @@ -238,15 +243,24 @@ you can specify them as an array as such: } } +If you want to have a fallback directory where any namespace can be, you can +use an empty prefix like: + + { + "autoload": { + "psr-0": { "": "src/" } + } + } + You can use the classmap generation support to define autoloading for all libraries -that do not follow PSR-0. To configure this you specify all directories +that do not follow PSR-0. To configure this you specify all directories or files to search for classes. Example: { "autoload: { - "classmap": ["src/", "lib/"] + "classmap": ["src/", "lib/", "Something.php"] } }