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

IlyasDeckers / ody-core / 13589380408

28 Feb 2025 01:41PM UTC coverage: 13.422% (-19.7%) from 33.151%
13589380408

push

github

IlyasDeckers
add support classes/methods (wip)

0 of 2412 new or added lines in 16 files covered. (0.0%)

544 of 4053 relevant lines covered (13.42%)

4.04 hits per line

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

0.0
/src/ServiceProvider/Resolver.php
1
<?php
2

3
namespace Ody\Core\ServiceProvider;
4

5
use Ody\Core\Kernel;
6

7
class Resolver
8
{
9
    /**
10
     * Resolve a controllers definition
11
     *
12
     * It takes a string with the form 'controller:action', this method will split the string in
13
     * 2 parts. It will look for the controller definition in the application container using the
14
     * first part of the string, it will use the second part of the string as the controller's
15
     * method. Those values will be used as a callable ([$controller, 'action']).
16
     * It will pass the route arguments, if any, followed by the Slim application and Slim request,
17
     * to the callable.
18
     * If a parameter converter is passed it will replace the default arguments with the values
19
     * returned by the converter.
20
     *
21
     * @param Kernel $app
22
     * @param string $key
23
     * @param callable|null $converter Optional parameter converter
24
     * @return callable
25
     */
NEW
26
    public function resolve(Kernel $app, $key, callable $converter = null)
×
27
    {
NEW
28
        list($controller, $action) = explode(':', $key);
×
29

NEW
30
        return function () use ($app, $controller, $action, $converter) {
×
31

NEW
32
            $arguments = array_merge(func_get_args(), [$app->request, $app]);
×
NEW
33
            if ($converter) {
×
NEW
34
                $arguments = call_user_func($converter, $arguments);
×
35
            }
36

NEW
37
            call_user_func_array([$app->container->get($controller), $action], $arguments);
×
NEW
38
        };
×
39
    }
40

41
    /**
42
     * Extend an existing service definition
43
     *
44
     * The $extension callable will receive the original service as its first argument and the
45
     * Slim application as its second argument.
46
     *
47
     * @param Kernel $app
48
     * @param string $key
49
     * @param callable $extension
50
     */
NEW
51
    public function extend(Kernel $app, $key, callable $extension)
×
52
    {
53
        // Unset the original factory defined by $key in order to avoid a recursion loop
NEW
54
        $services = $app->container->all();
×
NEW
55
        $original = $services[$key];
×
NEW
56
        unset($services[$key]);
×
NEW
57
        $app->container->replace($services);
×
58

NEW
59
        $app->container->singleton($key, function() use ($original, $app, $extension) {
×
60

61
            // Execute the original factory before calling, its extension
NEW
62
            return call_user_func_array($extension, [$original($app)]);
×
NEW
63
        });
×
64
    }
65
}
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