Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dev: Download and extract all Twig files from https://github.com/twig…
…php/Twig/tags under application/third_party/Twig (Yii: protected/vendor/Twig.) Dev: see https://github.com/yiiext/twig-renderer#installing-manually
- Loading branch information
LouisGac
committed
Dec 14, 2016
1 parent
ef8bff3
commit 2d9df54
Showing
194 changed files
with
17,077 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?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. | ||
*/ | ||
|
||
@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); | ||
|
||
/** | ||
* Autoloads Twig classes. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
* | ||
* @deprecated since 1.21 and will be removed in 2.0. Use Composer instead. 2.0. | ||
*/ | ||
class Twig_Autoloader | ||
{ | ||
/** | ||
* Registers Twig_Autoloader as an SPL autoloader. | ||
* | ||
* @param bool $prepend whether to prepend the autoloader or not | ||
*/ | ||
public static function register($prepend = false) | ||
{ | ||
@trigger_error('Using Twig_Autoloader is deprecated since version 1.21. Use Composer instead.', E_USER_DEPRECATED); | ||
|
||
if (PHP_VERSION_ID < 50300) { | ||
spl_autoload_register(array(__CLASS__, 'autoload')); | ||
} else { | ||
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend); | ||
} | ||
} | ||
|
||
/** | ||
* Handles autoloading of classes. | ||
* | ||
* @param string $class a class name | ||
*/ | ||
public static function autoload($class) | ||
{ | ||
if (0 !== strpos($class, 'Twig')) { | ||
return; | ||
} | ||
|
||
if (is_file($file = dirname(__FILE__).'/../'.str_replace(array('_', "\0"), array('/', ''), $class).'.php')) { | ||
require $file; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?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. | ||
*/ | ||
|
||
/** | ||
* Twig_BaseNodeVisitor can be used to make node visitors compatible with Twig 1.x and 2.x. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
*/ | ||
abstract class Twig_BaseNodeVisitor implements Twig_NodeVisitorInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
final public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) | ||
{ | ||
if (!$node instanceof Twig_Node) { | ||
throw new LogicException('Twig_BaseNodeVisitor only supports Twig_Node instances.'); | ||
} | ||
|
||
return $this->doEnterNode($node, $env); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
final public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env) | ||
{ | ||
if (!$node instanceof Twig_Node) { | ||
throw new LogicException('Twig_BaseNodeVisitor only supports Twig_Node instances.'); | ||
} | ||
|
||
return $this->doLeaveNode($node, $env); | ||
} | ||
|
||
/** | ||
* Called before child nodes are visited. | ||
* | ||
* @return Twig_Node The modified node | ||
*/ | ||
abstract protected function doEnterNode(Twig_Node $node, Twig_Environment $env); | ||
|
||
/** | ||
* Called after child nodes are visited. | ||
* | ||
* @return Twig_Node|false The modified node or false if the node must be removed | ||
*/ | ||
abstract protected function doLeaveNode(Twig_Node $node, Twig_Environment $env); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Twig. | ||
* | ||
* (c) 2015 Fabien Potencier | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
/** | ||
* Implements a cache on the filesystem. | ||
* | ||
* @author Andrew Tch <andrew@noop.lv> | ||
*/ | ||
class Twig_Cache_Filesystem implements Twig_CacheInterface | ||
{ | ||
const FORCE_BYTECODE_INVALIDATION = 1; | ||
|
||
private $directory; | ||
private $options; | ||
|
||
/** | ||
* @param $directory string The root cache directory | ||
* @param $options int A set of options | ||
*/ | ||
public function __construct($directory, $options = 0) | ||
{ | ||
$this->directory = rtrim($directory, '\/').'/'; | ||
$this->options = $options; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function generateKey($name, $className) | ||
{ | ||
$hash = hash('sha256', $className); | ||
|
||
return $this->directory.$hash[0].$hash[1].'/'.$hash.'.php'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load($key) | ||
{ | ||
if (file_exists($key)) { | ||
@include_once $key; | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function write($key, $content) | ||
{ | ||
$dir = dirname($key); | ||
if (!is_dir($dir)) { | ||
if (false === @mkdir($dir, 0777, true) && !is_dir($dir)) { | ||
throw new RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir)); | ||
} | ||
} elseif (!is_writable($dir)) { | ||
throw new RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir)); | ||
} | ||
|
||
$tmpFile = tempnam($dir, basename($key)); | ||
if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $key)) { | ||
@chmod($key, 0666 & ~umask()); | ||
|
||
if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) { | ||
// Compile cached file into bytecode cache | ||
if (function_exists('opcache_invalidate')) { | ||
opcache_invalidate($key, true); | ||
} elseif (function_exists('apc_compile_file')) { | ||
apc_compile_file($key); | ||
} | ||
} | ||
|
||
return; | ||
} | ||
|
||
throw new RuntimeException(sprintf('Failed to write cache file "%s".', $key)); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getTimestamp($key) | ||
{ | ||
if (!file_exists($key)) { | ||
return 0; | ||
} | ||
|
||
return (int) @filemtime($key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Twig. | ||
* | ||
* (c) 2015 Fabien Potencier | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
/** | ||
* Implements a no-cache strategy. | ||
* | ||
* @final | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
*/ | ||
class Twig_Cache_Null implements Twig_CacheInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function generateKey($name, $className) | ||
{ | ||
return ''; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function write($key, $content) | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load($key) | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getTimestamp($key) | ||
{ | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Twig. | ||
* | ||
* (c) 2015 Fabien Potencier | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
/** | ||
* Interface implemented by cache classes. | ||
* | ||
* It is highly recommended to always store templates on the filesystem to | ||
* benefit from the PHP opcode cache. This interface is mostly useful if you | ||
* need to implement a custom strategy for storing templates on the filesystem. | ||
* | ||
* @author Andrew Tch <andrew@noop.lv> | ||
*/ | ||
interface Twig_CacheInterface | ||
{ | ||
/** | ||
* Generates a cache key for the given template class name. | ||
* | ||
* @param string $name The template name | ||
* @param string $className The template class name | ||
* | ||
* @return string | ||
*/ | ||
public function generateKey($name, $className); | ||
|
||
/** | ||
* Writes the compiled template to cache. | ||
* | ||
* @param string $key The cache key | ||
* @param string $content The template representation as a PHP class | ||
*/ | ||
public function write($key, $content); | ||
|
||
/** | ||
* Loads a template from the cache. | ||
* | ||
* @param string $key The cache key | ||
*/ | ||
public function load($key); | ||
|
||
/** | ||
* Returns the modification timestamp of a key. | ||
* | ||
* @param string $key The cache key | ||
* | ||
* @return int | ||
*/ | ||
public function getTimestamp($key); | ||
} |
Oops, something went wrong.