You are here

public static function Autoloader::register in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/doctrine/common/lib/Doctrine/Common/Proxy/Autoloader.php \Doctrine\Common\Proxy\Autoloader::register()

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 vendor/doctrine/common/tests/Doctrine/Tests/Common/Proxy/AutoloaderTest.php
AutoloaderTest::testRegisterWithInvalidCallback in vendor/doctrine/common/tests/Doctrine/Tests/Common/Proxy/AutoloaderTest.php

File

vendor/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;
}