1 |
1686
|
darkviper
|
<?php
|
2 |
|
|
|
3 |
|
|
/*
|
4 |
|
|
* This file is part of Twig.
|
5 |
|
|
*
|
6 |
|
|
* (c) 2009 Fabien Potencier
|
7 |
|
|
*
|
8 |
|
|
* For the full copyright and license information, please view the LICENSE
|
9 |
|
|
* file that was distributed with this source code.
|
10 |
|
|
*/
|
11 |
|
|
|
12 |
|
|
/**
|
13 |
|
|
* Autoloads Twig classes.
|
14 |
|
|
*
|
15 |
|
|
* @package twig
|
16 |
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
17 |
|
|
*/
|
18 |
|
|
class Twig_Autoloader
|
19 |
|
|
{
|
20 |
|
|
/**
|
21 |
|
|
* Registers Twig_Autoloader as an SPL autoloader.
|
22 |
|
|
*/
|
23 |
|
|
static public function register()
|
24 |
|
|
{
|
25 |
|
|
ini_set('unserialize_callback_func', 'spl_autoload_call');
|
26 |
|
|
spl_autoload_register(array(new self, 'autoload'));
|
27 |
|
|
}
|
28 |
|
|
|
29 |
|
|
/**
|
30 |
|
|
* Handles autoloading of classes.
|
31 |
|
|
*
|
32 |
|
|
* @param string $class A class name.
|
33 |
|
|
*
|
34 |
|
|
* @return boolean Returns true if the class has been loaded
|
35 |
|
|
*/
|
36 |
|
|
static public function autoload($class)
|
37 |
|
|
{
|
38 |
|
|
if (0 !== strpos($class, 'Twig')) {
|
39 |
|
|
return;
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
if (is_file($file = dirname(__FILE__).'/../'.str_replace(array('_', "\0"), array('/', ''), $class).'.php')) {
|
43 |
|
|
require $file;
|
44 |
|
|
}
|
45 |
|
|
}
|
46 |
|
|
}
|