GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 3.x ( 289fd6...a05912 )
by Rob
10s
created

App::redirect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
1
<?php
2
/**
3
 * Slim Framework (https://slimframework.com)
4
 *
5
 * @link      https://github.com/slimphp/Slim
6
 * @copyright Copyright (c) 2011-2017 Josh Lockhart
7
 * @license   https://github.com/slimphp/Slim/blob/3.x/LICENSE.md (MIT License)
8
 */
9
namespace Slim;
10
11
use Exception;
12
use Slim\Exception\InvalidMethodException;
13
use Slim\Http\Response;
14
use Throwable;
15
use Closure;
16
use InvalidArgumentException;
17
use Psr\Http\Message\RequestInterface;
18
use Psr\Http\Message\ServerRequestInterface;
19
use Psr\Http\Message\ResponseInterface;
20
use Psr\Container\ContainerInterface;
21
use FastRoute\Dispatcher;
22
use Slim\Exception\SlimException;
23
use Slim\Exception\MethodNotAllowedException;
24
use Slim\Exception\NotFoundException;
25
use Slim\Http\Uri;
26
use Slim\Http\Headers;
27
use Slim\Http\Body;
28
use Slim\Http\Request;
29
use Slim\Interfaces\Http\EnvironmentInterface;
30
use Slim\Interfaces\RouteGroupInterface;
31
use Slim\Interfaces\RouteInterface;
32
use Slim\Interfaces\RouterInterface;
33
34
/**
35
 * App
36
 *
37
 * This is the primary class with which you instantiate,
38
 * configure, and run a Slim Framework application.
39
 * The \Slim\App class also accepts Slim Framework middleware.
40
 *
41
 * @property-read callable $errorHandler
42
 * @property-read callable $phpErrorHandler
43
 * @property-read callable $notFoundHandler function($request, $response)
44
 * @property-read callable $notAllowedHandler function($request, $response, $allowedHttpMethods)
45
 */
