/** * Adds a child to Composite, initializing it, if current Composite is * initialized. * * @api * @param \Nethgui\Module\ModuleInterface $childModule * @return Composite */ public function addChild(\Nethgui\Module\ModuleInterface $childModule) { if (isset($this->children[$childModule->getIdentifier()])) { throw new \LogicException(sprintf('%s: the module identifier "%s" is already registered as child!', __CLASS__, $childModule->getIdentifier()), 1322818691); } $this->children[$childModule->getIdentifier()] = $childModule; $childModule->setParent($this); if ($this->isInitialized() && !$childModule->isInitialized()) { call_user_func($this->dependencyInjector, $childModule); $childModule->initialize(); } return $this; }
public function bind(\Nethgui\Controller\RequestInterface $request) { parent::bind($request); $fileName = \Nethgui\array_head($request->getPath()); if (preg_match('/[a-z][a-z0-9]+(.rst)/i', $fileName) == 0 && preg_match('/[a-z][a-z0-9]+(.html)/i', $fileName) == 0) { throw new \Nethgui\Exception\HttpException('Not found', 404, 1322148405); } // Now assuming a trailing ".rst" or ".html" suffix. if (substr($fileName, -3) == 'rst') { $this->module = $this->getModuleSet()->getModule(substr($fileName, 0, -4)); } else { //html $this->module = $this->getModuleSet()->getModule(substr($fileName, 0, -5)); } if (is_null($this->module)) { throw new \Nethgui\Exception\HttpException('Not found', 404, 1322148406); } $this->module->setPlatform($this->getPlatform()); if (!$this->module->isInitialized()) { $this->module->initialize(); } }