-
-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handled API errors break preloaded content (#3920)
* fix: handled API errors break preloaded content * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot <[email protected]>
- Loading branch information
1 parent
deb99f0
commit 5e3f8db
Showing
9 changed files
with
147 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Flarum\Api; | ||
|
||
use Illuminate\Contracts\Container\Container; | ||
use Illuminate\Support\Collection; | ||
use Laminas\Stratigility\MiddlewarePipe; | ||
use Laminas\Stratigility\MiddlewarePipeInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\MiddlewareInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
|
||
class ClientMiddlewarePipe implements MiddlewarePipeInterface | ||
{ | ||
protected Collection $middlewares; | ||
protected MiddlewarePipeInterface $pipe; | ||
|
||
public function __construct( | ||
protected Container $container, | ||
array $middlewares | ||
) { | ||
$this->middlewares = new Collection($middlewares); | ||
} | ||
|
||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||
{ | ||
return $this->getPipe()->process($request, $handler); | ||
} | ||
|
||
public function handle(ServerRequestInterface $request): ResponseInterface | ||
{ | ||
return $this->getPipe()->handle($request); | ||
} | ||
|
||
public function pipe(MiddlewareInterface $middleware): void | ||
{ | ||
$this->middlewares->push($middleware); | ||
} | ||
|
||
protected function getPipe(): MiddlewarePipeInterface | ||
{ | ||
if (isset($this->pipe)) { | ||
return $this->pipe; | ||
} | ||
|
||
$this->pipe = new MiddlewarePipe(); | ||
|
||
foreach ($this->middlewares as $middleware) { | ||
$this->pipe->pipe($this->container->make($middleware)); | ||
} | ||
|
||
return $this->pipe; | ||
} | ||
|
||
public function errorHandling(bool $handleErrors): static | ||
{ | ||
$errorHandler = 'flarum.api.error_handler'; | ||
|
||
if ($handleErrors && ! $this->middlewares->contains($errorHandler)) { | ||
$this->middlewares = $this->middlewares->prepend($errorHandler); | ||
} elseif (! $handleErrors && $this->middlewares->contains($errorHandler)) { | ||
$this->middlewares = $this->middlewares->reject($errorHandler); | ||
} | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters