/** * @param Request|WebRequest $request * @throws HttpError * @throws \Exception * @return mixed */ protected function getResponse(Request $request) { try { return parent::getResponse($request); } catch (\BadMethodCallException $e) { throw new HttpError(WebResponse::STATUS_METHOD_NOT_ALLOWED, "Method [{$request->getMethod()}] is not allowed here.", $e->getMessage(), 0, $e); } catch (\InvalidArgumentException $e) { throw new HttpError(WebResponse::STATUS_BAD_REQUEST, "A request parameter is invalid or missing.", $e->getMessage(), 0, $e); } }
<?php use spec\watoki\deli\fixtures\TestDelivererStub; use watoki\deli\Delivery; use watoki\deli\Path; use watoki\deli\Request; use watoki\deli\router\NoneRouter; use watoki\deli\target\CallbackTarget; require_once __DIR__ . '/../../vendor/autoload.php'; error_reporting(0); $router = new NoneRouter(CallbackTarget::factory(function () { /** @noinspection PhpUndefinedFunctionInspection */ causeFatalError(); })); $test = new TestDelivererStub(new Request(new Path(), Path::fromString('some/target'))); $test->onDeliver(function ($response) { echo $response; }); $delivery = new Delivery($router, $test, $test); $delivery->run();
public function whenIRunTheDelivery() { $this->test = new TestDelivererStub($this->request->request); $this->delivery = new Delivery($this->router, $this->test, $this->test); $this->delivery->run(); }