mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Add autoloader
This commit is contained in:
parent
e740bb2bd9
commit
02368a0a47
@ -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();
|
||||
```
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user