The class stores namespaces and classes and automatically loads the class
files upon their first usage. It uses a mapper array to support complex
nesting and arbitrary subfolders to store the class files in.
Usage:
ClassLoader::addNamespace('Custom');
ClassLoader::addClass('Custom\\Calendar', 'calendar/Calendar.php');
/** * Returns all children of a given class * @param $strNamespace * * @return array */ public static function getChildClasses($strQualifiedClassName) { $arrOptions = array(); foreach (array_keys(ClassLoader::getClasses()) as $strName) { if (in_array($strQualifiedClassName, static::getParentClasses($strName))) { $arrOptions[$strName] = $strName; } } asort($arrOptions); return $arrOptions; }
public static function getImporterClasses() { $arrOptions = array(); foreach (array_keys(\Contao\ClassLoader::getClasses()) as $strName) { if (strpos($strName, 'HeimrichHannot\\EntityImport\\') !== false && ($strName == 'HeimrichHannot\\EntityImport\\Importer' || in_array('HeimrichHannot\\EntityImport\\Importer', \HeimrichHannot\HastePlus\Classes::getParentClasses($strName)))) { $arrOptions[$strName] = $strName; } } sort($arrOptions); return $arrOptions; }
/** * Initializes the framework. */ private function initializeFramework() { // Set the error_reporting level error_reporting($this->errorLevel); $this->includeHelpers(); // TODO: use Monolog to log errors $this->iniSet('error_log', $this->rootDir . '/system/logs/error.log'); $this->includeBasicClasses(); // Set the container System::setContainer($this->container); // Preload the configuration (see #5872) $this->config->preload(); // Register the class loader ClassLoader::scanAndRegister(); $this->initializeLegacySessionAccess(); $this->setDefaultLanguage(); // Fully load the configuration $this->config->initialize(); $this->validateInstallation(); Input::initialize(); $this->setTimezone(); // Set the mbstring encoding if (USE_MBSTRING && function_exists('mb_regex_encoding')) { mb_regex_encoding($this->config->get('characterSet')); } $this->triggerInitializeSystemHook(); $this->handleRequestToken(); }
/** * Boots the helper system. */ private function bootHelperSystem() { $contaoDir = $this->getRootDir() . '/../vendor/contao/core-bundle'; require_once $contaoDir . '/src/Resources/contao/config/constants.php'; require_once $contaoDir . '/src/Resources/contao/helper/functions.php'; // Register the class loader $libraryLoader = new LibraryLoader($this->getRootDir()); $libraryLoader->register(); Config::preload(); // Create the container $this->container = ContainerFactory::create($this); System::setContainer($this->container); ClassLoader::scanAndRegister(); }
<?php /** * Copyright (C) 2015 Christian Barkowsky * * @package news4ward_robots * @author Christian Barkowsky <*****@*****.**> * @copyright Christian Barkowsky <http://christianbarkowsky.de> * @license LGPL */ \Contao\ClassLoader::addNamespace('CBW'); /** * Register the classes */ ClassLoader::addClasses(array('CBW\\CBWNews4wardRobots' => 'system/modules/news4ward_robots/modules/CBWNews4wardRobots.php'));
/** * Initializes the framework. */ private function initializeFramework() { // Set the error_reporting level error_reporting($this->errorLevel); $this->includeHelpers(); $this->includeBasicClasses(); // Set the container System::setContainer($this->container); /** @var Config $config */ $config = $this->getAdapter('Contao\\Config'); // Preload the configuration (see #5872) $config->preload(); // Register the class loader ClassLoader::scanAndRegister(); $this->initializeLegacySessionAccess(); $this->setDefaultLanguage(); // Fully load the configuration $config->getInstance(); $this->validateInstallation(); Input::initialize(); $this->setTimezone(); $this->triggerInitializeSystemHook(); $this->handleRequestToken(); }
<?php /** * Rel Canonical * * @copyright Christian Barkowsky 2013-2016 * @package contao-rel-canonical * @author Christian Barkowsky <http://www.christianbarkowsky.de> * @license LGPL */ \Contao\ClassLoader::addNamespace('Barkowsky\\RelCanonical'); /** * Register the classes */ ClassLoader::addClasses(array('Barkowsky\\RelCanonical\\ClassRelCanonical' => 'system/modules/rel-canonical/classes/ClassRelCanonical.php', 'Barkowsky\\RelCanonical\\ModuleEventReader' => 'system/modules/rel-canonical/modules/ModuleEventReaderRelCannonical.php', 'Barkowsky\\RelCanonical\\ModuleNewsReader' => 'system/modules/rel-canonical/modules/ModuleNewsReaderRelCannonical.php', 'Barkowsky\\RelCanonical\\ModuleFaqReader' => 'system/modules/rel-canonical/modules/ModuleFaqReaderRelCannonical.php'));
<?php /** * Copyright (C) 2015-2016 Christian Barkowsky * * @author Christian Barkowsky <*****@*****.**> * @copyright Christian Barkowsky <http://christianbarkowsky.de> * @package tiny-compress-images * @license LGPL */ \Contao\ClassLoader::addNamespace('Barkowsky'); /** * Register the classes */ ClassLoader::addClasses(array('Barkowsky\\TinyCompressImages' => 'system/modules/tiny-compress-images/classes/TinyCompressImages.php'));
* Copyright (c) 2005-2015 Leo Feyer * * @license LGPL-3.0+ */ use Contao\ClassLoader; use Contao\Config; use Contao\InstallationBundle\ClassLoader\LibraryLoader; use Contao\InstallationBundle\Controller\InstallationController; use Contao\InstallationBundle\DependencyInjection\ContainerFactory; use Contao\System; error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_USER_DEPRECATED); $loader = (require_once __DIR__ . '/../vendor/autoload.php'); require_once __DIR__ . '/../app/AppKernel.php'; require_once __DIR__ . '/../vendor/contao/core-bundle/src/Resources/contao/config/constants.php'; require_once __DIR__ . '/../vendor/contao/core-bundle/src/Resources/contao/helper/functions.php'; $kernel = new AppKernel('prod', false); // Un-normalize the path (see #208) $rootDir = strtr($kernel->getRootDir(), '/', DIRECTORY_SEPARATOR); // Register the class loader $libraryLoader = new LibraryLoader($rootDir); $libraryLoader->register(); Config::preload(); // Create the container $container = ContainerFactory::create($rootDir); System::setContainer($container); ClassLoader::scanAndRegister(); // Run the controller $controller = new InstallationController(); $controller->setContainer($container); $response = $controller->indexAction(); $response->send();
private function autoload($parameters, $bridgeNamespace, $module) { ClassLoader::addNamespace($bridgeNamespace); ClassLoader::addClasses(array($bridgeNamespace . '\\' . $module => $parameters['path'], $bridgeNamespace . 'Bridge\\' . $module => $this->cacheDir . '/' . $bridgeNamespace . 'Bridge/' . $module . '.php')); }