Project

General

Profile

1
<?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
    public static 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
    public static function autoload($class)
35
    {
36
        if (0 !== strpos($class, 'Twig')) {
37
            return;
38
        }
39

    
40
        if (is_file($file = dirname(__FILE__).'/../'.str_replace(array('_', "\0"), array('/', ''), $class).'.php')) {
41
            require $file;
42
        }
43
    }
44
}
(1-1/34)