You are here

public static function Autoloader::register in Plug 7

Registers and returns autoloader callback for the given proxy dir and namespace.

Parameters

string $proxyDir:

string $proxyNamespace:

callable|null $notFoundCallback Invoked when the proxy file is not found.:

Return value

\Closure

Throws

InvalidArgumentException

2 calls to Autoloader::register()
AutoloaderTest::testAutoload in lib/doctrine/common/tests/Doctrine/Tests/Common/Proxy/AutoloaderTest.php
AutoloaderTest::testRegisterWithInvalidCallback in lib/doctrine/common/tests/Doctrine/Tests/Common/Proxy/AutoloaderTest.php

File

lib/doctrine/common/lib/Doctrine/Common/Proxy/Autoloader.php, line 68

Class

Autoloader
Special Autoloader for Proxy classes, which are not PSR-0 compliant.

Namespace

Doctrine\Common\Proxy

Code

public static function register($proxyDir, $proxyNamespace, $notFoundCallback = null) {
  $proxyNamespace = ltrim($proxyNamespace, '\\');
  if (!(null === $notFoundCallback || is_callable($notFoundCallback))) {
    throw InvalidArgumentException::invalidClassNotFoundCallback($notFoundCallback);
  }
  $autoloader = function ($className) use ($proxyDir, $proxyNamespace, $notFoundCallback) {
    if (0 === strpos($className, $proxyNamespace)) {
      $file = Autoloader::resolveFile($proxyDir, $proxyNamespace, $className);
      if ($notFoundCallback && !file_exists($file)) {
        call_user_func($notFoundCallback, $proxyDir, $proxyNamespace, $className);
      }
      require $file;
    }
  };
  spl_autoload_register($autoloader);
  return $autoloader;
}