public function testAutoload() { $this->assertFalse(class_exists('FooBarFoo'), '->autoload() does not try to load classes that does not begin with Twig'); $autoloader = new Twig_Autoloader(); $this->assertTrue($autoloader->autoload('Twig_Parser'), '->autoload() returns true if it is able to load a class'); $this->assertFalse($autoloader->autoload('Foo'), '->autoload() returns false if it is not able to load a class'); }
function load_twig() { global $twig, $config; require 'lib/Twig/Autoloader.php'; Twig_Autoloader::register(); Twig_Autoloader::autoload('Twig_Extensions_Node_Trans'); Twig_Autoloader::autoload('Twig_Extensions_TokenParser_Trans'); Twig_Autoloader::autoload('Twig_Extensions_Extension_I18n'); Twig_Autoloader::autoload('Twig_Extensions_Extension_Tinyboard'); $loader = new Twig_Loader_Filesystem($config['dir']['template']); $loader->setPaths($config['dir']['template']); $twig = new Twig_Environment($loader, array('autoescape' => false, 'cache' => is_writable('templates') && (!is_dir('templates/cache') || is_writable('templates/cache')) ? "{$config['dir']['template']}/cache" : false, 'debug' => $config['debug'])); $twig->addExtension(new Twig_Extensions_Extension_Tinyboard()); $twig->addExtension(new Twig_Extensions_Extension_I18n()); }
<?php /* * This file is part of Twig. * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../../lib/lime/LimeAutoloader.php'; LimeAutoloader::register(); require_once dirname(__FILE__) . '/../../../lib/Twig/Autoloader.php'; Twig_Autoloader::register(); $t = new LimeTest(3); // ->autoload() $t->diag('->autoload()'); $t->ok(!class_exists('Foo'), '->autoload() does not try to load classes that does not begin with Twig'); $autoloader = new Twig_Autoloader(); $t->is($autoloader->autoload('Twig_Parser'), true, '->autoload() returns true if it is able to load a class'); $t->is($autoloader->autoload('Foo'), false, '->autoload() returns false if it is not able to load a class');
<?php /** * @Product: NanoCore * @Author: Maxim P. */ # System functions include 'functions.php'; # Components autoloaders include 'Symfony' . S . 'Component' . S . 'Twig' . S . 'Autoloader.php'; include 'ActiveRecord' . S . 'ActiveRecord.php'; /* * Registar class loader */ spl_autoload_register(function ($class) { $path = ROOT . S . 'engine' . S . str_replace('\\', S, $class) . '.php'; if (is_file($path)) { include $path; } else { Twig_Autoloader::autoload($class); } }); /* * Run engine container */ new \System\Engine\NCContainer();
<?php if ($_SERVER['SCRIPT_FILENAME'] == str_replace('\\', '/', __FILE__)) { // You cannot request this file directly. header('Location: ../', true, 302); exit; } require 'contrib/Twig/Autoloader.php'; Twig_Autoloader::register(); Twig_Autoloader::autoload('Twig_Extensions_Node_Trans'); Twig_Autoloader::autoload('Twig_Extensions_TokenParser_Trans'); Twig_Autoloader::autoload('Twig_Extensions_Extension_I18n'); Twig_Autoloader::autoload('Twig_Extensions_Extension_Tinyboard'); $loader = new Twig_Loader_Filesystem($config['dir']['template']); function Element($templateFile, array $options) { global $config, $debug, $loader; if (function_exists('create_pm_header') && (isset($options['mod']) && $options['mod'] || isset($options['__mod']))) { $options['pm'] = create_pm_header(); } if (isset($options['body']) && $config['debug']) { if (isset($debug['start'])) { $debug['time'] = '~' . round((microtime(true) - $debug['start']) * 1000, 2) . 'ms'; unset($debug['start']); } $options['body'] .= '<h3>Debug</h3><pre style="white-space: pre-wrap;font-size: 10px;">' . str_replace("\n", '<br/>', utf8tohtml(print_r($debug, true))) . '</pre>'; } $loader->setPaths($config['dir']['template']); $twig = new Twig_Environment($loader, array('autoescape' => false, 'cache' => "{$config['dir']['template']}/cache", 'debug' => $config['debug'] ? true : false)); $twig->addExtension(new Twig_Extensions_Extension_Tinyboard()); $twig->addExtension(new Twig_Extensions_Extension_I18n());