/** * @param string $path * @param boolean $absolute * @return string */ public static function getPath($path, $absolute = false) { $project = ProjectManager::getActiveProject(); $resPath = ''; if ($project) { $resPath .= $project->getResourcePath(); } else { $resPath .= ProjectManager::getDefaultProject()->getResourcePath(); } $resPath .= $path; if (!$absolute) { $resPath = str_replace(PathHelper::getBasePath(), '', $resPath); } return PathHelper::normalizePath($resPath); }
/** * Returns the content of * a rendered element * * @param string $viewPath * @param array $config * @param string $wrapper * @return string */ public function render($viewPath, $config = array(), $wrapper = '') { $view = PathHelper::getRealViewPath(ltrim($viewPath, DR_SP), '', Template::getInstance()->getLayout()->getName()); $path = $view; // Handle relative path if (!PathHelper::isAbsolute($viewPath)) { $backtrace = debug_backtrace(); $viewIndex = PathHelper::getFirstViewIndexFromDebugBacktrace($backtrace); if (false === $viewIndex) { throw new Exception\NoViewOriginFoundException('The view "' . $view . '" could not be include. You can render relative path\'s only from an other view.'); } $file = PathHelper::normalizePath($backtrace[$viewIndex]['file']); $dir = pathinfo($file, PATHINFO_DIRNAME); $path = PathHelper::getRealViewFile(PathHelper::normalizePath($dir . DR_SP . $viewPath)); $view = PathHelper::normalizePath(realpath($path)); if ($view == $file) { throw new Exception\RenderRecursionException('The view "' . $view . '" is including itself (Recursion).'); exit; } } /** * Default check & render */ if (!$view || !file_exists($view)) { if (!$view) { $view = $path; } throw new Exception\ViewIncludeNotFoundException('The view "' . $view . '" was not found and could not be included'); } $content = $this->getRenderedHtml($view, $config); if (!empty($wrapper)) { $content = sprintf($wrapper, $content); } return $content; }
/** * Adds the config files to * the local config files var * * @param array $configs */ public function addConfigFiles($configs) { $files = array(); for ($i = 0, $len = count($configs); $i < $len; $i++) { $dir = PathHelper::normalizePath($configs[$i]['dir']); if (!is_dir($dir)) { continue; } $files[$dir] = DirHelper::getFilesByType($dir, $configs[$i]['type'], true); } $files = DirHelper::flattenTree($files); for ($i = 0, $len = count($files); $i < $len; $i++) { $this->configFiles[] = $files[$i]; } // Reload config file list $this->updateFiles(); }
/** * @param string $name * @param string $path * @param array $routeUrlParts */ public function __construct($name, $path) { $this->setName($name); $this->path = PathHelper::normalizePath($path); }