4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\ClassLoader;
14 @trigger_error('The '.__NAMESPACE__.'\ApcUniversalClassLoader class is deprecated since version 2.7 and will be removed in 3.0. Use the Symfony\Component\ClassLoader\ApcClassLoader class instead.', E_USER_DEPRECATED);
17 * ApcUniversalClassLoader implements a "universal" autoloader cached in APC for PHP 5.3.
19 * It is able to load classes that use either:
21 * * The technical interoperability standards for PHP 5.3 namespaces and
22 * class names (https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md);
24 * * The PEAR naming convention for classes (http://pear.php.net/).
26 * Classes from a sub-namespace or a sub-hierarchy of PEAR classes can be
27 * looked for in a list of locations to ease the vendoring of a sub-set of
28 * classes for large projects.
32 * require 'vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
33 * require 'vendor/symfony/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php';
35 * use Symfony\Component\ClassLoader\ApcUniversalClassLoader;
37 * $loader = new ApcUniversalClassLoader('apc.prefix.');
39 * // register classes with namespaces
40 * $loader->registerNamespaces(array(
41 * 'Symfony\Component' => __DIR__.'/component',
42 * 'Symfony' => __DIR__.'/framework',
43 * 'Sensio' => array(__DIR__.'/src', __DIR__.'/vendor'),
46 * // register a library using the PEAR naming convention
47 * $loader->registerPrefixes(array(
48 * 'Swift_' => __DIR__.'/Swift',
51 * // activate the autoloader
52 * $loader->register();
54 * In this example, if you try to use a class in the Symfony\Component
55 * namespace or one of its children (Symfony\Component\Console for instance),
56 * the autoloader will first look for the class under the component/
57 * directory, and it will then fallback to the framework/ directory if not
58 * found before giving up.
60 * @author Fabien Potencier <fabien@symfony.com>
61 * @author Kris Wallsmith <kris@symfony.com>
63 * @deprecated since version 2.4, to be removed in 3.0.
64 * Use the {@link ClassLoader} class instead.
66 class ApcUniversalClassLoader extends UniversalClassLoader
73 * @param string $prefix A prefix to create a namespace in APC
75 * @throws \RuntimeException
77 public function __construct($prefix)
79 if (!function_exists('apcu_fetch')) {
80 throw new \RuntimeException('Unable to use ApcUniversalClassLoader as APC is not enabled.');
83 $this->prefix = $prefix;
87 * Finds a file by class name while caching lookups to APC.
89 * @param string $class A class name to resolve to file
91 * @return string|null The path, if found
93 public function findFile($class)
95 $file = apcu_fetch($this->prefix.$class, $success);
98 apcu_store($this->prefix.$class, $file = parent::findFile($class) ?: null);