/** * If the class isn't already loaded, and an autoloader hasn't been set up * for the class (i.e. class not loaded), we will set up our own autoloader * for all namespaces and dirs registered and attempt to load the class * * @param $className * @throws Exception */ protected function autoloadClass($className) { // has the class be loaded? if (class_exists($className)) { return; } if (!$this->ourLoader) { $this->ourLoader = new Loader(); $ourLoaderNamespaces = array(); $ourLoaderDirs = array(); foreach ($this->namespaces as $ns) { if ($ns['ns']) { $ourLoaderNamespaces[$ns['ns']] = $ns['dir']; } else { $ourLoaderDirs[] = $ns['dir']; } } $this->ourLoader->registerNamespaces($ourLoaderNamespaces); $this->ourLoader->registerDirs($ourLoaderDirs); } $loaded = $this->ourLoader->autoLoad($className); if (!$loaded) { throw new \Exception('Unable to load autoload class ' . $className); } }
/** * AutoLoad * * @param string $className */ function autoLoad($className) { $array = explode('\\', $className); if (array_key_exists($array[0], $this->_namespaces)) { $array[0] = $this->_namespaces[$array[0]]; $class = array_pop($array); array_push($array, str_replace("_", DIRECTORY_SEPARATOR, $class)); $file = implode($array, DIRECTORY_SEPARATOR); foreach ($this->_extensions as $ext) { if (file_exists($file . ".{$ext}")) { require $file . ".{$ext}"; return true; } } } //If it did not fit standard PSR-0, pass it on to the original Phalcon autoloader parent::autoLoad($className); }
/** * Collects information from input directory * Returns collection of all information grabbed from input directory * * @return array */ public function build() { if ($this->eventsManager instanceof ManagerInterface) { $this->eventsManager->fire('generator:beforeBuild', $this); } $collections = array(); $files = $this->setupClassesAutoloader(); foreach ($files as $className => $file) { if (isset($this->options['verbose']) && $this->options['verbose']) { echo '# Processing file : ' . $file . PHP_EOL; } $this->loader->autoLoad($className); $collection = $this->getClassCollection($className); if (empty($collection)) { continue; } $collections[$className] = $this->getClassCollection($className); } if ($this->eventsManager instanceof ManagerInterface) { $this->eventsManager->fire('generator:afterBuild', $this, $collections); } return $collections; }
public function autoLoad($className) { return parent::autoLoad($className); }