Doctrine\Common\Proxy\Autoloader::register PHP Method

register() public static method

Registers and returns autoloader callback for the given proxy dir and namespace.
public static register ( string $proxyDir, string $proxyNamespace, callable | null $notFoundCallback = null ) : Closure
$proxyDir string
$proxyNamespace string
$notFoundCallback callable | null Invoked when the proxy file is not found.
return Closure
    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;
    }

Usage Example

Example #1
0
 /**
  * @param ModuleEvent $e
  */
 public function onPostLoadModules(ModuleEvent $e)
 {
     $configListener = $e->getConfigListener();
     $config = $configListener->getMergedConfig(false);
     if (isset($config['doctrine']['configuration']['orm_default']['proxy_dir']) && isset($config['doctrine']['configuration']['orm_default']['proxy_namespace'])) {
         // We need to register here manualy. Please see http://www.doctrine-project.org/jira/browse/DDC-1698
         ProxyAutoloader::register($config['doctrine']['configuration']['orm_default']['proxy_dir'], $config['doctrine']['configuration']['orm_default']['proxy_namespace']);
     }
 }
All Usage Examples Of Doctrine\Common\Proxy\Autoloader::register