Exemplo n.º 1
0
 /**
  * 构造函数
  *
  * 该异常产生时会自动写入core_error日志
  *
  * @param string    $message
  * @param int       $code
  * @param \Exception $previous
  */
 public function __construct($message = '', $code = 0, \Exception $previous = null)
 {
     if ($code == 500) {
         /** @var \Itslove\Passport\Core\LogProvider $log */
         $log = Provider::get('log') and $log['core_error']->error("资源服务异常, \"{$message}\" {$code} {$this->file} {$this->line}");
     }
     parent::__construct($message, $code, $previous);
 }
Exemplo n.º 2
0
 /**
  * 对调用Restful API的Client进行身份验证
  *
  * 验证采用HTTP基本验证, 认证口令以键值对形式保存在app配置文件的api_user数组中
  */
 public static function auth()
 {
     /** @var \Itslove\Passport\Core\LogProvider $log */
     if (!Provider::get('config')->api->authentication) {
         $log = Provider::get('log') and $log['api_access']->notice("认证功能被关闭, 客户端 {$_SERVER['REMOTE_ADDR']} 身份未被认证");
         return;
     }
     $user = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '';
     $password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';
     if ($user && $password && isset(Provider::get('config')->api_user->{$user}) && Provider::get('config')->api_user->{$user} == $password) {
         $log = Provider::get('log') and $log['api_access']->info("身份认证成功, 客户端 {$_SERVER['REMOTE_ADDR']} 使用口令 {$user}:{$password}");
     } else {
         header('HTTP/1.1 401 Unauthorized');
         header('WWW-Authenticate: Basic realm="passport"');
         echo 'Authorization Required.';
         $log = Provider::get('log') and $log['api_access']->notice("身份认证失败, 客户端 {$_SERVER['REMOTE_ADDR']} 尝试口令 {$user}:{$password}");
         exit;
     }
 }
Exemplo n.º 3
0
 /**
  * 获取缓存类实例
  *
  * @return object
  */
 public static function getCache()
 {
     return Provider::get('cache');
 }
Exemplo n.º 4
0
 /**
  * 获取缓存
  *
  * @param string $childNamespace  子命名空间
  * @param string $key             键名
  * @return array|string
  */
 public function get($childNamespace, $key)
 {
     $fullKey = $this->getFullKey($childNamespace, $key);
     if (false === ($result = $this->memcache->get($fullKey))) {
         /** @var \Itslove\Passport\Core\LogProvider $log */
         $log = Provider::get('log') and $log['cache_access']->notice("缓存未命中, Memcached {$fullKey}");
     }
     return $result;
 }
Exemplo n.º 5
0
    $app['url'] = function () {
        return Provider::get('url');
    };
    $app['view'] = function () {
        return Provider::get('view');
    };
    $app['validation'] = function () {
        return Provider::get('validation');
    };
    // 404页面
    $app->notFound(function () use($app) {
        $app->response->setStatusCode(404, "Not Found")->sendHeaders();
        echo 'Not Found';
    });
    //设置错误输出选项
    if (Provider::get('config')->env->testing) {
        ini_set('display_errors', 'On');
        error_reporting(E_ALL);
    } else {
        ini_set('display_errors', 'Off');
        error_reporting(0);
    }
    //关闭Phalcon模型特性, notNullValidations特性会严格审查NotNull
    Model::setup(array('columnRenaming' => false, 'notNullValidations' => false, 'virtualForeignKeys' => false, 'phqlLiterals' => false));
    // 载入路由规则
    require APP_PATH . 'front_routes.php';
    require APP_PATH . 'api_routes.php';
    // 处理请求
    defined('TEST_DEBUG') or $app->handle();
} catch (Exception $e) {
    echo $e->getMessage();