Last active
December 18, 2015 11:39
-
-
Save selvinortiz/5777021 to your computer and use it in GitHub Desktop.
CRAFT:Path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Craft; | |
/** | |
* @=Path: A wrapper for the Craft Path Service API | |
* | |
* Path allows you to access the API in a very flexible and elegant way. | |
* | |
* @author Selvin Ortiz | |
* @package Crafter | |
* | |
* @example | |
* Path::app() > /craft/app | |
* Path::plugins() > /craft/plugins | |
* Path::assets(js/shared.js) > /public/assets/js/shared.js | |
* | |
* The best part is that you can define your own by simply adding a {case} within the {switch} | |
* You can then call Path::{case}() OR Path::{case}(append) | |
* | |
* Only the paths I used the most are currently included but your can extended however you want | |
* | |
* @note | |
* Do not use reserved words within a {case} or PHP will complaint. | |
*/ | |
class Path | |
{ | |
protected static function factory($path='', $append='') | |
{ | |
switch( trim($path) ) | |
{ | |
case 'app': | |
$path = craft()->path->getAppPath(); | |
break; | |
case 'conf': | |
case 'config': | |
$path = craft()->path->getConfigPath(); | |
break; | |
case 'addons': | |
case 'plugins': | |
$path = craft()->path->getPluginsPath(); | |
break; | |
case 'storage': | |
$path = craft()->path->getStoragePath(); | |
break; | |
case 'tpl': | |
case 'tmpl': | |
case 'template': | |
case 'templates': | |
$path = craft()->path->getTemplatesPath(); | |
break; | |
case 'yii': | |
case 'framework': | |
$path = craft()->path->getFrameworkPath(); | |
break; | |
case 'tmp': | |
case 'temp': | |
case 'temporary': | |
$path = craft()->path->getTempPath(); | |
break; | |
case 'runtime': | |
$path = craft()->path->getRuntimePath(); | |
break; | |
case 'log': | |
case 'logs': | |
$path = craft()->path->getLogPath(); | |
break; | |
case 'lib': | |
case 'library': | |
$path = craft()->path->getLibPath(); | |
break; | |
case 'session': | |
case 'sessions': | |
$path = craft()->path->getSessionsPath(); | |
break; | |
case 'cache': | |
$path = craft()->path->getCachePath(); | |
break; | |
case 'pub': | |
case 'html': | |
$path = realpath( craft()->path->getAppPath().'../../public' ).'/'; | |
break; | |
case 'assets': | |
$path = realpath( craft()->path->getAppPath().'../../public/assets' ).'/'; | |
break; | |
case 'content': | |
$path = realpath( craft()->path->getAppPath().'../../public/content' ).'/'; | |
break; | |
default: | |
return false; | |
break; | |
} | |
$append = trim($append); | |
if ($append) | |
{ | |
return $path.ltrim($append, '/'); | |
} | |
return $path; | |
} | |
//-------------------------------------------------------------------------------- | |
public static function __callStatic($method, $args=array()) | |
{ | |
if ( is_array($args) && count($args) ) | |
{ | |
return self::factory($method, $args[0]); | |
} | |
return self::factory($method); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment