예제 #1
0
 /**
  * Constructor
  *
  * Upon invoking of the constructor, a few objects need to be created
  * in order to approve, authorize and secure the action contexts.
  *
  * This constructor sets up the Security, ErrorContainer, Authorization
  * and also sets the request parameters, files parameters, the format of the output
  * and of course the most important part which is the action/output contexts themselves.
  *
  * @warning IF-Clusterfuck.
  *
  * @see Security
  * @see ErrorContainer
  * @see Authorization
  * @params object $customAuthorization optional custom authorization extending Frapi_Authorization
  */
 public function __construct($customAuthorization = null)
 {
     try {
         $this->security = new Frapi_Security();
         $this->authorization = $customAuthorization instanceof Frapi_Authorization ? $customAuthorization : new Frapi_Authorization();
         $this->router = new Frapi_Router();
         $this->router->loadAndPrepareRoutes();
         $this->setInputFormat();
         $uri = $_SERVER['REQUEST_URI'];
         // For some reason, this is now a fatal
         // error in 5.3 and no longer a warning
         // in php (parse_url() with an http:// in the URL_PATH)...
         if (stristr($uri, '?') !== false) {
             $uri = substr($uri, 0, strpos($uri, '?'));
         }
         $query_path = parse_url($uri, PHP_URL_PATH);
         // @deprecated The use of extensions is considered deprecated
         //Query ending in .xxx may or may not be an output format
         $query_path_format = pathinfo($query_path, PATHINFO_EXTENSION);
         $format = $this->getParam('format');
         if (is_string($query_path_format) && strlen($query_path_format) || $format) {
             $extension = $query_path_format ? $query_path_format : $format;
             if ($query_path_format) {
                 $query_path = substr($query_path, 0, (strlen($extension) + 1) * -1);
             }
             if (Frapi_Rules::validateOutputType($extension) === true) {
                 $accept = Frapi_Output::getMimeTypeByFormat($extension);
                 if (isset($_SERVER['HTTP_ACCEPT'])) {
                     $_SERVER['HTTP_ACCEPT'] = $accept . ',' . $_SERVER['HTTP_ACCEPT'];
                 } else {
                     $_SERVER['HTTP_ACCEPT'] = $accept;
                 }
             }
             $query_path_format = $format = null;
         }
         if ($routed = $this->router->match($query_path)) {
             $_REQUEST = array_merge($_REQUEST, $routed['params']);
             $this->setAction(strtolower($routed['action']));
             $this->setRequest($_REQUEST);
         } else {
             $this->setRequest($_REQUEST);
             $this->setAction($this->getParam('action'));
         }
         // assign the files and params from the request
         $this->setFiles($_FILES)->setParams($this->request);
         $this->authorization->setAuthorizationParams($this->getParams());
     } catch (Frapi_Exception $e) {
         // Something RONG happened. Need to tell developers.
         throw $e;
     } catch (Exception $e) {
         // Something else? Silence! I Keeel you.
     }
 }
