Example #1
0
 /**
  * Constructor for the evergreen class that sets up all the necessary parts of the framework so it can run.
  * 
  * @access public
  */
 public function __construct()
 {
     $starttime = microtime(true);
     try {
         // register the autoloaders
         Autoloader::register();
         // setup error handling
         set_error_handler(array("Config", "logError"), ini_get("error_reporting"));
         // load the main config.php file
         if (file_exists(Reg::get("Path.physical") . '/config/config.php')) {
             include_once Reg::get("Path.physical") . '/config/config.php';
         } else {
             echo "You are missing the configuration file and without it Evergreen cannot run.";
             exit;
         }
         // load the main errors.php file
         if (file_exists(Reg::get("Path.physical") . '/config/errors.php')) {
             include Reg::get("Path.physical") . '/config/errors.php';
         }
         // check if the welcome content is present and if it is show it
         if (file_exists(Reg::get("Path.physical") . '/public/welcome.php')) {
             // Load the welcome content
             include Reg::get("Path.physical") . '/public/welcome.php';
             exit;
         }
         // code that is run at the exit of the script
         register_shutdown_function(array($this, 'shutdown'), $starttime);
         // process the uri and setup the Reg variables
         Config::processURI();
         // wait till after all the config files are loaded before loading in the autoload files
         Autoloader::loadFiles();
         // build the controller class name
         $load['name'] = Config::uriToClass(Reg::get("URI.working.controller"));
         if (Reg::hasVal("Branch.name")) {
             $load['branch'] = Config::uriToClass(Reg::get("Branch.name"));
         }
         $load['type'] = 'Controller';
         $load = implode('_', $load);
         // create an instance of the controller
         $controller = new $load();
         // run the _showView method in the loaded controller
         $controller->_showView();
     } catch (EvergreenException $e) {
         // handler for the EvergreenException class
         $e->processError();
     } catch (Exception $e) {
         // handler for general exceptions
         if (Config::read("System.mode") != "development") {
             echo Config::read("Error.generalErrorMessage");
             exit;
         } else {
             echo $e;
         }
     }
 }
