/** * inherit * * @param string $dir Directory * * @throws \Forge\Application\Exception * @return array */ public function inherit($dir) { $classmap = array(); $composer = $dir . DS . self::COMPOSER; $autoloadClassmap = $dir . DS . self::CLASSMAP; if (file_exists($autoloadClassmap)) { $content = (include $autoloadClassmap); $classmap = array_merge($classmap, $content); } else { if (file_exists($composer)) { set_include_path(get_include_path() . PATH_SEPARATOR . $dir); $json = json_decode(file_get_contents($composer)); if (isset($json->autoload)) { if (isset($json->autoload->{'psr-0'})) { $psr = $json->autoload->{'psr-0'}; $key = key($psr); if (isset($psr->{$key})) { $src = $dir . DS . $psr->{$key}; $srcFiles = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($src)); $phpFiles = new \RegexIterator($srcFiles, self::ISPHP); foreach ($phpFiles as $phpFile) { $class = preg_replace(array(self::ISPHP, '/\\//'), array('', '\\'), str_replace($src, '', $phpFile->getPathName())); if (!preg_match('/^' . $key . '/', $class)) { throw new Exception('Module ' . $key . ' should have the same namespace however it\'s declared as ' . $class); } $classmap[$class] = str_replace($dir, '', $phpFile->getPathName()); } } } if (isset($json->autoload->{'psr-4'})) { // @todo add psr-4 } } $view = new View(); $view->setTemplate(__DIR__ . DS . self::TEMPLATE); $view->classmap = $classmap; $view->save($dir . DS . self::CLASSMAP); } } return $classmap; }
/** * Render * * @throws Exception */ public function render() { $content = ''; $this->callEvent($this->getModule(), 'preRender'); $theme = self::getTheme(); if ($this->isThemeEnabled() && $theme instanceof Theme) { $layout = new View(); $layout->setTemplate($theme->getLayout()); $layout->config = $this->getConfig(); $layout->request = $this->getRequest(); $layout->menus = $this->menus; $layout->theme = $theme; $layout->application = $this; $layout->content = $this->getContent(); $module = $this->getModule(); foreach ($module as $key => $value) { if ($key == 'content') { $layout->content .= $value; } else { if (isset($layout->{$key})) { throw new Exception('View is using a reserved variable ' . $key); } else { $layout->{$key} = $value; } } } $globals = self::getGlobals(); if ($globals) { foreach ($globals as $key => $value) { $layout->{$key} = $value; } } $content = $layout->render(); } else { $content = $this->getContent(); } echo $content; $this->callEvent($this->getModule(), 'postRender'); }