46
class App
47
{
48
    use MiddlewareAwareTrait;
49
50
    /**
51
     * Current version
52
     *
53
     * @var string
54
     */
55
    const VERSION = '3.9.3-dev';
56
57
    /**
58
     * Container
59
     *
60
     * @var ContainerInterface
61
     */
62
    private $container;
63
64
    /********************************************************************************
65
     * Constructor
66
     *******************************************************************************/
67
68
    /**
69
     * Create new application
70
     *
71
     * @param ContainerInterface|array $container Either a ContainerInterface or an associative array of app settings
72
     * @throws InvalidArgumentException when no container is provided that implements ContainerInterface
73
     */
74
    public function __construct($container = [])
75
    {
76
        if (is_array($container)) {
77
            $container = new Container($container);
78
        }
79
        if (!$container instanceof ContainerInterface) {
80
            throw new InvalidArgumentException('Expected a ContainerInterface');
81
        }
82
        $this->container = $container;
83
    }
84
85
    /**
86
     * Enable access to the DI container by consumers of $app
87
     *
88
     * @return ContainerInterface
89
     */
90
    public function getContainer()
91
    {
92
        return $this->container;
93
    }
94
95
    /**
96
     * Add middleware
97
     *
98
     * This method prepends new middleware to the app's middleware stack.
99
     *
100
     * @param  callable|string    $callable The callback routine
101
     *
102
     * @return static
103
     */
104
    public function add($callable)
105
    {
106
        return $this->addMiddleware(new DeferredCallable($callable, $this->container));
107
    }
108
109
    /**
110
     * Calling a non-existant method on App checks to see if there's an item
111
     * in the container that is callable and if so, calls it.
112
     *
113
     * @param  string $method
114
     * @param  array $args
115
     * @return mixed
116
     */
117
    public function __call($method, $args)
118
    {
119
        if ($this->container->has($method)) {
120
            $obj = $this->container->get($method);
121
            if (is_callable($obj)) {
122
                return call_user_func_array($obj, $args);
123
            }
124
        }
125
126
        throw new \BadMethodCallException("Method $method is not a valid method");
127
    }
128
129
    /********************************************************************************
130
     * Router proxy methods
131
     *******************************************************************************/
132
133
    /**
134
     * Add GET route
135
     *
136
     * @param  string $pattern  The route URI pattern
137
     * @param  callable|string  $callable The route callback routine
138
     *
139
     * @return \Slim\Interfaces\RouteInterface
140
     */
141
    public function get($pattern, $callable)
142
    {
143
        return $this->map(['GET'], $pattern, $callable);
144
    }
145
146
    /**
147
     * Add POST route
148
     *
149
     * @param  string $pattern  The route URI pattern
150
     * @param  callable|string  $callable The route callback routine
151
     *
152
     * @return \Slim\Interfaces\RouteInterface
153
     */
154
    public function post($pattern, $callable)
155
    {
156
        return $this->map(['POST'], $pattern, $callable);
157
    }
158
159
    /**
160
     * Add PUT route
161
     *
162
     * @param  string $pattern  The route URI pattern
163
     * @param  callable|string  $callable The route callback routine
164
     *
165
     * @return \Slim\Interfaces\RouteInterface
166
     */
167
    public function put($pattern, $callable)
168
    {
169
        return $this->map(['PUT'], $pattern, $callable);
170
    }
171
172
    /**
173
     * Add PATCH route
174
     *
175
     * @param  string $pattern  The route URI pattern
176
     * @param  callable|string  $callable The route callback routine
177
     *
178
     * @return \Slim\Interfaces\RouteInterface
179
     */
180
    public function patch($pattern, $callable)
181
    {
182
        return $this->map(['PATCH'], $pattern, $callable);
183
    }
184
185
    /**
186
     * Add DELETE route
187
     *
188
     * @param  string $pattern  The route URI pattern
189
     * @param  callable|string  $callable The route callback routine
190
     *
191
     * @return \Slim\Interfaces\RouteInterface
192
     */
193
    public function delete($pattern, $callable)
194
    {
195
        return $this->map(['DELETE'], $pattern, $callable);
196
    }
197
198
    /**
199
     * Add OPTIONS route
200
     *
201
     * @param  string $pattern  The route URI pattern
202
     * @param  callable|string  $callable The route callback routine
203
     *
204
     * @return \Slim\Interfaces\RouteInterface
205
     */
206
    public function options($pattern, $callable)
207
    {
208
        return $this->map(['OPTIONS'], $pattern, $callable);
209
    }
210
211
    /**
212
     * Add route for any HTTP method
213
     *
214
     * @param  string $pattern  The route URI pattern
215
     * @param  callable|string  $callable The route callback routine
216
     *
217
     * @return \Slim\Interfaces\RouteInterface
218
     */
219
    public function any($pattern, $callable)
220
    {
221
        return $this->map(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], $pattern, $callable);
222
    }
223
224
    /**
225
     * Add route with multiple methods
226
     *
227
     * @param  string[] $methods  Numeric array of HTTP method names
228
     * @param  string   $pattern  The route URI pattern
229
     * @param  callable|string    $callable The route callback routine
230
     *
231
     * @return RouteInterface
232
     */
233
    public function map(array $methods, $pattern, $callable)
234
    {
235
        if ($callable instanceof Closure) {
236
            $callable = $callable->bindTo($this->container);
237
        }
238
239
        $route = $this->container->get('router')->map($methods, $pattern, $callable);
240
        if (is_callable([$route, 'setContainer'])) {
241
            $route->setContainer($this->container);
242
        }
243
244
        if (is_callable([$route, 'setOutputBuffering'])) {
245
            $route->setOutputBuffering($this->container->get('settings')['outputBuffering']);
246
        }
247
248
        return $route;
249
    }
250
251
    /**
252
     * Add a route that sends an HTTP redirect
253
     *
254
     * @param string              $from
255
     * @param string|UriInterface $to
256
     * @param int                 $status
257
     *
258
     * @return RouteInterface
259
     */
260
    public function redirect($from, $to, $status = 302)
