OSDN Git Service

add README v1.0.2
authorfrostbane <frostbane@programmer.net>
Mon, 9 Dec 2019 07:01:58 +0000 (16:01 +0900)
committerfrostbane <frostbane@programmer.net>
Mon, 9 Dec 2019 07:01:58 +0000 (16:01 +0900)
README.md

index a8b778d..5153799 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,3 +1,112 @@
 # Autoloader #
 
 ----------------------------------------------------------------------
+
+## Registering Paths ##
+
+Register a path as an autoload path
+
+Assuming the following directory structure:
+
+```
+__DOC_ROOT__
+     |- common
+     |    `- classes
+     |        `- Util
+     |            `- String
+     |                |- StringUtil.php
+     |                `- StringSearch.php
+     `- core
+          `- Input
+               |- InputValidator.php
+               `- InputFilter.php
+
+```
+
+And assuming that the following classes exists.
+
+- `StringUtil.php` contains:
+    + `\Util\String\StringUtil` class
+- `StringSearch.php` contains:
+    + `\Util\String_StringSearch` class
+
+```php
+use frostbane\autoloader\Psr0;
+use String\StringUtil;
+
+$loader = Psr0::instance();
+
+$loader->registerPath(__DOC_ROOT__ . "/common/classes");
+
+// StringUtil will automatically be loaded
+$strUtil = new StringUtil();
+
+// StringSearch will automatically be loaded
+$strSearch = new \String\StringSearch();
+```
+
+Having the same directory structure above, assume that the following
+classes exists.
+
+- `InputValidator.php` contains:
+    + `\Framework\Validation\Input\InputValidator` class
+- `InputFilter.php` contains:
+    + `\Framework\Validation\Input_InputFilter` class
+
+
+Registering the path `__DOC_ROOT_/core` will not autoload the validation
+classes.
+
+To register them with a prefixed namespace:
+
+```php
+use frostbane\autoloader\Psr0;
+use Framework\Validation\Input\InputValidator;
+
+$loader = Psr0::instance();
+
+$loader->registerNamespacePath("\\Framework\\Validation", __DOC_ROOT__ . "/core");
+
+// InputValidator will automatically be loaded
+$validator = new InputValidator();
+
+// InputFilter will automatically be loaded
+$filter = new \Framework\Validation\Input\InputFilter();
+```
+
+## Registering Multiple Paths ##
+
+A couple of overloads exists to make the code a little readable.
+
+```php
+use frostbane\autoloader\Psr0;
+
+$loader = Psr0::instance();
+
+$loader->registerPath(array(__DOC_ROOT__ . "/common/classes",
+                            __DOC_ROOT__ . "/some/other/path",
+                            __DIR__ . "/../another/path"));
+```
+
+and
+
+```php
+use frostbane\autoloader\Psr0;
+
+$loader = Psr0::instance();
+
+$loader->registerNamespacePath(array("\\some\\namespace"        => __DOC_ROOT__ . "/common/classes",
+                                     "\\some\\other\\namespace" => __DOC_ROOT__ . "/some/other/path",
+                                     "\\another\\namespace"     => __DIR__ . "/../another/path"));
+```
+
+## Debugging ##
+
+If you are lost and don't know what paths are registered, find a bible (perhaps.)
+
+```
+use frostbane\autoloader\Psr0;
+
+$loader          = Psr0::instance();
+$registeredPaths = $loader->getPaths();
+```