/** * Constructor * * @param $root * @param $segments * @return unknown_type */ public function __construct($dispatcher, $method, $root, &$segments, $query = null) { if (!$method) { $method = Request::get_request_method(); } parent::__construct($dispatcher, strtoupper($method), $root, $segments, $query); $this->is_secure = $_SERVER['HTTPS'] == "on"; }
/** * Executes a controller, returning the data * * @return array The data from the executed controller. */ public function call() { $data = array(); // any data to return to the view from the controller $cfound=$this->find(); $request_method=$cfound['request_method']; $classname=$cfound['classname']; $found_action=$cfound['found_action']; $root=$cfound['root']; $this->action=$found_action; if (!file_exists($this->controller_root.$this->controller_path.$this->controller.EXT)) throw new ControllerNotFoundException("Could not find a suitable controller: ".$this->controller_root.$this->controller_path.$this->controller.EXT); require_once($this->controller_root.$this->controller_path.$this->controller.EXT); $classname=str_replace('/','',$this->controller_path).$this->controller.'Controller'; if (!class_exists($classname)) throw new ControllerNotFoundException("'$classname' can not be found in '".$this->controller."'."); $request_method = Request::get_request_method(); $found_action=find_methods($classname, $request_method."_".str_replace('-','_',$this->action), str_replace('-','_',$this->action)); if (!$found_action) { $found_action=find_methods($classname, $request_method."_index", 'index'); array_unshift($this->segments,$this->action); // so here we put that mistakenly stripped parameter back on. } if (!$found_action) { throw new ControllerMethodNotFoundException("Could not find an action to call."); } $this->action=$found_action; // Handle the fact that some URIs contain extra segments that are not part of the controller/action root $root = $this->controller_path . (($this->controller!='index') ? $this->controller . "/" : "") . (($this->action!='index' && $found_action!='index') ? $this->action : ""); $root = rtrim($root,'/'); $request=$this->build_request($root); $class=new $classname($request); if ((isset ($class->ignored)) && (in_array($this->action, $class->ignored))) throw new IgnoredMethodCalledException("Ignored method called."); $meta=AttributeReader::MethodAttributes($class,$found_action); // Call the before screens $screen_data=array(); $method_args=$this->segments; Screen::Run('before',$class,$meta,$screen_data,$method_args); // call the method and pass the segments (add returned data to any initially returned by screens) $data = call_user_func_array(array(&$class, $found_action), $method_args); if (is_array($data)) $data=array_merge($screen_data,$data); else $data=$screen_data; // Call the after screens Screen::Run('after',$class,$meta,$data,$method_args); $class->session->save(); if ($class->view) $this->view=$class->view; else if ($meta->view) $this->view=$meta->view; $data['controller']=&$class; $data['session']=&$class->session; return $data; }