261
    {
262
        $handler = function ($request, ResponseInterface $response) use ($to, $status) {
263
            return $response->withHeader('Location', (string)$to)->withStatus($status);
264
        };
265
266
        return $this->get($from, $handler);
267
    }
268
269
    /**
270
     * Route Groups
271
     *
272
     * This method accepts a route pattern and a callback. All route
273
     * declarations in the callback will be prepended by the group(s)
274
     * that it is in.
275
     *
276
     * @param string   $pattern
277
     * @param callable $callable
278
     *
279
     * @return RouteGroupInterface
280
     */
281
    public function group($pattern, $callable)
282
    {
283
        /** @var RouteGroup $group */
284
        $group = $this->container->get('router')->pushGroup($pattern, $callable);
285
        $group->setContainer($this->container);
286
        $group($this);
287
        $this->container->get('router')->popGroup();
288
        return $group;
289
    }
290
291
    /********************************************************************************
292
     * Runner
293
     *******************************************************************************/
294
295
    /**
296
     * Run application
297
     *
298
     * This method traverses the application middleware stack and then sends the
299
     * resultant Response object to the HTTP client.
300
     *
301
     * @param bool|false $silent
302
     * @return ResponseInterface
303
     *
304
     * @throws Exception
305
     * @throws MethodNotAllowedException
306
     * @throws NotFoundException
307
     */
308
    public function run($silent = false)
309
    {
310
        $response = $this->container->get('response');
311
312
        try {
313
            ob_start();
314
            $response = $this->process($this->container->get('request'), $response);
315
        } catch (InvalidMethodException $e) {
316
            $response = $this->processInvalidMethod($e->getRequest(), $response);
317
        } finally {
318
            $output = ob_get_clean();
319
        }
320
321
        if (!empty($output) && $response->getBody()->isWritable()) {
322
            $outputBuffering = $this->container->get('settings')['outputBuffering'];
323
            if ($outputBuffering === 'prepend') {
324
                // prepend output buffer content
325
                $body = new Http\Body(fopen('php://temp', 'r+'));
326
                $body->write($output . $response->getBody());
327
                $response = $response->withBody($body);
328
            } elseif ($outputBuffering === 'append') {
329
                // append output buffer content
330
                $response->getBody()->write($output);
331
            }
332
        }
333
334
        $response = $this->finalize($response);
335
336
        if (!$silent) {
337
            $this->respond($response);
338
        }
339
340
        return $response;
341
    }
342
343
    /**
344
     * Pull route info for a request with a bad method to decide whether to
345
     * return a not-found error (default) or a bad-method error, then run
346
     * the handler for that error, returning the resulting response.
347
     *
348
     * Used for cases where an incoming request has an unrecognized method,
349
     * rather than throwing an exception and not catching it all the way up.
350
     *
351
     * @param ServerRequestInterface $request
352
     * @param ResponseInterface $response
353
     * @return ResponseInterface
354
     */
355
    protected function processInvalidMethod(ServerRequestInterface $request, ResponseInterface $response)
