From efbb0351db7d2edfa9a24f8584daa42b636d06df Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Sat, 13 Sep 2014 15:02:52 +1000 Subject: [PATCH] ViewMaker now uses PathMaker --- modules/backend/traits/ViewMaker.php | 6 ++++-- modules/system/traits/PathMaker.php | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/modules/backend/traits/ViewMaker.php b/modules/backend/traits/ViewMaker.php index 9511d2ad3..8bfa68ec1 100644 --- a/modules/backend/traits/ViewMaker.php +++ b/modules/backend/traits/ViewMaker.php @@ -16,6 +16,8 @@ use System\Classes\SystemException; trait ViewMaker { + use \System\Traits\PathMaker; + /** * @var array A list of variables to pass to the page. */ @@ -50,7 +52,7 @@ trait ViewMaker */ public function makePartial($partial, $params = [], $throwException = true) { - if (!in_array(substr($partial, 0, 1), ['/', '@']) && realpath($partial) === false) + if (!$this->isPathSymbol($partial) && realpath($partial) === false) $partial = '_' . strtolower($partial) . '.htm'; $partialPath = $this->getViewPath($partial); @@ -151,7 +153,7 @@ trait ViewMaker if (!$viewPath) $viewPath = $this->viewPath; - $fileName = str_replace('@', PATH_BASE, $fileName); + $fileName = $this->makePath($fileName, $fileName); if (substr($fileName, 0, 1) == '/' || realpath($fileName) !== false) return $fileName; diff --git a/modules/system/traits/PathMaker.php b/modules/system/traits/PathMaker.php index ba99e0313..4aad14ea3 100644 --- a/modules/system/traits/PathMaker.php +++ b/modules/system/traits/PathMaker.php @@ -21,6 +21,8 @@ trait PathMaker protected $pathSymbols = [ '$' => PATH_PLUGINS, '~' => PATH_BASE, + '/' => PATH_BASE, // @deprecated + '@' => PATH_BASE, // @deprecated ]; /** @@ -30,13 +32,25 @@ trait PathMaker */ public function makePath($path, $default = false) { - $firstChar = substr($path, 0, 1); - - if (!isset($this->pathSymbols[$firstChar])) + if (!$firstChar = $this->isPathSymbol($path)) return $default; $_path = substr($path, 1); return $this->pathSymbols[$firstChar] . $_path; } + /** + * Returns true if the path uses a symbol. + * @param string $path + * @return boolean + */ + public function isPathSymbol($path) + { + $firstChar = substr($path, 0, 1); + if (isset($this->pathSymbols[$firstChar])) + return $firstChar; + + return false; + } + } \ No newline at end of file