/** * Init * This method must return self * @return self */ public function init() { parent::init(); $reflector = new \ReflectionClass($this); $this->_applicationNamespace = $reflector->getNamespaceName(); //Define BASE Asset paths $assetConfig = $this->config()->get("assets"); $assetPath = $assetConfig->get("assets", "assets"); if (!defined("BASE_ASSETS")) { define("BASE_ASSETS", Router::buildPath(SITE_URL, $assetPath)); } if (!defined("BASE_IMAGES")) { define("BASE_IMAGES", Router::buildPath(SITE_URL, $assetPath, $assetConfig->get("images", "images"))); } if (!defined("BASE_STYLES")) { define("BASE_STYLES", Router::buildPath(SITE_URL, $assetPath, $assetConfig->get("css", "css"))); } if (!defined("BASE_SCRIPTS")) { define("BASE_SCRIPTS", Router::buildPath(SITE_URL, $assetPath, $assetConfig->get("js", "js"))); } if (!defined("BASE_TEMPLATES")) { define("BASE_TEMPLATES", Filesystem::buildPath(PROJECT_PATH, $assetConfig->get("templates", "Templates"))); } return $this; }
/** * Template Search Paths * @return Generator<string> - The filepath to the current application directory */ public function templateSearchPaths() { //Search order // - Application/Templates/Theme/Controller // - Application/Templates/Theme // - Base/Templates/Theme/Application/Controller // - Base/Templates/Theme/Application // - Application/Templates/Controller // - Application/Templates // - Application/ // - Base/Templates/Theme // - Base/Templates/ $assetConfig = $this->config("assets"); $templatesPath = $assetConfig->get("templates", "Templates"); (yield null); //This allows the use of an absolute path to be used when merging paths. (yield Filesystem::buildPath($this->applicationPath, $templatesPath, $this->theme(), $this->_controllerName)); (yield Filesystem::buildPath($this->applicationPath, $templatesPath, $this->theme())); (yield Filesystem::buildPath(PROJECT_PATH, $templatesPath, $this->theme(), basename($this->applicationPath), $this->_controllerName)); (yield Filesystem::buildPath(PROJECT_PATH, $templatesPath, $this->theme(), basename($this->applicationPath))); (yield Filesystem::buildPath($this->applicationPath, $templatesPath, $this->_controllerName)); (yield Filesystem::buildPath($this->applicationPath, $templatesPath)); (yield Filesystem::buildPath($this->applicationPath)); (yield Filesystem::buildPath(PROJECT_PATH, $templatesPath, $this->theme())); (yield Filesystem::buildPath(PROJECT_PATH, $templatesPath)); }
/** * Asset Search Paths * @param string $type - CSS | JS | IMAGES * @return Generator<string> - A file path to search for self */ private function assetSearchPaths($type) { //Search order // - Application/self/{type}/Theme/ // - Application/self/{type} // - Base/self/{type}/Theme // - Base/self/{type} $assetConfig = $this->config("assets"); $assetsPath = $assetConfig->get("assets", "Assets"); $typePath = $assetConfig->get($type, $type . DIRECTORY_SEPARATOR); $searchPaths[] = null; //This allows the use of an absolute path to be used when merging paths. if ($this->controller) { $searchPaths[] = Filesystem::buildPath($this->controller->applicationPath, $assetsPath, $typePath, $this->controller->theme()); $searchPaths[] = Filesystem::buildPath($this->controller->applicationPath, $assetsPath, $typePath); } $searchPaths[] = Filesystem::buildPath(PROJECT_PATH, $assetsPath, $typePath, $this->controller->theme()); $searchPaths[] = Filesystem::buildPath(PROJECT_PATH, $assetsPath, $typePath); foreach ($searchPaths as $searchPath) { (yield $searchPath ? static::urlForPath($searchPath) : $searchPath); } }