356
    {
357
        $router = $this->container->get('router');
358 View Code Duplication
        if (is_callable([$request->getUri(), 'getBasePath']) && is_callable([$router, 'setBasePath'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
359
            $router->setBasePath($request->getUri()->getBasePath());
360
        }
361
362
        $request = $this->dispatchRouterAndPrepareRoute($request, $router);
363
        $routeInfo = $request->getAttribute('routeInfo', [RouterInterface::DISPATCH_STATUS => Dispatcher::NOT_FOUND]);
364
365
        if ($routeInfo[RouterInterface::DISPATCH_STATUS] === Dispatcher::METHOD_NOT_ALLOWED) {
366
            return $this->handleException(
367
                new MethodNotAllowedException($request, $response, $routeInfo[RouterInterface::ALLOWED_METHODS]),
368
                $request,
369
                $response
370
            );
371
        }
372
373
        return $this->handleException(new NotFoundException($request, $response), $request, $response);
374
    }
375
376
    /**
377
     * Process a request
378
     *
379
     * This method traverses the application middleware stack and then returns the
380
     * resultant Response object.
381
     *
382
     * @param ServerRequestInterface $request
383
     * @param ResponseInterface $response
384
     * @return ResponseInterface
385
     *
386
     * @throws Exception
387
     * @throws MethodNotAllowedException
388
     * @throws NotFoundException
389
     */
390
    public function process(ServerRequestInterface $request, ResponseInterface $response)
391
    {
392
        // Ensure basePath is set
393
        $router = $this->container->get('router');
394 View Code Duplication
        if (is_callable([$request->getUri(), 'getBasePath']) && is_callable([$router, 'setBasePath'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
395
            $router->setBasePath($request->getUri()->getBasePath());
396
        }
397
398
        // Dispatch the Router first if the setting for this is on
399
        if ($this->container->get('settings')['determineRouteBeforeAppMiddleware'] === true) {
400
            // Dispatch router (note: you won't be able to alter routes after this)
401
            $request = $this->dispatchRouterAndPrepareRoute($request, $router);
402
        }
403
404
        // Traverse middleware stack
405
        try {
406
            $response = $this->callMiddlewareStack($request, $response);
407
        } catch (Exception $e) {
408
            $response = $this->handleException($e, $request, $response);
409
        } catch (Throwable $e) {
0 ignored issues
show
Bug introduced by
The class Throwable does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
410
            $response = $this->handlePhpError($e, $request, $response);
411
        }
412
413
        return $response;
414
    }
415
416
    /**
417
     * Send the response to the client
418
     *
419
     * @param ResponseInterface $response
420
     */
421
    public function respond(ResponseInterface $response)
422
    {
423
        // Send response
424
        if (!headers_sent()) {
425
            // Headers
426
            foreach ($response->getHeaders() as $name => $values) {
427
                foreach ($values as $value) {
428
                    header(sprintf('%s: %s', $name, $value), false);
429
                }
430
            }
431
432
            // Set the status _after_ the headers, because of PHP's "helpful" behavior with location headers.
433
            // See https://github.com/slimphp/Slim/issues/1730
434
435
            // Status
436
            header(sprintf(
437
                'HTTP/%s %s %s',
438
                $response->getProtocolVersion(),
439
                $response->getStatusCode(),
440
                $response->getReasonPhrase()
441
            ));
442
        }
443
444
        // Body
445
        if (!$this->isEmptyResponse($response)) {
446
            $body = $response->getBody();
447
            if ($body->isSeekable()) {
448
                $body->rewind();
449
            }
450
            $settings       = $this->container->get('settings');
451
            $chunkSize      = $settings['responseChunkSize'];
452
453
            $contentLength  = $response->getHeaderLine('Content-Length');
454
            if (!$contentLength) {
455
                $contentLength = $body->getSize();
456
            }
457
458
459
            if (isset($contentLength)) {
460
                $amountToRead = $contentLength;
461
                while ($amountToRead > 0 && !$body->eof()) {
462
                    $data = $body->read(min($chunkSize, $amountToRead));
463
                    echo $data;
464
465
                    $amountToRead -= strlen($data);
466
467
                    if (connection_status() != CONNECTION_NORMAL) {
468
                        break;
469
                    }
470
                }
471
            } else {
472
                while (!$body->eof()) {
473
                    echo $body->read($chunkSize);
474
                    if (connection_status() != CONNECTION_NORMAL) {
475
                        break;
476
                    }
477
                }
478
            }
479
        }
480
    }
481
482
    /**
483
     * Invoke application
484
     *
485
     * This method implements the middleware interface. It receives
486
     * Request and Response objects, and it returns a Response object
487
     * after compiling the routes registered in the Router and dispatching
488
     * the Request object to the appropriate Route callback routine.
489
     *
490
     * @param  ServerRequestInterface $request  The most recent Request object
491
     * @param  ResponseInterface      $response The most recent Response object
492
     *
493
     * @return ResponseInterface
494
     * @throws MethodNotAllowedException
495
     * @throws NotFoundException
496
     */
497
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response)
498
    {
499
        // Get the route info
500
        $routeInfo = $request->getAttribute('routeInfo');
501
502
        /** @var \Slim\Interfaces\RouterInterface $router */
503
        $router = $this->container->get('router');
504
505
        // If router hasn't been dispatched or the URI changed then dispatch
506
        if (null === $routeInfo || ($routeInfo['request'] !== [$request->getMethod(), (string) $request->getUri()])) {
507
            $request = $this->dispatchRouterAndPrepareRoute($request, $router);
508
            $routeInfo = $request->getAttribute('routeInfo');
509
        }
510
511
        if ($routeInfo[0] === Dispatcher::FOUND) {
512
            $route = $router->lookupRoute($routeInfo[1]);
513
            return $route->run($request, $response);
514
        } elseif ($routeInfo[0] === Dispatcher::METHOD_NOT_ALLOWED) {
515
            if (!$this->container->has('notAllowedHandler')) {
516
                throw new MethodNotAllowedException($request, $response, $routeInfo[1]);
517
            }
518
            /** @var callable $notAllowedHandler */
519
            $notAllowedHandler = $this->container->get('notAllowedHandler');
520
            return $notAllowedHandler($request, $response, $routeInfo[1]);
521
        }
522
523
        if (!$this->container->has('notFoundHandler')) {
524
            throw new NotFoundException($request, $response);
525
        }
526
        /** @var callable $notFoundHandler */
527
        $notFoundHandler = $this->container->get('notFoundHandler');
528
        return $notFoundHandler($request, $response);
529
    }
530
531
    /**
532
     * Perform a sub-request from within an application route
533
     *
534
     * This method allows you to prepare and initiate a sub-request, run within
535
     * the context of the current request. This WILL NOT issue a remote HTTP
536
     * request. Instead, it will route the provided URL, method, headers,
537
     * cookies, body, and server variables against the set of registered
538
     * application routes. The result response object is returned.
539
     *
540
     * @param  string            $method      The request method (e.g., GET, POST, PUT, etc.)
541
     * @param  string            $path        The request URI path
542
     * @param  string            $query       The request URI query string
543
     * @param  array             $headers     The request headers (key-value array)
544
     * @param  array             $cookies     The request cookies (key-value array)
545
     * @param  string            $bodyContent The request body
546
     * @param  ResponseInterface $response     The response object (optional)
547
     * @return ResponseInterface
548
     */
549
    public function subRequest(
550
        $method,
551
        $path,
552
        $query = '',
553
        array $headers = [],
554
        array $cookies = [],
555
        $bodyContent = '',
556
        ResponseInterface $response = null
557
    ) {
558
        $env = $this->container->get('environment');
559
        $uri = Uri::createFromEnvironment($env)->withPath($path)->withQuery($query);
560
        $headers = new Headers($headers);
561
        $serverParams = $env->all();
562
        $body = new Body(fopen('php://temp', 'r+'));
563
        $body->write($bodyContent);
564
        $body->rewind();
565
        $request = new Request($method, $uri, $headers, $cookies, $serverParams, $body);
566
567
        if (!$response) {
568
            $response = $this->container->get('response');
569
        }
570
571
        return $this($request, $response);
572
    }
573
574
    /**
575
     * Dispatch the router to find the route. Prepare the route for use.
576
     *
577
     * @param ServerRequestInterface $request
578
     * @param RouterInterface        $router
579
     * @return ServerRequestInterface
580
     */
581
    protected function dispatchRouterAndPrepareRoute(ServerRequestInterface $request, RouterInterface $router)
582
    {
583
        $routeInfo = $router->dispatch($request);
584
585
        if ($routeInfo[0] === Dispatcher::FOUND) {
586
            $routeArguments = [];
587
            foreach ($routeInfo[2] as $k => $v) {
588
                $routeArguments[$k] = urldecode($v);
589
            }
590
591
            $route = $router->lookupRoute($routeInfo[1]);
592
            $route->prepare($request, $routeArguments);
593
594
            // add route to the request's attributes in case a middleware or handler needs access to the route
595
            $request = $request->withAttribute('route', $route);
596
        }
597
598
        $routeInfo['request'] = [$request->getMethod(), (string) $request->getUri()];
599
600
        return $request->withAttribute('routeInfo', $routeInfo);
601
    }
602
603
    /**
604
     * Finalize response
605
     *
606
     * @param ResponseInterface $response
607
     * @return ResponseInterface
608
     */
609
    protected function finalize(ResponseInterface $response)
610
    {
611
        // stop PHP sending a Content-Type automatically
612
        ini_set('default_mimetype', '');
613
614
        if ($this->isEmptyResponse($response)) {
615
            return $response->withoutHeader('Content-Type')->withoutHeader('Content-Length');
616
        }
617
618
        // Add Content-Length header if `addContentLengthHeader` setting is set
619
        if (isset($this->container->get('settings')['addContentLengthHeader']) &&
620
            $this->container->get('settings')['addContentLengthHeader'] == true) {
621
            if (ob_get_length() > 0) {
622
                throw new \RuntimeException("Unexpected data in output buffer. " .
623
                    "Maybe you have characters before an opening <?php tag?");
624
            }
625
            $size = $response->getBody()->getSize();
626
            if ($size !== null && !$response->hasHeader('Content-Length')) {
627
                $response = $response->withHeader('Content-Length', (string) $size);
628
            }
629
        }
630
631
        return $response;
632
    }
633
634
    /**
635
     * Helper method, which returns true if the provided response must not output a body and false
636
     * if the response could have a body.
637
     *
638
     * @see https://tools.ietf.org/html/rfc7231
639
     *
640
     * @param ResponseInterface $response
641
     * @return bool
642
     */
643
    protected function isEmptyResponse(ResponseInterface $response)
644
    {
645
        if (method_exists($response, 'isEmpty')) {
646
            return $response->isEmpty();
647
        }
648
649
        return in_array($response->getStatusCode(), [204, 205, 304]);
650
    }
651
652
    /**
653
     * Call relevant handler from the Container if needed. If it doesn't exist,
654
     * then just re-throw.
655
     *
656
     * @param  Exception $e
657
     * @param  ServerRequestInterface $request
658
     * @param  ResponseInterface $response
659
     *
660
     * @return ResponseInterface
661
     * @throws Exception if a handler is needed and not found
662
     */
663
    protected function handleException(Exception $e, ServerRequestInterface $request, ResponseInterface $response)
664
    {
665
        if ($e instanceof MethodNotAllowedException) {
666
            $handler = 'notAllowedHandler';
667
            $params = [$e->getRequest(), $e->getResponse(), $e->getAllowedMethods()];
668
        } elseif ($e instanceof NotFoundException) {
669
            $handler = 'notFoundHandler';
670
            $params = [$e->getRequest(), $e->getResponse(), $e];
671
        } elseif ($e instanceof SlimException) {
672
            // This is a Stop exception and contains the response
673
            return $e->getResponse();
674
        } else {
675
            // Other exception, use $request and $response params
676
            $handler = 'errorHandler';
677
            $params = [$request, $response, $e];
678
        }
679
680 View Code Duplication
        if ($this->container->has($handler)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
681
            $callable = $this->container->get($handler);
682
            // Call the registered handler
683
            return call_user_func_array($callable, $params);
684
        }
685
686
        // No handlers found, so just throw the exception
687
        throw $e;
688
    }
689
690
    /**
691
     * Call relevant handler from the Container if needed. If it doesn't exist,
692
     * then just re-throw.
693
     *
694
     * @param  Throwable $e
695
     * @param  ServerRequestInterface $request
696
     * @param  ResponseInterface $response
697
     * @return ResponseInterface
698
     * @throws Throwable
699
     */
700
    protected function handlePhpError(Throwable $e, ServerRequestInterface $request, ResponseInterface $response)
701
    {
702
        $handler = 'phpErrorHandler';
703
        $params = [$request, $response, $e];
704
705 View Code Duplication
        if ($this->container->has($handler)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
706
            $callable = $this->container->get($handler);
707
            // Call the registered handler
708
            return call_user_func_array($callable, $params);
709
        }
710
711
        // No handlers found, so just throw the exception
712
        throw $e;
713
    }
714
}
715