ViewMaker now uses PathMaker
This commit is contained in:
parent
277a2daf7b
commit
efbb0351db
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue