Esempio n. 1
0
 public static function call($class_and_method, $parameters, $arguments = false)
 {
     $arguments = $arguments ? $arguments : array();
     if (!class_exists($class_and_method[0])) {
         throw new Exception($class_and_method[0] . ' class was not found.');
     }
     $instance = new $class_and_method[0]();
     self::$current_controller = $instance;
     $instance->params = array_merge($parameters, $arguments);
     foreach (PicoraEvent::getObserverList($class_and_method[0] . '.beforeCall') as $callback) {
         if (call_user_func($callback, $instance, $class_and_method[1]) === false) {
             return false;
         }
     }
     if ($instance->beforeCall($class_and_method[1]) === false) {
         return false;
     }
     $callback = array($instance, $class_and_method[1]);
     if (!is_callable($callback)) {
         throw new Exception(get_class($callback[0]) . '->' . $callback[1] . '() is not callable.');
     }
     $response = call_user_func($callback);
     if ($response !== false) {
         foreach (PicoraEvent::getObserverList($class_and_method[0] . '.afterCall') as $callback) {
             $callback_response = call_user_func($callback, $instance, $response, $class_and_method[1]);
             if (!is_null($callback_response)) {
                 $response = $callback_response;
             }
         }
         $callback_response = $instance->afterCall($response, $class_and_method[1]);
         if (!is_null($callback_response)) {
             $response = $callback_response;
         }
     }
     return $response;
 }