bug #11768 [ClassLoader] Add a __call() method to XcacheClassLoader (tstoeckler)
This PR was squashed before being merged into the 2.3 branch (closes #11768).
Discussion
----------
[ClassLoader] Add a __call() method to XcacheClassLoader
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #11733
| License | MIT
| Doc PR |
Commits
-------
dd0d6af
[ClassLoader] Add a __call() method to XcacheClassLoader
This commit is contained in:
commit
f7769b52f1
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue