public function __invoke(Request $request, Response $response) { $msg = 'Not Found : ' . $request->getUri()->__toString(); $this->logger->alert($msg); $output = json_encode(['error' => $msg, 'code' => 404]); $body = new \Slim\Http\Body(fopen('php://temp', 'r+')); $body->write($output); return $response->withStatus(404)->withHeader('Content-type', 'application/json;charset=utf-8')->withBody($body); }
public function __invoke(Request $request, Response $response, array $methods) { $msg = 'Method must be one of: ' . implode(', ', $methods); $this->logger->alert($msg); $output = json_encode(['error' => $msg, 'code' => 405]); $body = new \Slim\Http\Body(fopen('php://temp', 'r+')); $body->write($output); return $response->withStatus(405)->withHeader('Content-type', 'application/json;charset=utf-8')->withBody($body); }
public function __invoke(Request $request, Response $response, \Exception $exception) { $context = ['file' => $exception->getFile(), 'line' => $exception->getLine(), 'code' => $exception->getCode()]; $msg = $exception->getMessage(); $this->logger->critical($msg, $context); //return parent::__invoke($request, $response, $exception); $output = json_encode(['error' => $msg, 'code' => 500]); $body = new \Slim\Http\Body(fopen('php://temp', 'r+')); $body->write($output); return $response->withStatus(500)->withHeader('Content-type', 'application/json;charset=utf-8')->withBody($body); }
public function __invoke($request, $response, $next) { // call next middleware $response = $next($request, $response); $content = (string) $response->getBody(); $search = array('/\\>[^\\S ]+/s', '/[^\\S ]+\\</s', '/\\>[\\r\\n\\t ]+\\</s', '/(\\s)+/s', '/\\n/', '/<!--(?!\\s*(?:\\[if [^\\]]+]|<!|>))(?:(?!-->).)*-->/s'); $replace = array('>', '<', '><', '\\1', ' ', ''); $newContent = preg_replace($search, $replace, $content); $newBody = new \Slim\Http\Body(fopen('php://temp', 'r+')); $newBody->write($newContent); return $response->withBody($newBody); }
/** * Getter for failureCallable * * @return callable|\Closure */ public function getFailureCallable() { if (is_null($this->failureCallable)) { $this->failureCallable = function (ServerRequestInterface $request, ResponseInterface $response, $next) { $body = new \Slim\Http\Body(fopen('php://temp', 'r+')); $body->write('Failed CSRF check!'); return $response->withStatus(400)->withHeader('Content-type', 'text/plain')->withBody($body); }; } return $this->failureCallable; }
/** * Getter for failureCallable * * @return callable|\Closure */ public function getFailureCallable() { if (is_null($this->failureCallable)) { $this->failureCallable = function ($request, $response, $next) { $body = new \Slim\Http\Body(fopen('php://temp', 'r+')); $body->write('Unauthorized'); return $response->withStatus(401)->withHeader('Content-type', 'text/plain')->withBody($body); }; } return $this->failureCallable; }