mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 12:06:56 +00:00
[1.x] Allow using namespaced aliases as extension names
This commit is contained in:
@@ -9,6 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
require_once __DIR__.'/Environment.php';
|
||||
require_once __DIR__.'/Node.php';
|
||||
|
||||
/**
|
||||
* Twig_BaseNodeVisitor can be used to make node visitors compatible with Twig 1.x and 2.x.
|
||||
*
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
require_once __DIR__.'/Node.php';
|
||||
|
||||
/**
|
||||
* Compiles a node to PHP code.
|
||||
*
|
||||
|
||||
@@ -758,7 +758,7 @@ class Twig_Environment
|
||||
|
||||
public function setLoader(Twig_LoaderInterface $loader)
|
||||
{
|
||||
if (!$loader instanceof Twig_SourceContextLoaderInterface && 0 !== strpos(get_class($loader), 'Mock_Twig_LoaderInterface')) {
|
||||
if (!$loader instanceof Twig_SourceContextLoaderInterface && 0 !== strpos(get_class($loader), 'Mock_')) {
|
||||
@trigger_error(sprintf('Twig loader "%s" should implement Twig_SourceContextLoaderInterface since version 1.27.', get_class($loader)), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
@@ -831,6 +831,12 @@ class Twig_Environment
|
||||
public function hasExtension($class)
|
||||
{
|
||||
$class = ltrim($class, '\\');
|
||||
if (!isset($this->extensionsByClass[$class]) && class_exists($class, false)) {
|
||||
// For BC/FC with namespaced aliases
|
||||
$class = new ReflectionClass($class);
|
||||
$class = $class->name;
|
||||
}
|
||||
|
||||
if (isset($this->extensions[$class])) {
|
||||
if ($class !== get_class($this->extensions[$class])) {
|
||||
@trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), E_USER_DEPRECATED);
|
||||
@@ -860,6 +866,11 @@ class Twig_Environment
|
||||
public function getExtension($class)
|
||||
{
|
||||
$class = ltrim($class, '\\');
|
||||
if (!isset($this->extensionsByClass[$class]) && class_exists($class, false)) {
|
||||
// For BC/FC with namespaced aliases
|
||||
$class = new ReflectionClass($class);
|
||||
$class = $class->name;
|
||||
}
|
||||
|
||||
if (isset($this->extensions[$class])) {
|
||||
if ($class !== get_class($this->extensions[$class])) {
|
||||
@@ -938,6 +949,12 @@ class Twig_Environment
|
||||
}
|
||||
|
||||
$class = ltrim($name, '\\');
|
||||
if (!isset($this->extensionsByClass[$class]) && class_exists($class, false)) {
|
||||
// For BC/FC with namespaced aliases
|
||||
$class = new ReflectionClass($class);
|
||||
$class = $class->name;
|
||||
}
|
||||
|
||||
if (isset($this->extensions[$class])) {
|
||||
if ($class !== get_class($this->extensions[$class])) {
|
||||
@trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), E_USER_DEPRECATED);
|
||||
@@ -1560,4 +1577,4 @@ class Twig_Environment
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_Environment', 'Twig\Environment', false);
|
||||
class_alias('Twig_Environment', 'Twig\Twig', false);
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
require_once __DIR__.'/Source.php';
|
||||
|
||||
/**
|
||||
* Twig base exception.
|
||||
*
|
||||
|
||||
@@ -27,3 +27,5 @@ interface Twig_ExistsLoaderInterface
|
||||
*/
|
||||
public function exists($name);
|
||||
}
|
||||
|
||||
class_alias('Twig_ExistsLoaderInterface', 'Twig\Loader\ExistsLoaderInterface', false);
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
require_once __DIR__.'/Environment.php';
|
||||
|
||||
abstract class Twig_Extension implements Twig_ExtensionInterface
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -20,3 +20,5 @@
|
||||
interface Twig_Extension_GlobalsInterface
|
||||
{
|
||||
}
|
||||
|
||||
class_alias('Twig_Extension_GlobalsInterface', 'Twig\Extension\GlobalsInterface', false);
|
||||
|
||||
@@ -20,3 +20,5 @@
|
||||
interface Twig_Extension_InitRuntimeInterface
|
||||
{
|
||||
}
|
||||
|
||||
class_alias('Twig_Extension_InitRuntimeInterface', 'Twig\Extension\InitRuntimeInterface', false);
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
require_once __DIR__.'/../Profiler/Profile.php';
|
||||
|
||||
class Twig_Extension_Profiler extends Twig_Extension
|
||||
{
|
||||
private $actives = array();
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
require_once __DIR__.'/Environment.php';
|
||||
|
||||
/**
|
||||
* Interface implemented by extension classes.
|
||||
*
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
require_once __DIR__.'/Compiler.php';
|
||||
|
||||
/**
|
||||
* Represents a node in the AST.
|
||||
*
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
require_once __DIR__.'/Environment.php';
|
||||
require_once __DIR__.'/Node.php';
|
||||
|
||||
/**
|
||||
* Twig_NodeVisitorInterface is the interface the all node visitor classes must implement.
|
||||
*
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
require_once __DIR__.'/Node.php';
|
||||
require_once __DIR__.'/TokenStream.php';
|
||||
|
||||
/**
|
||||
* Default parser implementation.
|
||||
*
|
||||
|
||||
@@ -29,3 +29,5 @@ interface Twig_SourceContextLoaderInterface
|
||||
*/
|
||||
public function getSourceContext($name);
|
||||
}
|
||||
|
||||
class_alias('Twig_SourceContextLoaderInterface', 'Twig\Loader\SourceContextLoaderInterface', false);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
@@ -10,6 +8,12 @@ use PHPUnit\Framework\TestCase;
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
require_once __DIR__.'/../Environment.php';
|
||||
require_once __DIR__.'/../Node.php';
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
abstract class Twig_Test_NodeTestCase extends TestCase
|
||||
{
|
||||
abstract public function getTests();
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
require_once __DIR__.'/Parser.php';
|
||||
require_once __DIR__.'/Token.php';
|
||||
|
||||
/**
|
||||
* Interface implemented by token parsers.
|
||||
*
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Twig\Cache;
|
||||
require __DIR__.'/../../lib/Twig/CacheInterface.php';
|
||||
|
||||
if (\false) {
|
||||
class CacheInterface extends \Twig_CacheInterface
|
||||
interface CacheInterface extends \Twig_CacheInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Twig\Extension;
|
||||
require __DIR__.'/../../lib/Twig/ExtensionInterface.php';
|
||||
|
||||
if (\false) {
|
||||
class ExtensionInterface extends \Twig_ExtensionInterface
|
||||
interface ExtensionInterface extends \Twig_ExtensionInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Twig\Extension;
|
||||
|
||||
require __DIR__.'/../../lib/Twig/Extension/GlobalsInterface.php';
|
||||
|
||||
if (\false) {
|
||||
interface GlobalsInterface extends \Twig_Extension_ExtensionInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Twig\Extension;
|
||||
|
||||
require __DIR__.'/../../lib/Twig/Extension/InitRuntimeInterface.php';
|
||||
|
||||
if (\false) {
|
||||
interface InitRuntimeInterface extends \Twig_Extension_InitRuntimeInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Twig\Loader;
|
||||
|
||||
require __DIR__.'/../../lib/Twig/ExistsLoaderInterface.php';
|
||||
|
||||
if (\false) {
|
||||
interface ExistsLoaderInterface extends \Twig_ExistsLoaderInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace Twig\Loader;
|
||||
require __DIR__.'/../../lib/Twig/LoaderInterface.php';
|
||||
|
||||
if (\false) {
|
||||
class LoaderInterface extends \Twig_LoaderInterface
|
||||
interface LoaderInterface extends \Twig_LoaderInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Twig\Loader;
|
||||
|
||||
require __DIR__.'/../../lib/Twig/SourceContextLoaderInterface.php';
|
||||
|
||||
if (\false) {
|
||||
interface SourceContextLoaderInterface extends \Twig_SourceContextLoaderInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace Twig\Node;
|
||||
require __DIR__.'/../../lib/Twig/NodeCaptureInterface.php';
|
||||
|
||||
if (\false) {
|
||||
class NodeCaptureInterface extends \Twig_NodeCaptureInterface
|
||||
interface NodeCaptureInterface extends \Twig_NodeCaptureInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Twig\Node;
|
||||
require __DIR__.'/../../lib/Twig/NodeOutputInterface.php';
|
||||
|
||||
if (\false) {
|
||||
class NodeOutputInterface extends \Twig_NodeOutputInterface
|
||||
interface NodeOutputInterface extends \Twig_NodeOutputInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Twig\NodeVisitor;
|
||||
require __DIR__.'/../../lib/Twig/NodeVisitorInterface.php';
|
||||
|
||||
if (\false) {
|
||||
class NodeVisitorInterface extends \Twig_NodeVisitorInterface
|
||||
interface NodeVisitorInterface extends \Twig_NodeVisitorInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Twig\RuntimeLoader;
|
||||
require __DIR__.'/../../lib/Twig/RuntimeLoaderInterface.php';
|
||||
|
||||
if (\false) {
|
||||
class RuntimeLoaderInterface extends \Twig_RuntimeLoaderInterface
|
||||
interface RuntimeLoaderInterface extends \Twig_RuntimeLoaderInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Twig\Sandbox;
|
||||
require __DIR__.'/../../lib/Twig/Sandbox/SecurityPolicyInterface.php';
|
||||
|
||||
if (\false) {
|
||||
class SecurityPolicyInterface extends \Twig_Sandbox_SecurityPolicyInterface
|
||||
interface SecurityPolicyInterface extends \Twig_Sandbox_SecurityPolicyInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Twig\TokenParser;
|
||||
require __DIR__.'/../../lib/Twig/TokenParserInterface.php';
|
||||
|
||||
if (\false) {
|
||||
class TokenParserInterface extends \Twig_TokenParserInterface
|
||||
interface TokenParserInterface extends \Twig_TokenParserInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Twig;
|
||||
require __DIR__.'/../lib/Twig/Environment.php';
|
||||
|
||||
if (\false) {
|
||||
class Environment extends \Twig_Environment
|
||||
class Twig extends \Twig_Environment
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -311,6 +311,9 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertSame($ext, $twig->getExtension('Twig_Tests_EnvironmentTest_Extension'));
|
||||
$this->assertSame($ext, $twig->getExtension('\Twig_Tests_EnvironmentTest_Extension'));
|
||||
|
||||
$this->assertTrue($twig->hasExtension('Twig\Tests\EnvironmentTest\Extension'));
|
||||
$this->assertSame($ext, $twig->getExtension('Twig\Tests\EnvironmentTest\Extension'));
|
||||
}
|
||||
|
||||
public function testAddExtension()
|
||||
@@ -557,6 +560,7 @@ class Twig_Tests_EnvironmentTest_Extension extends Twig_Extension implements Twi
|
||||
);
|
||||
}
|
||||
}
|
||||
class_alias('Twig_Tests_EnvironmentTest_Extension', 'Twig\Tests\EnvironmentTest\Extension', false);
|
||||
|
||||
class Twig_Tests_EnvironmentTest_Extension_WithDeprecatedName extends Twig_Extension
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user