예제 #1
0
파일: Error.php 프로젝트: reith2004/frapi
    /**
     * Private function to get error (statically, APC, or DB).
     *
     * This function tries to locate the error in progressively
     * slower datastores (static class variable, APC, database)
     * and will store the loaded errors in the faster stores.
     *
     * @param string $error_name Name of error.
     * @param string $error_msg  The actual message of the error.
     * @param int    $http_code  This might be hard to grasp however, we are in a web
     *                           industry dealing with the web. The code you are sending
     *                           to your exception should really be represented by the
     *                           HTTP Code returned to your users.
     *
     * @return array An array with the content of the error.
     */
    private static function _get($error_name, $error_msg = false, $http_code = false)
    {
        if (!self::$_statically_loaded) {
            $errors = Frapi_Internal::getCached('Errors.user-defined');

            if ($errors) {
                self::$_errors = $errors;
            } elseif ($errors = self::_getErrorsFromDb()) {
                self::$_errors = $errors;
                Frapi_Internal::setCached('Errors.user-defined', $errors);
            }

            self::$_statically_loaded = true;
        }

        if (isset(self::$_errors[$error_name])) {
            $error = self::$_errors[$error_name];

            if ($error_msg !== false) {
                $error['message'] = $error_msg;
            }

            if ($http_code !== false) {
                $error['http_code'] = $http_code;
            }

            return $error;
        }

        return array(
            'name'      => $error_name,
            'message'   => $error_msg !== false ? $error_msg : $error_name,
            'http_code' => $http_code !== false  ? $http_code : '400',
        );
    }
예제 #2
0
파일: Error.php 프로젝트: crlang44/frapi
 /**
  * Private function to get error (statically, APC, or DB).
  *
  * This function tries to locate the error in progressively
  * slower datastores (static class variable, APC, database)
  * and will store the loaded errors in the faster stores.
  *
  * @param string $error_name Name of error.
  * @param string $error_msg   The actual message of the error.
  * @param int    $http_code   This might be hard to grasp however, we are in a web
  *                            industry dealing with the web. The code you are sending
  *                            to your exception should really be represented by the
  *                            HTTP Code returned to your users.
  * @param string $http_phrase The http phrase associated with the http_code
  *
  * @return array An array with the content of the error.
  */
 private static function _get($error_name, $error_msg = false, $http_code = false, $http_phrase = false)
 {
     if (!self::$_statically_loaded) {
         $errors = Frapi_Internal::getCached('Errors.user-defined');
         if ($errors) {
             self::$_errors = $errors;
         } elseif ($errors = self::_getErrorsFromDb()) {
             self::$_errors = $errors;
             Frapi_Internal::setCached('Errors.user-defined', $errors);
         }
         self::$_statically_loaded = true;
     }
     if (isset(self::$_errors[$error_name])) {
         $error = self::$_errors[$error_name];
         if ($error_msg !== false) {
             $error['message'] = $error_msg;
         }
         if ($http_code !== false) {
             $error['http_code'] = $http_code;
         }
         if ($http_phrase !== false) {
             $error['http_phrase'] = $http_phrase;
         } else {
             if (isset(Frapi_Response::$http_reason[$error['http_code']]) && !$error['http_phrase']) {
                 $error['http_phrase'] = Frapi_Response::$http_reason[$error['http_code']];
             } else {
                 if ($error['message'] !== false && !$error['http_phrase']) {
                     $error['http_phrase'] = $error['message'];
                 }
             }
         }
         return $error;
     }
     if ($http_phrase === false) {
         if (isset(Frapi_Response::$http_reason[$http_code])) {
             $http_phrase = Frapi_Response::$http_reason[$http_code];
         } else {
             if ($error_msg !== false) {
                 $http_phrase = $error_msg;
             }
         }
     }
     return array('name' => $error_name, 'message' => $error_msg !== false ? $error_msg : $error_name, 'http_code' => $http_code !== false ? $http_code : '400', 'http_phrase' => $http_phrase !== false ? $http_phrase : 'Bad Request');
 }