Skip to content

Commit

Permalink
added an autoloader to ease integration
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Dec 15, 2010
1 parent 61184e4 commit d540791
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
46 changes: 46 additions & 0 deletions lib/Twig/Extensions/Autoloader.php
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of Twig.
*
* (c) 2009 Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* Autoloads Twig Extensions classes.
*
* @package twig
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class Twig_Extensions_Autoloader
{
/**
* Registers Twig_Extensions_Autoloader as an SPL autoloader.
*/
static public function register()
{
ini_set('unserialize_callback_func', 'spl_autoload_call');
spl_autoload_register(array(new self, 'autoload'));
}

/**
* Handles autoloading of classes.
*
* @param string $class A class name.
*
* @return boolean Returns true if the class has been loaded
*/
static public function autoload($class)
{
if (0 !== strpos($class, 'Twig_Extensions')) {
return;
}

if (file_exists($file = dirname(__FILE__).'/../../'.str_replace('_', '/', $class).'.php')) {
require $file;
}
}
}
14 changes: 2 additions & 12 deletions test/bootstrap.php
Expand Up @@ -16,15 +16,5 @@
require_once TWIG_LIB_DIR.'/Twig/Autoloader.php';
Twig_Autoloader::register();

function twigExtensionAutoload($class)
{
if (0 !== strpos($class, 'Twig_Extensions')) {
return;
}

if (file_exists($file = dirname(__FILE__).'/../lib/'.str_replace('_', '/', $class).'.php')) {
require $file;
}
}

spl_autoload_register('twigExtensionAutoload');
require_once dirname(__FILE__).'/../lib/Twig/Extensions/Autoloader.php';
Twig_Extensions_Autoloader::register();

0 comments on commit d540791

Please sign in to comment.