/** * Registers default autoloading for the Extension. * * @return \Composer\Autoload\ClassLoader */ public function registerDefaultAutoloading() { $loader = new ClassLoader(); $loader->add($this->namespace, $this->path . '/src'); $loader->register(); $loader->setUseIncludePath(true); return $this->autoloaders[] = $loader; }
protected function loadModule($modCfgArray, $modIdx) { $cfg = new Config($modCfgArray['default']); $ns = $cfg->get('namespace'); // If this class can't be loaded, enable the autoload using the composer class loader. if (!empty($ns)) { // Full directory of the module to be initialized. $dir = $cfg->get('directory'); $parentDir = $this->config->get('directory'); $parentModulesDir = $this->config->get('modulesDir'); if (preg_match('/^\\//', $dir) > 0) { } else { if (preg_match('/^\\//', $parentModulesDir) > 0) { $dir = $parentModulesDir . DIRECTORY_SEPARATOR . $dir; } else { $dir = $parentDir . DIRECTORY_SEPARATOR . $parentModulesDir . DIRECTORY_SEPARATOR . $dir; } } $dirReal = realpath($dir) . DIRECTORY_SEPARATOR; if (!$dirReal) { throw new \Exception("The directory {$dir} of the child module does not exists or is not readable."); } // Override the current module 'directory' value $cfg->set('directory', $dir); // Add the namespacec to the composer ClassLoader $loader = new ClassLoader(); $loader->add($ns, $dir); $loader->register(); $loader->setUseIncludePath(true); } if ($cn = $cfg->get('moduleClassName')) { $mClass = $ns . '\\' . $cn; } else { // Use the default moduleClassName. See the top of this file. $mClass = $this->config->get('moduleClassName'); } // Add others options sets, if provided foreach ($modCfgArray as $k => $optSet) { if ($k == 'default') { continue; } $cfg->set($optSet, null, $k); } // Instance the module. $mod = new $mClass($cfg, $this, $this->injections); return $this->children[$modIdx] = $mod; }
/** * Register the class autoloading. * * @return void */ protected function registerAutoloading() { // Instantiate the class loader. $loader = new ClassLoader(); // Add the extension namespace and path. $loader->add($this->namespace, $this->path . '/src'); // Register the loader. $loader->register(); // Use the path for includes. $loader->setUseIncludePath(true); }