示例#1
0
 /**
  * Processes the request, executing the controller action that handles this
  * request, determined by the [Route].
  *
  * 1. Before the controller action is called, the [Controller::before] method
  * will be called.
  * 2. Next the controller action will be called.
  * 3. After the controller action is called, the [Controller::after] method
  * will be called.
  *
  * By default, the output from the controller is captured and returned, and
  * no headers are sent.
  *
  *     $request->execute();
  *
  * KoJo Modification:
  *		extension name is prefixed to the prefix instead of directory suffixed to the prefix. 
  *		extension name format will be changed to ComAppname, ModAppname, or PlgAppname 
  *
  * @return  $this
  * @throws  Kohana_Exception
  * @uses    [Kohana::$profiling]
  * @uses    [Profiler]
  */
 public function execute()
 {
     // Create the class prefix
     $prefix = 'controller_';
     if ($this->extension) {
         // extension format name should be com_app or mod_app or plg_app
         $extension = substr($this->extension, 0, 3) . substr($this->extension, 4);
         // Add the extension name to the class prefix. Add _admin_ depending on the client being called
         $this->extension_prefix = $this->client == 'admin' ? $extension . '_admin_' : $extension . '_';
         // Set the extension prefix for the controller
         $prefix = $this->extension_prefix . $prefix;
     }
     if (Kohana::$profiling) {
         // Set the benchmark name
         $benchmark = '"' . $this->uri . '"';
         if ($this !== Request::$instance and Request::$current) {
             // Add the parent request uri
             $benchmark .= ' « "' . Request::$current->uri . '"';
         }
         // Start benchmarking
         $benchmark = Profiler::start('Requests', $benchmark);
     }
     // Store the currently active request
     $previous = Request::$current;
     // Change the current request to this request
     Request::$current = $this;
     try {
         // Load the controller using reflection
         $class = new ReflectionClass($prefix . $this->controller);
         // Add the classes path in the CFS
         $path = KoJo::get_path_from_class($prefix . $this->controller);
         // Assign the path to this Request
         $this->path = $path['path'];
         // Add the path to the CFS under existing paths of parent Requests
         KoJo::add_path($this->path);
         if ($class->isAbstract()) {
             throw new Kohana_Exception('Cannot create instances of abstract :controller', array(':controller' => $prefix . $this->controller));
         }
         // Create a new instance of the controller
         $controller = $class->newInstance($this);
         // Execute the "before action" method
         $class->getMethod('before')->invoke($controller);
         // Determine the action to use
         $action = empty($this->action) ? Route::$default_action : $this->action;
         // Execute the main action with the parameters
         $class->getMethod('action_' . $action)->invokeArgs($controller, $this->_params);
         // Execute the "after action" method
         $class->getMethod('after')->invoke($controller);
     } catch (Exception $e) {
         // Restore the previous request
         Request::$current = $previous;
         if (isset($benchmark)) {
             // Delete the benchmark, it is invalid
             Profiler::delete($benchmark);
         }
         if ($e instanceof ReflectionException) {
             // Reflection will throw exceptions for missing classes or actions
             $this->status = 404;
         } else {
             // All other exceptions are PHP/server errors
             $this->status = 500;
         }
         // Re-throw the exception
         throw $e;
     }
     // Restore the previous request
     Request::$current = $previous;
     if (isset($benchmark)) {
         // Stop the benchmark
         Profiler::stop($benchmark);
     }
     return $this;
 }
示例#2
0
 /**
  * Cleans up the environment:
  *
  * - Restore the previous error and exception handlers
  * - Destroy the self::$log and self::$config objects
  *
  * @return  void
  */
 public static function deinit()
 {
     if (self::$_init) {
         // Removed the autoloader
         spl_autoload_unregister(array('KoJo', 'auto_load'));
         if (self::$errors) {
             // Go back to the previous error handler
             restore_error_handler();
             // Go back to the previous exception handler
             restore_exception_handler();
         }
         // Destroy objects created by init
         self::$log = self::$config = NULL;
         // Reset internal storage
         self::$_modules = self::$_files = array();
         self::$_paths = array(APPPATH, SYSPATH);
         // Reset file cache status
         self::$_files_changed = FALSE;
         // Kohana is no longer initialized
         self::$_init = FALSE;
     }
 }
示例#3
0
 public function ExitKojo()
 {
     if (defined('KOJO_INITIALIZED')) {
         KoJo::deinit();
     }
 }