/** * Run method * * @return void */ public function run() { // register the default autoloader require SERVER_AUTOLOADER; // iterate over all structures and generate them foreach ($this->structures as $structure) { $this->generator->create($structure); } }
/** * Will load any given structure based on it's availability in our structure map which depends on the configured * project directories. * If the structure cannot be found we will redirect to the composer autoloader which we registered as a fallback * * @param string $className The name of the structure we will try to load * * @return boolean */ public function loadClass($className) { // Might the class be a omitted one? If so we can require the original. if ($this->config->hasValue('autoloader/omit')) { $omittedNamespaces = $this->config->getValue('autoloader/omit'); foreach ($omittedNamespaces as $omitted) { // If our class name begins with the omitted part e.g. it's namespace if (strpos($className, str_replace('\\\\', '\\', $omitted)) === 0) { return false; } } } // Do we have the file in our cache dir? If we are in development mode we have to ignore this. if ($this->config->getValue('environment') !== 'development') { $cachePath = $this->config->getValue('cache/dir') . DIRECTORY_SEPARATOR . str_replace('\\', '_', $className) . '.php'; if (is_readable($cachePath)) { $res = fopen($cachePath, 'r'); $str = fread($res, 384); $success = preg_match('/' . Dictionaries\Placeholders::ORIGINAL_PATH_HINT . '(.+)' . Dictionaries\Placeholders::ORIGINAL_PATH_HINT . '/', $str, $tmp); if ($success > 0) { $tmp = explode('#', $tmp[1]); $path = $tmp[0]; $mTime = $tmp[1]; if (filemtime($path) == $mTime) { // the cached file is recent, load it require $cachePath; return true; } } } } // If we are loading something that the autoloader needs to function, then we have to skip to composer if (strpos($className, 'AppserverIo\\Doppelgaenger') === 0 && strpos($className, 'AppserverIo\\Doppelgaenger\\Tests') === false || strpos($className, 'PHP') === 0 || strpos($className, 'AppserverIo\\Psr\\MetaobjectProtocol') === 0 || strpos($className, 'AppserverIo\\Lang\\') === 0) { return false; } // If the structure map did not get filled by now we will do so here if ($this->structureMap->isEmpty()) { $this->structureMap->fill(); } // Get the file from the map $file = $this->structureMap->getEntry($className); // Did we get something? If not return false. if ($file === false) { return false; } // We are still here, so we know the class and it is not omitted. Does it contain annotations then? if (!$file->hasAnnotations() || !$file->isEnforced()) { // on un-enforced classes we will require the original require $file->getPath(); return true; } // So we have to create a new class definition for this original class. // Get a current cache instance if we do not have one already. if ($this->cache === null) { // We also require the classes of our maps as we do not have proper autoloading in place $this->cache = new CacheMap($this->getConfig()->getValue('cache/dir'), array(), $this->config); } $this->generator = new Generator($this->structureMap, $this->cache, $this->config, $this->aspectRegister); // Create the new class definition if ($this->generator->create($file, $this->config->getValue('enforcement/contract-inheritance')) === true) { // Require the new class, it should have been created now $file = $this->generator->getFileName($className); if ($file !== false && is_readable($file) === true) { require $file; return true; } } else { return false; } // Still here? That sounds like bad news! return false; }