From dd0d6afc2168934972d7e8b33f7094089b2b0ab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20St=C3=B6ckler?= Date: Fri, 22 Aug 2014 02:43:44 +0200 Subject: [PATCH] [ClassLoader] Add a __call() method to XcacheClassLoader --- .../Component/ClassLoader/ApcClassLoader.php | 5 ++- .../ClassLoader/XcacheClassLoader.php | 35 +++++++++++++------ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Component/ClassLoader/ApcClassLoader.php b/src/Symfony/Component/ClassLoader/ApcClassLoader.php index 8ee49fb45d..513362a503 100644 --- a/src/Symfony/Component/ClassLoader/ApcClassLoader.php +++ b/src/Symfony/Component/ClassLoader/ApcClassLoader.php @@ -15,7 +15,7 @@ namespace Symfony\Component\ClassLoader; * ApcClassLoader implements a wrapping autoloader cached in APC for PHP 5.3. * * It expects an object implementing a findFile method to find the file. This - * allow using it as a wrapper around the other loaders of the component (the + * allows using it as a wrapper around the other loaders of the component (the * ClassLoader and the UniversalClassLoader for instance) but also around any * other autoloader following this convention (the Composer one for instance) * @@ -46,7 +46,7 @@ class ApcClassLoader /** * The class loader object being decorated. * - * @var \Symfony\Component\ClassLoader\ClassLoader + * @var object * A class loader object that implements the findFile() method. */ protected $decorated; @@ -133,5 +133,4 @@ class ApcClassLoader { return call_user_func_array(array($this->decorated, $method), $args); } - } diff --git a/src/Symfony/Component/ClassLoader/XcacheClassLoader.php b/src/Symfony/Component/ClassLoader/XcacheClassLoader.php index 299a79af93..04a1bf420f 100644 --- a/src/Symfony/Component/ClassLoader/XcacheClassLoader.php +++ b/src/Symfony/Component/ClassLoader/XcacheClassLoader.php @@ -12,7 +12,7 @@ namespace Symfony\Component\ClassLoader; /** - * XcacheClassLoader implements a wrapping autoloader cached in Xcache for PHP 5.3. + * XcacheClassLoader implements a wrapping autoloader cached in XCache for PHP 5.3. * * It expects an object implementing a findFile method to find the file. This * allows using it as a wrapper around the other loaders of the component (the @@ -43,31 +43,38 @@ namespace Symfony\Component\ClassLoader; class XcacheClassLoader { private $prefix; - private $classFinder; + + /** + * The class loader object being decorated. + * + * @var object + * A class loader object that implements the findFile() method. + */ + private $decorated; /** * Constructor. * - * @param string $prefix A prefix to create a namespace in Xcache - * @param object $classFinder An object that implements findFile() method. + * @param string $prefix The XCache namespace prefix to use. + * @param object $decorated A class loader object that implements the findFile() method. * * @throws \RuntimeException * @throws \InvalidArgumentException * * @api */ - public function __construct($prefix, $classFinder) + public function __construct($prefix, $decorated) { - if (!extension_loaded('Xcache')) { - throw new \RuntimeException('Unable to use XcacheClassLoader as Xcache is not enabled.'); + if (!extension_loaded('xcache')) { + throw new \RuntimeException('Unable to use XcacheClassLoader as XCache is not enabled.'); } - if (!method_exists($classFinder, 'findFile')) { + if (!method_exists($decorated, 'findFile')) { throw new \InvalidArgumentException('The class finder must implement a "findFile" method.'); } $this->prefix = $prefix; - $this->classFinder = $classFinder; + $this->decorated = $decorated; } /** @@ -116,10 +123,18 @@ class XcacheClassLoader if (xcache_isset($this->prefix.$class)) { $file = xcache_get($this->prefix.$class); } else { - $file = $this->classFinder->findFile($class); + $file = $this->decorated->findFile($class); xcache_set($this->prefix.$class, $file); } return $file; } + + /** + * Passes through all unknown calls onto the decorated object. + */ + public function __call($method, $args) + { + return call_user_func_array(array($this->decorated, $method), $args); + } }