Example #1
0
 /**
  * Class construct
  */
 public function __construct($_options)
 {
     self::$instance = $this;
     $this->name = __CLASS__;
     $this->options($_options);
     if (isset($this->_options['disableLayout'])) {
         $this->disableLayout = $this->_options['disableLayout'];
     }
     if (isset($this->_options['layout'])) {
         $this->layout = $this->_options['layout'];
     }
     $this->view = new K_View($this->_options);
     $this->view->controller =& $this;
     K_Plugins::callHook('controller.viewCreate', array('controller' => &$this, 'view' => &$this->view));
     if (!isset($this->_options['module'])) {
         $this->_options['module'] = 'default';
     }
     $this->MODULE_PATH = APP_PATH . '/' . $this->_options['module'];
     $this->MODULE_TEMPLATES_PATH = APP_PATH . '/' . $this->_options['module'] . '/templates';
     K_ViewHelper::get()->addDirectory(APP_PATH . '/' . $this->_options['module'] . '/helpers');
     K_ViewHelper::get()->addDirectory(APP_PATH . '/helpers');
     if (is_dir(APP_PATH . '/' . $this->_options['module'] . '/plugins')) {
         K_Plugins::addDirectory(APP_PATH . '/' . $this->_options['module'] . '/plugins');
     }
     if (count($this->plugins)) {
         K_Plugins::load($this->plugins);
     }
     K_Plugins::callHook('controller.beforeInit', array('controller' => &$this));
     if (method_exists($this, 'onInit')) {
         $this->onInit();
         // event
     }
     K_Plugins::callHook('controller.afterInit', array('controller' => &$this));
 }
Example #2
0
 /**
  * Inline exception handler, displays the error message, source of the
  * exception, and the stack trace of the error.
  *
  * @uses    Exception_Exception::text
  * @param   object   exception object
  * @return  boolean
  */
 public static function handler(exception $e)
 {
     try {
         // устанавливаем ошибку в контроллер, что бы не рендерил представление
         K_Controller::setError();
         // Get the exception information
         $type = get_class($e);
         $code = $e->getCode();
         $message = $e->getMessage();
         $file = $e->getFile();
         $line = $e->getLine();
         // Get the exception backtrace
         $trace = $e->getTrace();
         if ($e instanceof ErrorException) {
             if (isset(K_Exception::$php_errors[$code])) {
                 // Use the human-readable error name
                 $code = K_Exception::$php_errors[$code];
             }
         }
         // Create a text version of the exception
         $error = K_Exception::text($e);
         if (K_Request::isAjax() === true) {
             // Just display the text of the exception
             echo "\n{$error}\n";
             // добовляем ошибку в логгер и дебагер
             K_Log::get()->add($error);
             K_Debug::get()->add($error, $trace);
             exit(1);
         }
         echo "\n{$error}\n";
         // добовляем ошибку в логгер и дебагер
         K_Log::get()->add($error);
         K_Debug::get()->addError($error, $trace);
         exit(1);
     } catch (exception $e) {
         // Clean the output buffer if one exists
         ob_get_level() and ob_clean();
         // Display the exception text
         echo K_Exception::text($e), "\n";
         // Exit with an error status
         exit(1);
     }
 }