2014-08-29 19:23:09 +10:00
|
|
|
<?php namespace System\Traits;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Path Maker Trait
|
|
|
|
*
|
|
|
|
* Converts path symbols to relevant points in the filesystem.
|
|
|
|
*
|
|
|
|
* $ - Relative to the plugins directory
|
|
|
|
* ~ - Relative to the application directory
|
|
|
|
*
|
|
|
|
* @package october\system
|
|
|
|
* @author Alexey Bobkov, Samuel Georges
|
|
|
|
*/
|
|
|
|
|
|
|
|
trait PathMaker
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array Known path symbols and their prefixes.
|
|
|
|
*/
|
|
|
|
protected $pathSymbols = [
|
|
|
|
'$' => PATH_PLUGINS,
|
|
|
|
'~' => PATH_BASE,
|
2014-09-15 08:58:42 +10:00
|
|
|
// '/' => PATH_BASE, // @deprecated
|
2014-09-13 15:02:52 +10:00
|
|
|
'@' => PATH_BASE, // @deprecated
|
2014-08-29 19:23:09 +10:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a path.
|
|
|
|
* @param string $path
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function makePath($path, $default = false)
|
|
|
|
{
|
2014-09-13 15:02:52 +10:00
|
|
|
if (!$firstChar = $this->isPathSymbol($path))
|
2014-08-29 19:23:09 +10:00
|
|
|
return $default;
|
|
|
|
|
|
|
|
$_path = substr($path, 1);
|
|
|
|
return $this->pathSymbols[$firstChar] . $_path;
|
|
|
|
}
|
|
|
|
|
2014-09-13 15:02:52 +10:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2014-08-29 19:23:09 +10:00
|
|
|
}
|