diff --git a/docs/install.md b/docs/install.md index dc8ee1c..e1d8083 100644 --- a/docs/install.md +++ b/docs/install.md @@ -12,4 +12,8 @@ For installation use [composer](http://getcomposer.org). Add in your `composer.j or use shell `composer require fenom/fenom` -If you do not use composer - use `psr-0` format for loading Fenom's classes. +If you do not use composer - use `psr-0` format for loading Fenom's classes or just register Fenom's autoloader: + +```php +Fenom::registerAutoload(); +``` diff --git a/sandbox/fenom.php b/sandbox/fenom.php index 5f5bc5c..26843eb 100644 --- a/sandbox/fenom.php +++ b/sandbox/fenom.php @@ -9,7 +9,9 @@ namespace Ts { } namespace { - require_once __DIR__.'/../vendor/autoload.php'; + require_once __DIR__.'/../src/Fenom.php'; + + \Fenom::registerAutoload(); $fenom = Fenom::factory(__DIR__.'/templates', __DIR__.'/compiled', Fenom::FORCE_COMPILE); diff --git a/src/Fenom.php b/src/Fenom.php index bdb6b9e..7459f6f 100644 --- a/src/Fenom.php +++ b/src/Fenom.php @@ -964,4 +964,22 @@ class Fenom } return $mask; } + + /** + * Register PSR-0 autoload for Fenom + * @param string $dir custom directory for autoloading, if NULL — autoload itself + * @return bool + */ + public static function registerAutoload($dir = null) + { + if(!$dir) { + $dir = __DIR__; + } + return spl_autoload_register(function($classname) use ($dir) { + $file = $dir.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $classname).'.php'; + if(is_file($file)) { + require_once $file; + } + }); + } }