Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to namespaces (2.x) #2863

Merged
merged 9 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
47 changes: 4 additions & 43 deletions lib/Twig/BaseNodeVisitor.php
Original file line number Diff line number Diff line change
@@ -1,50 +1,11 @@
<?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.
*/
use Twig\NodeVisitor\AbstractNodeVisitor;

use Twig\Environment;
use Twig\Node\Node;
use Twig\NodeVisitor\NodeVisitorInterface;
class_exists('Twig\NodeVisitor\AbstractNodeVisitor');

/**
* Twig_BaseNodeVisitor can be used to make node visitors compatible with Twig 1.x and 2.x.
*
* @author Fabien Potencier <[email protected]>
*/
abstract class Twig_BaseNodeVisitor implements NodeVisitorInterface
{
final public function enterNode(Node $node, Environment $env)
if (\false) {
class Twig_BaseNodeVisitor extends AbstractNodeVisitor
{
return $this->doEnterNode($node, $env);
}

final public function leaveNode(Node $node, Environment $env)
{
return $this->doLeaveNode($node, $env);
}

/**
* Called before child nodes are visited.
*
* @return Node The modified node
*/
abstract protected function doEnterNode(Node $node, Environment $env);

/**
* Called after child nodes are visited.
*
* @return Node|false The modified node or false if the node must be removed
*/
abstract protected function doLeaveNode(Node $node, Environment $env);
}

class_alias('Twig_BaseNodeVisitor', 'Twig\NodeVisitor\AbstractNodeVisitor', false);
class_exists('Twig_Environment');
class_exists('Twig_Node');
90 changes: 4 additions & 86 deletions lib/Twig/Cache/Filesystem.php
Original file line number Diff line number Diff line change
@@ -1,93 +1,11 @@
<?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.
*/
use Twig\Cache\FilesystemCache;

use Twig\Cache\CacheInterface;
class_exists('Twig\Cache\FilesystemCache');

/**
* Implements a cache on the filesystem.
*
* @author Andrew Tch <[email protected]>
*/
class Twig_Cache_Filesystem implements CacheInterface
{
const FORCE_BYTECODE_INVALIDATION = 1;

private $directory;
private $options;

/**
* @param string $directory The root cache directory
* @param int $options A set of options
*/
public function __construct($directory, $options = 0)
{
$this->directory = rtrim($directory, '\/').'/';
$this->options = $options;
}

public function generateKey($name, $className)
if (\false) {
class Twig_Cache_Filesystem extends FilesystemCache
{
$hash = hash('sha256', $className);

return $this->directory.$hash[0].$hash[1].'/'.$hash.'.php';
}

public function load($key)
{
if (file_exists($key)) {
@include_once $key;
}
}

public function write($key, $content)
{
$dir = \dirname($key);
if (!is_dir($dir)) {
if (false === @mkdir($dir, 0777, true)) {
clearstatcache(true, $dir);
if (!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));
}

public function getTimestamp($key)
{
if (!file_exists($key)) {
return 0;
}

return (int) @filemtime($key);
}
}

class_alias('Twig_Cache_Filesystem', 'Twig\Cache\FilesystemCache', false);
37 changes: 4 additions & 33 deletions lib/Twig/Cache/Null.php
Original file line number Diff line number Diff line change
@@ -1,40 +1,11 @@
<?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.
*/
use Twig\Cache\NullCache;

use Twig\Cache\CacheInterface;
class_exists('Twig\Cache\NullCache');

/**
* Implements a no-cache strategy.
*
* @author Fabien Potencier <[email protected]>
*/
final class Twig_Cache_Null implements CacheInterface
{
public function generateKey($name, $className)
if (\false) {
class Twig_Cache_Null extends NullCache
{
return '';
}

public function write($key, $content)
{
}

public function load($key)
{
}

public function getTimestamp($key)
{
return 0;
}
}

class_alias('Twig_Cache_Null', 'Twig\Cache\NullCache', false);
59 changes: 6 additions & 53 deletions lib/Twig/CacheInterface.php
Original file line number Diff line number Diff line change
@@ -1,58 +1,11 @@
<?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.
*/
use Twig\Cache\CacheInterface;

/**
* 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 <[email protected]>
*/
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);
class_exists('Twig\Cache\CacheInterface');

/**
* 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);
if (\false) {
class Twig_CacheInterface extends CacheInterface
{
}
}

class_alias('Twig_CacheInterface', 'Twig\Cache\CacheInterface', false);
Loading