• 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/CallableResolver.php
1
<?php
2
declare(strict_types=1);
3

4
namespace Ody\Core\DI;
5

6
use Invoker\Exception\NotCallableException;
7
use Ody\Core\Interfaces\AdvancedCallableResolverInterface;
8
use Psr\Http\Server\MiddlewareInterface;
9
use Psr\Http\Server\RequestHandlerInterface;
10

11
/**
12
 * Resolve middleware and route callables using PHP-DI.
13
 */
14
class CallableResolver implements AdvancedCallableResolverInterface
15
{
16
    /** @var \Invoker\CallableResolver */
17
    private $callableResolver;
18

19
    public function __construct(\Invoker\CallableResolver $callableResolver)
×
20
    {
21
        $this->callableResolver = $callableResolver;
×
22
    }
23

24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function resolve($toResolve): callable
×
28
    {
29
        return $this->callableResolver->resolve($this->translateNotation($toResolve));
×
30
    }
31

32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function resolveRoute($toResolve): callable
×
36
    {
37
        return $this->resolvePossibleSignature($toResolve, 'handle', RequestHandlerInterface::class);
×
38
    }
39

40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function resolveMiddleware($toResolve): callable
×
44
    {
45
        return $this->resolvePossibleSignature($toResolve, 'process', MiddlewareInterface::class);
×
46
    }
47

48
    /**
49
     * Translate string callable notation ('nameOrKey:method') to PHP-DI notation ('nameOrKey::method').
50
     *
51
     * @param callable|string $toResolve
52
     */
53
    private function translateNotation(string|callable $toResolve): callable|string
×
54
    {
55
        if (is_string($toResolve) && preg_match(\Ody\Core\CallableResolver::$callablePattern, $toResolve)) {
×
56
            $toResolve = str_replace(':', '::', $toResolve);
×
57
        }
58

59
        return $toResolve;
×
60
    }
61

62
    /**
63
     * @param callable|string $toResolve
64
     */
65
    private function resolvePossibleSignature(string|callable $toResolve, string $method, string $typeName): callable
×
66
    {
67
        if (is_string($toResolve)) {
×
68
            $toResolve = $this->translateNotation($toResolve);
×
69

70
            try {
71
                $callable = $this->callableResolver->resolve([$toResolve, $method]);
×
72

73
                if (is_array($callable) && $callable[0] instanceof $typeName) {
×
74
                    return $callable;
×
75
                }
76
            } catch (NotCallableException $e) {
×
77
                // Fall back to looking for a generic callable.
78
            }
79
        }
80

81
        return $this->callableResolver->resolve($toResolve);
×
82
    }
83
}
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