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
//@trigger_error('The Twig_Autoloader class is deprecated since version 1.21 and will be removed in 2.0. Use Composer instead.', E_USER_DEPRECATED);
13

    
14
/**
15
 * Autoloads Twig classes.
16
 *
17
 * @author Fabien Potencier <fabien@symfony.com>
18
 *
19
 * @deprecated since 1.21 and will be removed in 2.0. Use Composer instead. 2.0.
20
 */
21
class Twig_Autoloader
22
{
23
    /**
24
     * Registers Twig_Autoloader as an SPL autoloader.
25
     *
26
     * @param bool $prepend Whether to prepend the autoloader or not.
27
     */
28
    public static function register($prepend = false)
29
    {
30
//        @trigger_error('Using Twig_Autoloader is deprecated since version 1.21. Use Composer instead.', E_USER_DEPRECATED);
31

    
32
        if (PHP_VERSION_ID < 50300) {
33
            spl_autoload_register(array(__CLASS__, 'autoload'));
34
        } else {
35
            spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
36
        }
37
    }
38

    
39
    /**
40
     * Handles autoloading of classes.
41
     *
42
     * @param string $class A class name.
43
     */
44
    public static function autoload($class)
45
    {
46
        if (0 !== strpos($class, 'Twig')) {
47
            return;
48
        }
49

    
50
        if (is_file($file = dirname(__FILE__).'/../'.str_replace(array('_', "\0"), array('/', ''), $class).'.php')) {
51
            require $file;
52
        }
53
    }
54
}
(1-1/43)