mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 02:46:29 +00:00
Merge branch '1.x' into 2.x
* 1.x: [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.
|
||||
*
|
||||
|
||||
@@ -599,7 +599,26 @@ class Twig_Environment
|
||||
*/
|
||||
public function hasExtension($class)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
return $this->extensionSet->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);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return isset($this->extensionsByClass[$class]);
|
||||
>>>>>>> 1.x
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -619,7 +638,30 @@ class Twig_Environment
|
||||
*/
|
||||
public function getExtension($class)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
return $this->extensionSet->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])) {
|
||||
@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);
|
||||
}
|
||||
|
||||
return $this->extensions[$class];
|
||||
}
|
||||
|
||||
if (!isset($this->extensionsByClass[$class])) {
|
||||
throw new Twig_Error_Runtime(sprintf('The "%s" extension is not enabled.', $class));
|
||||
}
|
||||
|
||||
return $this->extensionsByClass[$class];
|
||||
>>>>>>> 1.x
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -648,7 +690,61 @@ class Twig_Environment
|
||||
|
||||
public function addExtension(Twig_ExtensionInterface $extension)
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
$this->extensionSet->addExtension($extension);
|
||||
=======
|
||||
if ($this->extensionInitialized) {
|
||||
throw new LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $extension->getName()));
|
||||
}
|
||||
|
||||
$class = get_class($extension);
|
||||
if ($class !== $extension->getName()) {
|
||||
if (isset($this->extensions[$extension->getName()])) {
|
||||
unset($this->extensions[$extension->getName()], $this->extensionsByClass[$class]);
|
||||
@trigger_error(sprintf('The possibility to register the same extension twice ("%s") is deprecated since version 1.23 and will be removed in Twig 2.0. Use proper PHP inheritance instead.', $extension->getName()), E_USER_DEPRECATED);
|
||||
}
|
||||
}
|
||||
|
||||
$this->lastModifiedExtension = 0;
|
||||
$this->extensionsByClass[$class] = $extension;
|
||||
$this->extensions[$extension->getName()] = $extension;
|
||||
$this->updateOptionsHash();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an extension by name.
|
||||
*
|
||||
* This method is deprecated and you should not use it.
|
||||
*
|
||||
* @param string $name The extension name
|
||||
*
|
||||
* @deprecated since 1.12 (to be removed in 2.0)
|
||||
*/
|
||||
public function removeExtension($name)
|
||||
{
|
||||
@trigger_error(sprintf('The %s method is deprecated since version 1.12 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
if ($this->extensionInitialized) {
|
||||
throw new LogicException(sprintf('Unable to remove extension "%s" as extensions have already been initialized.', $name));
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
unset($this->extensions[$class]);
|
||||
}
|
||||
|
||||
unset($this->extensions[$class]);
|
||||
>>>>>>> 1.x
|
||||
$this->updateOptionsHash();
|
||||
}
|
||||
|
||||
@@ -945,4 +1041,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.
|
||||
*
|
||||
|
||||
@@ -15,3 +15,5 @@
|
||||
interface Twig_ExistsLoaderInterface extends Twig_LoaderInterface
|
||||
{
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
public function getTokenParsers()
|
||||
|
||||
@@ -26,3 +26,5 @@ interface Twig_Extension_GlobalsInterface
|
||||
*/
|
||||
public function getGlobals();
|
||||
}
|
||||
|
||||
class_alias('Twig_Extension_GlobalsInterface', 'Twig\Extension\GlobalsInterface', false);
|
||||
|
||||
@@ -28,3 +28,5 @@ interface Twig_Extension_InitRuntimeInterface
|
||||
*/
|
||||
public function initRuntime(Twig_Environment $environment);
|
||||
}
|
||||
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -15,3 +15,5 @@
|
||||
interface Twig_SourceContextLoaderInterface extends Twig_LoaderInterface
|
||||
{
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -249,6 +249,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()
|
||||
@@ -448,6 +451,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_TokenParser extends Twig_TokenParser
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user