From 09ba90919e599927188856402ee79c14efebdeab Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 19 Oct 2012 14:32:48 +0200 Subject: [PATCH] renamed Twig_ExtendedLoaderInterface to Twig_ExistsLoaderInterface --- CHANGELOG | 2 +- lib/Twig/ExistsLoaderInterface.php | 29 +++++++++++++++++++++++++++++ lib/Twig/ExtendedLoaderInterface.php | 31 ------------------------------- lib/Twig/Loader/Array.php | 2 +- lib/Twig/Loader/Chain.php | 28 +++++++++++++--------------- lib/Twig/Loader/Filesystem.php | 2 +- lib/Twig/Loader/String.php | 2 +- 7 files changed, 46 insertions(+), 50 deletions(-) create mode 100644 lib/Twig/ExistsLoaderInterface.php delete mode 100644 lib/Twig/ExtendedLoaderInterface.php diff --git a/CHANGELOG b/CHANGELOG index 3784432..db781f8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,6 @@ * 1.11.0 (2012-XX-XX) - * n/a + * added Twig_ExistsLoaderInterface (implementing this interface in your loader make the chain loader much faster) * 1.10.3 (2012-10-19) diff --git a/lib/Twig/ExistsLoaderInterface.php b/lib/Twig/ExistsLoaderInterface.php new file mode 100644 index 0000000..90709c6 --- /dev/null +++ b/lib/Twig/ExistsLoaderInterface.php @@ -0,0 +1,29 @@ + + */ +interface Twig_ExistsLoaderInterface +{ + + /** + * Check if we have the source code of a template, given its name. + * + * @param string $name The name of the template to check if we can load + * + * @return boolean If the template source code is handled by this loader or not + */ + public function exists($name); +} diff --git a/lib/Twig/ExtendedLoaderInterface.php b/lib/Twig/ExtendedLoaderInterface.php deleted file mode 100644 index 8d59867..0000000 --- a/lib/Twig/ExtendedLoaderInterface.php +++ /dev/null @@ -1,31 +0,0 @@ - - */ -interface Twig_ExtendedLoaderInterface -{ - - /** - * Check if we have the source code of a template, given its name. - * - * @param string $name The name of the template to check if we can load - * - * @return boolean If the template source code is handled by this loader or not - */ - public function exists($name); - -} diff --git a/lib/Twig/Loader/Array.php b/lib/Twig/Loader/Array.php index dfaf701..e00910c 100644 --- a/lib/Twig/Loader/Array.php +++ b/lib/Twig/Loader/Array.php @@ -20,7 +20,7 @@ * @package twig * @author Fabien Potencier */ -class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExtendedLoaderInterface +class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterface { protected $templates; diff --git a/lib/Twig/Loader/Chain.php b/lib/Twig/Loader/Chain.php index fd767c2..1ab1853 100644 --- a/lib/Twig/Loader/Chain.php +++ b/lib/Twig/Loader/Chain.php @@ -15,7 +15,7 @@ * @package twig * @author Fabien Potencier */ -class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExtendedLoaderInterface +class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterface { private $hasSourceCache = array(); protected $loaders; @@ -51,7 +51,7 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExtendedLoaderInte { $exceptions = array(); foreach ($this->loaders as $loader) { - if ($loader instanceof Twig_ExtendedLoaderInterface && !$loader->exists($name)) { + if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) { continue; } @@ -75,17 +75,15 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExtendedLoaderInte } foreach ($this->loaders as $loader) { - if ($loader instanceof Twig_ExtendedLoaderInterface) { - if ($loader->exists($name)) { - return $this->hasSourceCache[$name] = true; - } - } else { - try { - $loader->getSource($name); - return $this->hasSourceCache[$name] = true; - } catch (Twig_Error_Loader $e) { - - } + if ($loader instanceof Twig_ExistsLoaderInterface && $loader->exists($name)) { + return $this->hasSourceCache[$name] = true; + } + + try { + $loader->getSource($name); + + return $this->hasSourceCache[$name] = true; + } catch (Twig_Error_Loader $e) { } } @@ -99,7 +97,7 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExtendedLoaderInte { $exceptions = array(); foreach ($this->loaders as $loader) { - if ($loader instanceof Twig_ExtendedLoaderInterface && !$loader->exists($name)) { + if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) { continue; } @@ -120,7 +118,7 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExtendedLoaderInte { $exceptions = array(); foreach ($this->loaders as $loader) { - if ($loader instanceof Twig_ExtendedLoaderInterface && !$loader->exists($name)) { + if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) { continue; } diff --git a/lib/Twig/Loader/Filesystem.php b/lib/Twig/Loader/Filesystem.php index 391facf..b201428 100644 --- a/lib/Twig/Loader/Filesystem.php +++ b/lib/Twig/Loader/Filesystem.php @@ -15,7 +15,7 @@ * @package twig * @author Fabien Potencier */ -class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExtendedLoaderInterface +class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderInterface { protected $paths; protected $cache; diff --git a/lib/Twig/Loader/String.php b/lib/Twig/Loader/String.php index 04742cd..5e1b82c 100644 --- a/lib/Twig/Loader/String.php +++ b/lib/Twig/Loader/String.php @@ -24,7 +24,7 @@ * @package twig * @author Fabien Potencier */ -class Twig_Loader_String implements Twig_LoaderInterface, Twig_ExtendedLoaderInterface +class Twig_Loader_String implements Twig_LoaderInterface, Twig_ExistsLoaderInterface { /** * {@inheritdoc} -- 1.7.2.5