예제 #2
0
파일: Main.php 프로젝트: helgi/frapi
 /**
  * Constructor
  *
  * Upon invoking of the constructor, a few objects need to be created
  * in order to approve, authorize and secure the action contexts.
  *
  * This constructor sets up the Security, ErrorContainer, Authorization
  * and also sets the request parameters, files parameters, the format of the output
  * and of course the most important part which is the action/output contexts themselves.
  *
  * @warning IF-Clusterfuck.
  *
  * @see Security
  * @see ErrorContainer
  * @see Authorization
  * @see Frapi_Router
  */
 public function __construct()
 {
     try {
         $this->security = new Frapi_Security();
         $this->authorization = new Frapi_Authorization();
         $this->router = new Frapi_Router();
         $this->router->loadAndPrepareRoutes();
         $this->setInputFormat();
         $uri = $_SERVER['REQUEST_URI'];
         // For some reason, this is now a fatal
         // error in 5.3 and no longer a warning
         // in php (parse_url() with an http:// in the URL_PATH)...
         if (stristr($uri, '?') !== false) {
             $uri = substr($uri, 0, strpos($uri, '?'));
         }
         $query_path = parse_url($uri, PHP_URL_PATH);
         //Query ending in .xxx may or may not be an output format
         $query_path_format = null;
         if (strrpos($query_path, '.')) {
             $query_path_format = substr($query_path, $format_pos = strrpos($query_path, '.') + 1);
         }
         if (Frapi_Rules::validateOutputType($query_path_format) === true) {
             //Output format suffix is valid, remove from URL!
             $query_path = substr($query_path, 0, $format_pos - 1);
         } else {
             $query_path_format = null;
         }
         if ($routed = $this->router->match($query_path)) {
             $_REQUEST = array_merge($_REQUEST, $routed['params']);
             $this->setAction(strtolower($routed['action']));
             $this->setRequest($_REQUEST);
         } else {
             $this->setRequest($_REQUEST);
             $this->setAction($this->getParam('action'));
         }
         $this->setFiles($_FILES);
         try {
             $format = $this->getParam('format');
             if (!is_null($query_path_format)) {
                 $format = $query_path_format;
                 $this->formatSetByExtension = true;
             }
             $setFormat = $this->getFormat();
             $this->setFormat(isset($setFormat) && Frapi_Controller_Api::DEFAULT_OUTPUT_FORMAT == $setFormat ? $format : $setFormat);
         } catch (Frapi_Exception $fex) {
             $this->setFormat($this->getDefaultFormatFromConfiguration());
         }
         $this->authorization->setAuthorizationParams($this->getParams());
     } catch (Frapi_Exception $e) {
         // Something RONG happened. Need to tell developers.
         throw $e;
     } catch (Exception $e) {
         // Something else? Silence! I Keeel you.
     }
 }
예제 #3
0
 /**
  * Constructor
  *
  * Upon invoking of the constructor, a few objects need to be created
  * in order to approve, authorize and secure the action contexts.
  *
  * This constructor sets up the Security, ErrorContainer, Authorization
  * and also sets the request parameters, files parameters, the format of the output
  * and of course the most important part which is the action/output contexts themselves.
  *
  * @warning IF-Clusterfuck.
  *
  * @see Security
  * @see ErrorContainer
  * @see Authorization
  * @see Frapi_Router
  */
 public function __construct()
 {
     try {
         $this->security = new Frapi_Security();
         $this->authorization = new Frapi_Authorization();
         $this->router = new Frapi_Router();
         $this->router->loadAndPrepareRoutes();
         $query_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
         //Query ending in .xxx may or may not be an output format
         $query_path_format = null;
         if (strrpos($query_path, '.')) {
             $query_path_format = substr($query_path, $format_pos = strrpos($query_path, '.') + 1);
         }
         if (Frapi_Rules::validateOutputType($query_path_format) === true) {
             //Output format suffix is valid, remove from URL!
             $query_path = substr($query_path, 0, $format_pos - 1);
         } else {
             $query_path_format = null;
         }
         if ($routed = $this->router->match($query_path)) {
             $_REQUEST = array_merge($_REQUEST, $routed['params']);
             $this->setAction(strtolower($routed['action']));
             $this->setRequest($_REQUEST);
         } else {
             $this->setRequest($_REQUEST);
             $this->setAction($this->getParam('action'));
         }
         $this->setFiles($_FILES);
         try {
             if (!is_null($query_path_format)) {
                 $format = $query_path_format;
             } else {
                 $format = $this->getParam('format');
             }
             $this->setFormat($format);
         } catch (Frapi_Exception $fex) {
             $this->setFormat($this->getDefaultFormatFromConfiguration());
         }
         $this->authorization->setAuthorizationParams($this->getParams());
     } catch (Exception $e) {
         throw $e;
     }
 }