Example #2
0
 /**
  * Checks if a view exists by file, method, or both.
  * 
  * @access protected
  * @final
  * @param array|string $args Can be either the name of the view or an array with name and controller defined
  * @param string $controller The name of the controller where the view is located, if left blank assumes the current controller
  * @param mixed $checkmethod Indicates whether to check if the method exists, file exists, or both
  * @return boolean true if the view exists and boolean false if not
  */
 protected final function _viewExists($args, $controller = "", $checkmethod = false)
 {
     $args = func_get_args();
     if (count($args) < 1 || count($args) > 4) {
         return false;
     }
     if (count($args) == 1 && is_array($args[0])) {
         $args = $args[0];
     } else {
         $checkmethod = false;
         if (is_bool($args[count($args) - 1]) === true || $args[count($args) - 1] == 'both') {
             $checkmethod = array_pop($args);
         }
         $args = array_combine(array_merge(array_slice(array('name', 'controller', 'branch'), 0, count($args)), (array) 'checkmethod'), array_merge($args, (array) $checkmethod));
         unset($checkmethod);
     }
     // call hook
     Hook::call('Controller.viewExists.before', array(&$args));
     if (empty($args['name'])) {
         return false;
     }
     if (empty($args['controller'])) {
         $args['controller'] = $this->params['controller'];
     }
     if (empty($args['branch']) && Reg::hasVal('Branch.name')) {
         $args['branch'] = Reg::get('Branch.name');
     }
     if (!empty($args['branch']) && $args['branch'] == Reg::get('System.rootIdentifier')) {
         unset($args['branch']);
     }
     if (!isset($args['checkmethod'])) {
         $args['checkmethod'] = false;
     }
     if ($args['name'][0] != '_' && (!isset($this->bounceback['check']) || $this->bounceback['check'] != $args['controller']) && !in_array($args['controller'], $this->notAView)) {
         if ($args['checkmethod'] === true) {
             $load['name'] = Config::uriToClass(Config::fileToClass($args['controller']));
             if (!empty($args['branch'])) {
                 $load['branch'] = Config::uriToClass(Config::fileToClass($args['branch']));
             }
             $load['type'] = 'Controller';
             $load = implode('_', $load);
             if (is_callable(array($load, Config::uriToMethod(Config::fileToMethod($args['name'])))) && method_exists($load, Config::uriToMethod(Config::fileToMethod($args['name'])))) {
                 $return = true;
             } else {
                 $return = false;
             }
         } else {
             $path = Reg::get("Path.physical") . ($args['branch'] ? "/branches/" . Config::uriToFile(Config::classToFile($args['branch'])) : "") . "/views/" . Config::uriToFile(Config::classToFile($args['controller'])) . "/" . Config::uriToFile(Config::methodToFile($args['name'])) . ".php";
             // call hook
             Hook::call('Controller.viewExists.setPath', array(&$args, &$path));
             if (file_exists($path)) {
                 if ($args['checkmethod'] == 'both') {
                     $load['name'] = Config::uriToClass(Config::fileToClass($args['controller']));
                     if (!empty($args['branch'])) {
                         $load['branch'] = Config::uriToClass(Config::fileToClass($args['branch']));
                     }
                     $load['type'] = 'Controller';
                     $load = implode('_', $load);
                     if (is_callable(array($load, Config::uriToMethod(Config::fileToMethod($args['name'])))) && method_exists($load, Config::uriToMethod(Config::fileToMethod($args['name'])))) {
                         $return = true;
                     } else {
                         $return = false;
                     }
                 } else {
                     $return = true;
                 }
             } else {
                 $return = false;
             }
             unset($path);
         }
     } else {
         $return = false;
     }
     // call hook
     Hook::call('Controller.viewExists.after', array(&$return));
     return $return;
 }
 /**
  * Loads the url for the error. If the url points to a page inside the framework the function attempts to load it and handles any errors
  * or issues associated such as loading in a default error. If the url points to a page outside the framework then header location is set
  * and execution is stopped.
  * 
  * @access public
  * @static
  * @final
  * @param string|array $url The url that should be loaded can be the url or an array in the URI.map format
  */
 public function loadURL($url)
 {
     // call hook
     Hook::call('Exception.loadURL.before', array(&$url));
     if (!empty($url)) {
         if (!is_array($url) && preg_match("/^(http:|https:|ftp:|ftps:)/im", $url)) {
             // call hook
             Hook::call('Exception.loadURL.redirect', array(&$url));
             header('Location: ' . $url);
             header('Connection: close');
             exit;
         }
         if (is_array($url)) {
             $url = '/' . implode('/', array_merge(Reg::get("URI.map"), $url));
         }
         $url = str_replace(Reg::get('Path.root'), "", $url);
         $_SERVER['REQUEST_URI'] = $url;
         Reg::set("URI.working", $url);
         Reg::del("Branch.name");
         Config::processURI();
         $load['name'] = Config::uriToClass(Reg::get("URI.working.controller"));
         if (Reg::hasVal("Branch.name")) {
             $load['branch'] = Config::uriToClass(Reg::get("Branch.name"));
         }
         $load['type'] = 'Controller';
         $load = implode('_', $load);
         $controller = new $load();
         if (!is_object($controller)) {
             if (!file_exists(Reg::get("System.defaultError404"))) {
                 include Reg::get("System.defaultError404");
             } else {
                 echo Reg::get("System.defaultError404");
             }
         } else {
             try {
                 // call hook
                 Hook::call('Exception.loadURL.controller', array(&$controller));
                 $controller->_showView();
             } catch (EvergreenException $e) {
                 var_dump($e);
                 exit;
                 if (Reg::get("System.mode") == "development") {
                     if (isset(self::$params['code'])) {
                         $code = self::$params['code'];
                     }
                     // call hook
                     Hook::call('Exception.loadURL.default', array(&$url, &$code));
                     switch ($code) {
                         case 'GEN':
                             if (file_exists(Reg::get("System.defaultErrorGEN"))) {
                                 include Reg::get("System.defaultErrorGEN");
                             } else {
                                 echo Reg::get("System.defaultErrorGEN");
                             }
                             break;
                         case 'DB':
                             if (file_exists(Reg::get("System.defaultErrorDB"))) {
                                 include Reg::get("System.defaultErrorDB");
                             } else {
                                 echo Reg::get("System.defaultErrorDB");
                             }
                             break;
                         default:
                             if (file_exists(Reg::get("System.defaultErrorGEN"))) {
                                 include Reg::get("System.defaultErrorGEN");
                             } else {
                                 echo Reg::get("System.defaultErrorGEN");
                             }
                             break;
                     }
                 }
             }
         }
     } else {
         if (file_exists(Reg::get("System.defaultErrorGEN"))) {
             include Reg::get("System.defaultErrorGEN");
         } else {
             echo Reg::get("System.defaultErrorGEN");
         }
     }
 }