/** * Compile a hack function. * * @param callable $loader The loader function. * * @param string $hackName The name of the hack. * * @return \Closure */ private function compileHack($loader, $hackName) { $logger = $this->logger; return function ($class) use($loader, $hackName, $logger) { if (call_user_func($loader, $class)) { $logger->debug('Custom class loader hack {hackName} loaded {class}.', array('hackName' => $hackName, 'class' => $class)); return $hackName; } if (EnumeratingClassLoader::isLoaded($class)) { $logger->warning('Hack {hackName} appears to have loaded {class} but did return null. It SHOULD return true.', array('hackName' => $hackName, 'class' => $class)); return $hackName; } return null; }; }
* @filesource */ // WARNING!!!! This file is just a reference and should not be used literally. use PhpCodeQuality\AutoloadValidation\ClassLoader\EnumeratingClassLoader; use PhpCodeQuality\AutoloadValidation\ClassMapGenerator; use PhpCodeQuality\AutoloadValidation\Exception\ParentClassNotFoundException; // Support for Contao 4.1. if (is_dir($path = getcwd() . '/vendor/contao/core-bundle/src/Resources/contao')) { $loader = new \Composer\Autoload\ClassLoader(); foreach (array('classes', 'controllers', 'drivers', 'elements', 'forms', 'library', 'models', 'modules', 'pages', 'widgets') as $subDir) { $classMap = ClassMapGenerator::createMap($path . '/' . $subDir); $loader->addClassMap($classMap); } $loader->register(); } // This is the hack to mimic the Contao auto loader. spl_autoload_register(function ($class) { if (substr($class, 0, 7) === 'Contao\\') { return null; } try { spl_autoload_call('Contao\\' . $class); } catch (ParentClassNotFoundException $exception) { return null; } if (EnumeratingClassLoader::isLoaded('Contao\\' . $class) && !EnumeratingClassLoader::isLoaded($class)) { class_alias('Contao\\' . $class, $class); return true; } return null; });