Exemplo n.º 1
0
 /**
  * Load routes from APC, database etc.
  * Prepare routes if necessary!
  *
  * @return void
  */
 public function loadAndPrepareRoutes()
 {
     if ($routes = Frapi_Internal::getCached('Router.routes-prepared')) {
         $this->setPreparedRoutes($routes);
     } else {
         $routes = array();
         $ret = Frapi_Internal::getConfiguration('actions');
         $rows = $ret->getAll('action');
         foreach ($rows as $row) {
             if (isset($row['route']) && !empty($row['route'])) {
                 $routes[$row['name']] = $row['route'];
             }
         }
         $this->setPreparedRoutes($preparedRoutes = self::prepareRoutes($routes));
         Frapi_Internal::setCached('Router.routes-prepared', $preparedRoutes);
     }
 }
Exemplo n.º 2
0
 /**
  * Parse mimetype for params
  *
  * @param string $mimetype
  *
  * @return array
  */
 protected function parseMimeTypes()
 {
     $cache = new Frapi_Internal();
     $mimetypes = $cache->getConfiguration('mimetypes')->getAll('mimetype');
     if (!$mimetypes) {
         return array();
     }
     $patterns = array();
     foreach ($mimetypes as $mimetype) {
         $this->mimeMaps[$mimetype['mimetype']] = $mimetype['output_format'];
         if (strpos($mimetype['mimetype'], ':') === false) {
             continue;
         }
         $segments = preg_split("@/|\\.|\\+@", $mimetype['mimetype']);
         $mimetype['pattern'] = preg_quote($mimetype['mimetype']);
         $params = array();
         foreach ($segments as $segment) {
             if ($segment[0] == ':') {
                 $param = substr($segment, 1);
                 $params[] = $param;
                 $mimetype['pattern'] = str_replace(preg_quote($segment), '(?P<' . preg_quote($param) . '>[^\\.\\+]*?)', $mimetype['pattern']);
             }
         }
         $mimetype['pattern'] = '@^' . $mimetype['pattern'] . '$@';
         // Don't add mimetypes that didn't have params
         if (sizeof($params)) {
             $patterns[] = $mimetype + array('params' => $params);
         }
     }
     return $patterns;
 }
Exemplo n.º 3
0
Arquivo: Main.php Projeto: helgi/frapi
 /**
  * Get default format from SQLite database
  *
  * A format (output type) has not been supplied
  * so try to get default from backend.
  *
  * @return String The format.
  */
 public function getDefaultFormatFromConfiguration()
 {
     if ($default_output_format = Frapi_Internal::getCached('Output.default-format')) {
         return $default_output_format;
     }
     $conf = Frapi_Internal::getConfiguration('outputs');
     $row = $conf->getByField('output', 'default', '1');
     if (isset($row) && isset($row['name'])) {
         Frapi_Internal::setCached('Output.default-format', $row['name']);
         return $row['name'];
     }
     return Frapi_Controller_Api::DEFAULT_OUTPUT_FORMAT;
 }
Exemplo n.º 4
0
    /**
     * Get errors from database.
     *
     * This method fetches the errors from the database (XML)
     * key-values which then get cached when used in self::_get
     *
     * @return Array An array of errors
     */
    private static function _getErrorsFromDb()
    {
        $conf          = Frapi_Internal::getConfiguration('errors');

        $conf_errors   = $conf->getAll('error');

        $errors = array();

        if (is_array($conf_errors) && !empty($conf_errors)) {
            foreach ($conf_errors as $errKey => $error) {
                $errors[$error['name']] = $error;
            }
        }

        return $errors;
    }
Exemplo n.º 5
0
 /**
  * Parse mimetype for params
  *
  * @param string $mimetype
  *
  * @return array
  */
 protected function parseMimeTypes()
 {
     $cache = new Frapi_Internal();
     $mimetypes = $cache->getConfiguration('mimetypes')->getAll('mimetype');
     $patterns = array();
     foreach ($mimetypes as $mimetype) {
         if (strpos($mimetype['mimetype'], ':') === false) {
             continue;
         }
         $segments = preg_split("@/|\\.|\\+@", $mimetype['mimetype']);
         $mimetype['mimetype'] = preg_quote($mimetype['mimetype']);
         foreach ($segments as $segment) {
             if ($segment[0] == ':') {
                 $param = substr($segment, 1);
                 $params[] = $param;
                 $mimetype['mimetype'] = str_replace(preg_quote($segment), '(?P<' . preg_quote($param) . '>.*?)', $mimetype['mimetype']);
             }
         }
         // Don't add mimetypes that didn't have params
         if (sizeof($params)) {
             $patterns[] = $mimetype + array('pattern' => "@^{$mimetype['mimetype']}\$@", 'params' => $params);
         }
     }
     return $patterns;
 }
Exemplo n.º 6
0
 public static function getEnabledFormats()
 {
     try {
         if ($formats = Frapi_Internal::getCached('Output.formats-enabled')) {
             return $formats;
         }
         $cache = new Frapi_Internal();
         $outputs = $cache->getConfiguration('outputs')->getAll('output');
         $formats = array();
         foreach ($outputs as $output) {
             if ($output['enabled'] == 1) {
                 $formats[] = strtolower($output['name']);
             }
         }
     } catch (Exception $e) {
         return false;
     }
     Frapi_Internal::setCached('Output.formats-enabled', $formats);
     return $formats;
 }
Exemplo n.º 7
0
 public static function getMimeTypeMap()
 {
     try {
         $cache = new Frapi_Internal();
         $mimetypes = $cache->getConfiguration('mimetypes')->getAll('mimetype');
         $outputs = $cache->getConfiguration('outputs')->getAll('output');
         $disabled = array();
         foreach ($outputs as $output) {
             if ($output['enabled'] == 0) {
                 $disabled[strtolower($output['name'])] = true;
             }
         }
         $map = array();
         foreach ($mimetypes as $mimetype) {
             if (isset($disabled[strtolower($mimetype['output_format'])])) {
                 continue;
             }
             $map[$mimetype['mimetype']] = $mimetype['output_format'];
         }
     } catch (Exception $e) {
         // No matter what happens for legacy reasons we fallback to the defaults
         return false;
     }
     return $map;
 }
Exemplo n.º 8
0
 public static function getMimeTypeMap()
 {
     try {
         $cache = new Frapi_Internal();
         $mimetypes = $cache->getConfiguration('mimetypes')->getAll('mimetype');
         $map = array();
         foreach ($mimetypes as $mimetype) {
             $map[$mimetype['mimetype']] = $mimetype['output_format'];
         }
     } catch (Exception $e) {
         // No matter what happens for legacy reasons we fallback to the defaults
         return false;
     }
     return $map;
 }