Exemplo n.º 1
0
 /**
  * Loads a class and instantiate an object.
  * @param string $class class name
  * @param null $params
  * @param bool $instantiate
  * @param bool $force_new_object
  * @return object|bool
  */
 public static function &factory($class, $params = null, $instantiate = true, $force_new_object = false)
 {
     $class = strtolower($class);
     $path = str_replace('_', '/', $class);
     // If we would like to instantiate a new object,
     // we do not need to check the class existance.
     if ($force_new_object) {
         // Does the class exist? If so, we're done...
         if (isset(self::$_objects[$class])) {
             return self::$_objects[$class];
         }
     }
     $p = explode('/', $path);
     $filename = end($p);
     $path = implode('/', array_slice($p, 0, -1)) . '/';
     // Try to find a file
     $file = Exido::findFile($path, $filename, true);
     if (is_file($file)) {
         include_once $file;
         $name = $class;
         if ($force_new_object) {
             Helper::load('guid');
             $name = $name . '_' . guidGet();
         }
         if ($instantiate == false) {
             self::$_objects[$name] = true;
             return self::$_objects[$name];
         }
         self::$_objects[$name] = new $class($params);
         return self::$_objects[$name];
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * Loads a global view. Design theme.
  * @return View_Layout
  */
 public function load()
 {
     $this->_file = Exido::findFile($this->_layout_path, $this->_layout_name);
     if ($this->_file == null) {
         $this->_file = sprintf(__('[View file %s is not found]'), $this->_layout_path . $this->_layout_name . '.php');
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Loads an action view. Controller method.
  * @param string $controller
  * @param string $method
  * @return View_Action
  */
 public function load($controller, $method)
 {
     $this->_file = Exido::findFile('template/default/action/' . $controller . '/', $method);
     if ($this->_file == null) {
         $this->_file = sprintf(__('[View file %s is not found]'), 'template/default/action/' . $controller . '/' . $method . '.php');
     }
     return $this;
 }
Exemplo n.º 4
0
 /**
  * Merges language lines from all the loaded files.
  * @return array
  */
 public function load()
 {
     static $i18n = array();
     if ($files = Exido::findFile($this->_directory, $this->_idiom)) {
         // Set config array
         foreach ($files as $file) {
             // Merge each config array to the global array
             $i18n = array_merge($i18n, require $file);
         }
     }
     return $i18n;
 }
Exemplo n.º 5
0
 /**
  * Merges configurations from all the loaded files.
  * @param string $group
  * @param array $config
  * @return Config_Reader
  */
 public function load($group, array $config = NULL)
 {
     if ($files = Exido::findFile($this->_directory, $group)) {
         // Set config array
         $config = array();
         foreach ($files as $file) {
             // Merge each config array to the global array
             $config = arrayMerge($config, require $file);
         }
     }
     return parent::load($group, $config);
 }
Exemplo n.º 6
0
 /**
  * Loads a custom view. Returns FALSE if the view has already been loaded.
  * @param string $file
  * @return View_Custom
  */
 public function load($file)
 {
     if (isset($this->_files[$file])) {
         return $this;
     }
     // Find a view file
     $this->_files[$file] = Exido::findFile('template/default', $file);
     if ($this->_files[$file] == null) {
         $this->_files[$file] = sprintf(__('[View file %s is not found]'), 'template/default/' . $file . '.php');
     }
     return $this;
 }
Exemplo n.º 7
0
 /**
  * Loads a helper.
  * @param string $helper
  * @return bool
  */
 public static function load($helper)
 {
     $_helpers = func_get_args();
     foreach ($_helpers as $file) {
         // Does the class exist?  If so, we're done...
         if (!isset(self::$_helpers[$file])) {
             $path = Exido::findFile('helper/', $file, true);
             if ($path) {
                 include_once $path;
                 self::$_helpers[$file] = $path;
             }
         }
     }
     return true;
 }
Exemplo n.º 8
0
 /**
  * Loads a vendor.
  * @param string $vendor
  * @return bool
  */
 public static function load($vendor)
 {
     $_vendors = func_get_args();
     foreach ($_vendors as $file) {
         // Does the file exist?  If so, we're done...
         if (!isset(self::$_vendors[$file])) {
             $path = Exido::findFile('vendors/' . str_replace('_', '/', $file), '_init', true);
             if ($path) {
                 include_once $path;
                 self::$_vendors[$file] = $path;
             }
         }
     }
     return true;
 }
Exemplo n.º 9
0
 /**
  * Inline exception handler, displays the error message, source of the
  * exception, and the stack trace of the error.
  * @param object $e
  * return void
  */
 public static function handlerException($e)
 {
     try {
         // Get the exception information
         $type = get_class($e);
         $code = $e->getCode();
         $message = $e->getMessage();
         $file = $e->getFile();
         $line = $e->getLine();
         if (!in_array($code, self::$codes)) {
             $code = 500;
         }
         // Get the exception backtrace
         $trace = $e->getTrace();
         // Run logger
         self::log($e);
         // If Exido running in a command line environment
         // or using an XML request.
         // We just print a json encoded string.
         if (Exido::$is_cli or Exido::$is_xml) {
             // Just display the text of the exception
             exit(json_encode(array('status' => false, 'code' => $code, 'text' => $message)));
         }
         if (!headers_sent()) {
             // Make sure the proper http header is sent
             header('Content-Type: text/html; charset=' . __('__charset'), true, $code);
         }
         // If we're in production so we should return the correct error page.
         if (IN_PRODUCTION == true) {
             if ($e instanceof Exception_Database) {
                 exit($message);
             } else {
                 $view = View::instance();
                 $view->code = $code;
                 $view->message = $message;
                 $view->file = Debug::path($file);
                 $view->line = $line;
                 $html = Registry::factory('View_Exception')->setLayout('exception/template', 'error' . $code)->load()->parse($view, new View_Helper());
                 // Display the contents and exit
                 exit($html);
             }
         } else {
             if ($e instanceof Exception_Database) {
                 $message = $e->errstr . ' [ ' . $e->errquery . ' ]';
             }
             // Return the page with more information about error in the development mode.
             include_once Exido::findFile('exception/template', 'development');
             exit(1);
         }
     } catch (Exception $e) {
         // Clean the output buffer if one exists
         ob_get_level() and ob_clean();
         // Display the exception text
         echo self::text($e), EXIDO_EOL;
         // Run logger
         Exido::$log->write();
         // Exit with an error status
         exit(1);
     }
 }