• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IlyasDeckers / ody-core / 13532154862

25 Feb 2025 10:24PM UTC coverage: 30.374% (+1.7%) from 28.706%
13532154862

push

github

web-flow
Update php.yml

544 of 1791 relevant lines covered (30.37%)

9.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/DI/ControllerInvoker.php
1
<?php
2
declare(strict_types=1);
3

4
namespace Ody\Core\DI;
5

6
use Invoker\Exception\InvocationException;
7
use Invoker\Exception\NotCallableException;
8
use Invoker\Exception\NotEnoughParametersException;
9
use Invoker\InvokerInterface;
10
use Psr\Http\Message\ResponseInterface;
11
use Psr\Http\Message\ServerRequestInterface;
12
use Ody\Core\Interfaces\InvocationStrategyInterface;
13

14
class ControllerInvoker implements InvocationStrategyInterface
15
{
16
    /** @var InvokerInterface */
17
    private InvokerInterface $invoker;
18

19
    public function __construct(InvokerInterface $invoker)
×
20
    {
21
        $this->invoker = $invoker;
×
22
    }
23

24
    /**
25
     * Invoke a route callable.
26
     *
27
     * @param callable $callable The callable to invoke using the strategy.
28
     * @param ServerRequestInterface $request The request object.
29
     * @param ResponseInterface $response The response object.
30
     * @param array $routeArguments The route's placeholder arguments
31
     * @return ResponseInterface The response from the callable.
32
     * @throws InvocationException
33
     * @throws NotCallableException
34
     * @throws NotEnoughParametersException
35
     */
36
    public function __invoke(
×
37
        callable $callable,
38
        ServerRequestInterface $request,
39
        ResponseInterface $response,
40
        array $routeArguments
41
    ): ResponseInterface {
42
        // Inject the request and response by parameter name
43
        $parameters = [
×
44
            'request'  => self::injectRouteArguments($request, $routeArguments),
×
45
            'response' => $response,
×
46
        ];
×
47
        // Inject the route arguments by name
48
        $parameters += $routeArguments;
×
49
        // Inject the attributes defined on the request
50
        $parameters += $request->getAttributes();
×
51

52
        return $this->invoker->call($callable, $parameters);
×
53
    }
54

55
    private static function injectRouteArguments(ServerRequestInterface $request, array $routeArguments): ServerRequestInterface
×
56
    {
57
        $requestWithArgs = $request;
×
58
        foreach ($routeArguments as $key => $value) {
×
59
            $requestWithArgs = $requestWithArgs->withAttribute($key, $value);
×
60
        }
61
        return $requestWithArgs;
×
62
    }
63
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc