Example #1
0
 /**
  * Sets up Autoloading
  *
  * @param string|array path
  * @return this
  */
 public function setLoader()
 {
     if (!class_exists('Eden_Loader')) {
         //require autoload
         require_once dirname(__FILE__) . '/eden/loader.php';
     }
     //set autoload class as the autoload handler
     spl_autoload_register(array(Eden_Loader::i(), 'handler'));
     //we need Eden_Path to fix the path formatting
     if (!class_exists('Eden_Path')) {
         Eden_Loader::i()->addRoot(dirname(__FILE__))->load('Eden_Path');
     }
     //get paths
     $paths = func_get_args();
     //if no paths
     if (empty($paths)) {
         //do nothing more
         return $this;
     }
     //no dupes
     $paths = array_unique($paths);
     //for each path
     foreach ($paths as $i => $path) {
         if (!is_string($path) && !is_null($path)) {
             continue;
         }
         if ($path) {
             //format the path
             $path = (string) Eden_Path::i($path);
         } else {
             $path = $this->_root;
         }
         //if path is not a real path
         if (!is_dir($path)) {
             //append the root
             $path = $this->_root . $path;
         }
         //if the path is still a real path
         if (is_dir($path)) {
             //add the root
             Eden_Loader::i()->addRoot($path);
         }
     }
     return $this;
 }
Example #2
0
 /**
  * Sets a cache path root
  *
  * @param string the root path
  * @return Eden_CacheModel
  */
 public function setRoot($root)
 {
     //argument 1 must be a string
     Eden_Cache_Error::i()->argument(1, 'string');
     $this->_path = (string) Eden_Path::i($root)->absolute();
     return $this;
 }
Example #3
0
if(!class_exists('Eden_Cache')){class Eden_Cache extends Eden_Class{protected $_key=NULL;protected $_path=NULL;protected $_cache=array();public static function i(){return self::_getMultiple(__CLASS__);}public function __construct($root,$key='key.php'){Eden_Cache_Error::i()->argument(1,'string')->argument(2,'string');$this->setKey($key)->setRoot($root)->build();}public function build(){try{$this->_cache=Eden_File::i($this->_path.'/'.$this->_key)->getData();}catch(Eden_Path_Error $e){$this->_cache=array();}return $this;}public function get($key,$default=NULL){Eden_Cache_Error::i()->argument(1,'string');if($this->keyExists($key)){return Eden_File::i($this->_cache[$key])->getData();}return $default;}public function getCreated($key){Eden_Cache_Error::i()->argument(1,'string');if($this->keyExists($key)){return Eden_File::i($this->_cache[$key])->getTime();}return 0;}public function getKeys(){return array_keys($this->_cache);}public function keyExists($key){Eden_Cache_Error::i()->argument(1,'string');return isset($this->_cache[$key]) && file_exists($this->_cache[$key]);}public function remove($key){Eden_Cache_Error::i()->argument(1,'string');if(isset($this->_cache[$key])){unset($this->_cache[$key]);}Eden_File::i($this->_path.'/'.$this->_key)->setData($this->_cache);return $this;}public function set($key,$path,$data){Eden_Cache_Error::i()->argument(1,'string')->argument(2,'string');$path=$this->_path.Eden_Path::i($path);Eden_File::i($path)->setData($data);$this->_cache[$key]=$path;Eden_File::i($this->_path.'/'.$this->_key)->setData($this->_cache);return $this;}public function setKey($key){Eden_Cache_Error::i()->argument(1,'string');$this->_key=$key;return $this;}public function setRoot($root){Eden_Cache_Error::i()->argument(1,'string');$this->_path=(string) Eden_Path::i($root)->absolute();return $this;}}class Eden_Cache_Error extends Eden_Error{public static function i($message=NULL,$code=0){$class=__CLASS__;return new $class($message,$code);}}}