protected static function _getSingleton($class = NULL) { if (is_null($class) && function_exists('get_called_class')) { $class = get_called_class(); } $class = Eden_Route::i()->getClass()->getRoute($class); if (!isset(self::$_instances[$class])) { self::$_instances[$class] = self::_getInstance($class); } return self::$_instances[$class]; }
if(!class_exists('Eden')){function eden(){$class=Eden::i();if(func_num_args()==0){return $class;}$args=func_get_args();return $class->__invoke($args);}class Eden extends Eden_Event{protected $_root=NULL;protected static $_active=NULL;public static function i(){return self::_getSingleton(__CLASS__);}public function __construct(){if(!self::$_active){self::$_active=$this;}$this->_root=dirname(__FILE__);}public function __call($name,$args){try{return parent::__call($name,$args);}catch(Eden_Route_Exception $e){return parent::__call('Eden_'.$name,$args);}}public function setRoot($root){Eden_Error::i()->argument(1,'string');if(!class_exists('Eden_Path')){Eden_Loader::i()->load('Eden_Path');}$this->_root=(string) Eden_Path::i($root);return $this;}public function getRoot(){return $this->_root;}public function getActiveApp(){return self::$_active;}public function setLoader(){if(!class_exists('Eden_Loader')){require_once dirname(__FILE__).'/eden/loader.php';}spl_autoload_register(array(Eden_Loader::i(),'handler'));if(!class_exists('Eden_Path')){Eden_Loader::i()->addRoot(dirname(__FILE__))->load('Eden_Path');}$paths=func_get_args();if(empty($paths)){return $this;}$paths=array_unique($paths);foreach($paths as $i=>$path){if(!is_string($path) && !is_null($path)){continue;}if($path){$path=(string) Eden_Path::i($path);}else{$path=$this->_root;}if(!is_dir($path)){$path=$this->_root.$path;}if(is_dir($path)){Eden_Loader::i()->addRoot($path);}}return $this;}public function routeClasses($routes){Eden_Error::i()->argument(1,'string','array','bool');$route=Eden_Route::i()->getClass();if($routes===true){$route->route('Cache','Eden_Cache')->route('Registry','Eden_Registry')->route('Model','Eden_Model')->route('Collection','Eden_Collection')->route('Cookie','Eden_Cookie')->route('Session','Eden_Session')->route('Template','Eden_Template')->route('Curl','Eden_Curl')->route('Event','Eden_Event')->route('Path','Eden_Path')->route('File','Eden_File')->route('Folder','Eden_Folder')->route('Image','Eden_Image')->route('Mysql','Eden_Mysql')->route('Type','Eden_Type');return $this;}if(is_string($routes)){$routes=include($routes);}foreach($routes as $alias=>$class){$route->route($alias,$class);}return $this;}public function routeMethods($routes){Eden_Error::i()->argument(1,'string','array','bool');$route=Eden_Route::i()->getMethod();if(is_bool($routes)){$route->route(NULL,'output','Eden_Debug');return $this;}if(is_string($routes)){$routes=include($routes);}foreach($routes as $method=>$routePath){if(is_string($routePath)){$routePath=array($routePath);}if(is_array($routePath) && !empty($routePath)){if(count($routePath)==1){$routePath[]=$method;}$route->route($method,$routePath[0],$routePath[1]);}}return $this;}public function startSession(){Eden_Session::i()->start();return $this;}public function setTimezone($zone){Eden_Error::i()->argument(1,'string');date_default_timezone_set($zone);return $this;}}}
/** * Sets method routes * * @param string|array routes * @return Eden_Framework */ public function routeMethods($routes) { Eden_Error::i()->argument(1, 'string', 'array', 'bool'); $route = Eden_Route::i()->getMethod(); if (is_bool($routes)) { $route->route(NULL, 'output', 'Eden_Debug'); return $this; } if (is_string($routes)) { $routes = (include $routes); } //walk the routes foreach ($routes as $method => $routePath) { //if the path is a string if (is_string($routePath)) { //turn it into an array $routePath = array($routePath); } //if the path is an array and it's not empty if (is_array($routePath) && !empty($routePath)) { //if the size is 1 if (count($routePath) == 1) { //they mean the methods have the same name $routePath[] = $method; } //route the method $route->route($method, $routePath[0], $routePath[1]); } } return $this; }
public function routeMethods($routes) { Eden_Error::i()->argument(1, 'string', 'array', 'bool'); $route = Eden_Route::i()->getMethod(); if (is_bool($routes)) { $route->route(NULL, 'output', 'Eden_Debug'); return $this; } if (is_string($routes)) { $routes = (include $routes); } foreach ($routes as $method => $routePath) { if (is_string($routePath)) { $routePath = array($routePath); } if (is_array($routePath) && !empty($routePath)) { if (count($routePath) == 1) { $routePath[] = $method; } $route->route($method, $routePath[0], $routePath[1]); } } return $this; }