Example #1
0
 /**
  * Create Authentication Scheme
  * 
  * @param Request $request
  */
 public function __construct(Request $request)
 {
     $this->request = $request;
     $this->registry = Registry::getInstance();
     // get the user from the request
     $this->user = $this->request->getUser();
     // send them back here when they are done
     $this->return_url = $this->request->getParam("return");
     // flesh out our return url
     $base = $this->request->getBaseUrl();
     $server = $this->request->getServerUrl();
     if ($this->return_url == "") {
         $this->return_url = $base;
         // so send them home!
     }
     // @todo find out if some CAS servers are still tripping up on this
     $params = array('controller' => 'authenticate', 'action' => 'validate', 'return' => $this->return_url);
     $this->validate_url = $this->request->url_for($params, true);
 }
 /**
  * Run specified action
  * 
  * @param string $action		action name
  * @throws NotFoundException
  */
 public function execute($action)
 {
     $action_name = str_replace('-', '', $action);
     $action_name = str_replace('_', '', $action_name);
     $action_name .= 'Action';
     if (!method_exists($this, $action_name)) {
         throw new NotFoundException("Could not find '{$action}'");
     }
     // initial tasks
     $init = $this->init();
     if ($init instanceof HttpFoundation\Response) {
         return $init;
     }
     // check authentication
     $auth = $this->checkAuthentication($action);
     if ($auth instanceof HttpFoundation\Response) {
         return $auth;
     }
     // run the action
     $response = $this->{$action_name}();
     // make sure we got a response
     if (!$response instanceof HttpFoundation\Response) {
         // nope, but see if we still have the original
         $response = $this->response;
         if (!$response instanceof HttpFoundation\Response) {
             throw new \Exception("Action '{$action}' returned no Response");
         }
     }
     // this was a redirect or something
     if (!$response instanceof Response) {
         return $response;
     }
     // add event objects to response
     if ($this->response->getVariable('base_url') == '') {
         $this->response->setVariable('base_url', $this->request->getServerUrl() . $this->request->getBasePath());
         $this->response->setVariable('request', $this->request);
         $this->response->setVariable('config', $this->registry);
     }
     // clean-up tasks
     $shutdown = $this->shutdown();
     if ($shutdown instanceof HttpFoundation\Response) {
         return $shutdown;
     }
     return $response;
 }