phphacks/zend-httperrors

v1.0.5 2020-09-25 19:07 UTC

This package is not auto-updated.

Last update: 2024-09-21 15:38:35 UTC


README

为zend框架提供符合HTTP规范的错误报告结构。

composer require phphacks/zend-httperrors

添加到您的 modules.config.php 文件中

return [
  'Zend\HttpErrors',
  'My\Other\Modules'
];

然后抛出 HttpErrorException

class MyController
{
   private $auth;
   
   public function __construct(AuthorizationService $auth)
   {
      $this->auth = $auth;
   }
   
   public function doSomethingAction()
   {
      if(!$auth->isAuthorized()) {
         throw new HttpUnauthorizedException();
      }
   }
}

就是这样。