You are here

class ApcUniversalClassLoader in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/class-loader/ApcUniversalClassLoader.php \Symfony\Component\ClassLoader\ApcUniversalClassLoader

ApcUniversalClassLoader implements a "universal" autoloader cached in APC for PHP 5.3.

It is able to load classes that use either:

Classes from a sub-namespace or a sub-hierarchy of PEAR classes can be looked for in a list of locations to ease the vendoring of a sub-set of classes for large projects.

Example usage:

require 'vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php'; require 'vendor/symfony/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php';

use Symfony\Component\ClassLoader\ApcUniversalClassLoader;

$loader = new ApcUniversalClassLoader('apc.prefix.');

// register classes with namespaces $loader->registerNamespaces(array( 'Symfony\Component' => __DIR__.'/component', 'Symfony' => __DIR__.'/framework', 'Sensio' => array(__DIR__.'/src', __DIR__.'/vendor'), ));

// register a library using the PEAR naming convention $loader->registerPrefixes(array( 'Swift_' => __DIR__.'/Swift', ));

// activate the autoloader $loader->register();

In this example, if you try to use a class in the Symfony\Component namespace or one of its children (Symfony\Component\Console for instance), the autoloader will first look for the class under the component/ directory, and it will then fallback to the framework/ directory if not found before giving up.

@author Fabien Potencier <fabien@symfony.com> @author Kris Wallsmith <kris@symfony.com>

Hierarchy

Expanded class hierarchy of ApcUniversalClassLoader

Deprecated

since version 2.4, to be removed in 3.0. Use the {@link ClassLoader} class instead.

1 file declares its use of ApcUniversalClassLoader
LegacyApcUniversalClassLoaderTest.php in vendor/symfony/class-loader/Tests/LegacyApcUniversalClassLoaderTest.php

File

vendor/symfony/class-loader/ApcUniversalClassLoader.php, line 66

Namespace

Symfony\Component\ClassLoader
View source
class ApcUniversalClassLoader extends UniversalClassLoader {
  private $prefix;

  /**
   * Constructor.
   *
   * @param string $prefix A prefix to create a namespace in APC
   *
   * @throws \RuntimeException
   */
  public function __construct($prefix) {
    if (!extension_loaded('apc')) {
      throw new \RuntimeException('Unable to use ApcUniversalClassLoader as APC is not enabled.');
    }
    $this->prefix = $prefix;
  }

  /**
   * Finds a file by class name while caching lookups to APC.
   *
   * @param string $class A class name to resolve to file
   *
   * @return string|null The path, if found
   */
  public function findFile($class) {
    if (false === ($file = apc_fetch($this->prefix . $class))) {
      apc_store($this->prefix . $class, $file = parent::findFile($class));
    }
    return $file;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ApcUniversalClassLoader::$prefix private property
ApcUniversalClassLoader::findFile public function Finds a file by class name while caching lookups to APC. Overrides UniversalClassLoader::findFile
ApcUniversalClassLoader::__construct public function Constructor.
UniversalClassLoader::$namespaceFallbacks private property
UniversalClassLoader::$namespaces private property
UniversalClassLoader::$prefixes private property
UniversalClassLoader::$prefixFallbacks private property
UniversalClassLoader::$useIncludePath private property
UniversalClassLoader::getNamespaceFallbacks public function Gets the directory(ies) to use as a fallback for namespaces.
UniversalClassLoader::getNamespaces public function Gets the configured namespaces.
UniversalClassLoader::getPrefixes public function Gets the configured class prefixes.
UniversalClassLoader::getPrefixFallbacks public function Gets the directory(ies) to use as a fallback for class prefixes.
UniversalClassLoader::getUseIncludePath public function Can be used to check if the autoloader uses the include path to check for classes.
UniversalClassLoader::loadClass public function Loads the given class or interface. 1
UniversalClassLoader::register public function Registers this instance as an autoloader.
UniversalClassLoader::registerNamespace public function Registers a namespace.
UniversalClassLoader::registerNamespaceFallback public function Registers a directory to use as a fallback for namespaces.
UniversalClassLoader::registerNamespaceFallbacks public function Registers the directory to use as a fallback for namespaces.
UniversalClassLoader::registerNamespaces public function Registers an array of namespaces.
UniversalClassLoader::registerPrefix public function Registers a set of classes using the PEAR naming convention.
UniversalClassLoader::registerPrefixes public function Registers an array of classes using the PEAR naming convention.
UniversalClassLoader::registerPrefixFallback public function Registers a directory to use as a fallback for class prefixes.
UniversalClassLoader::registerPrefixFallbacks public function Registers directories to use as a fallback for class prefixes.
UniversalClassLoader::useIncludePath public function Turns on searching the include for class files. Allows easy loading of installed PEAR packages.