• 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

48.15
/src/Factory/ServerRequestCreatorFactory.php
1
<?php
2
declare(strict_types=1);
3

4
namespace Ody\Core\Factory;
5

6
use Ody\Core\Interfaces\Psr17FactoryProviderInterface;
7
use Ody\Core\Interfaces\ServerRequestCreatorInterface;
8
use RuntimeException;
9
use Ody\Core\Factory\Psr17\Psr17Factory;
10
use Ody\Core\Factory\Psr17\Psr17FactoryProvider;
11
use Ody\Core\Factory\Psr17\SlimHttpServerRequestCreator;
12

13
/** @api */
14
class ServerRequestCreatorFactory
15
{
16
    protected static ?Psr17FactoryProviderInterface $psr17FactoryProvider = null;
17

18
    protected static ?ServerRequestCreatorInterface $serverRequestCreator = null;
19

20
    protected static bool $slimHttpDecoratorsAutomaticDetectionEnabled = true;
21

22
    public static function create(): ServerRequestCreatorInterface
1✔
23
    {
24
        return static::determineServerRequestCreator();
1✔
25
    }
26

27
    /**
28
     * @throws RuntimeException
29
     */
30
    public static function determineServerRequestCreator(): ServerRequestCreatorInterface
1✔
31
    {
32
        if (static::$serverRequestCreator) {
1✔
33
            return static::attemptServerRequestCreatorDecoration(static::$serverRequestCreator);
×
34
        }
35

36
        $psr17FactoryProvider = static::$psr17FactoryProvider ?? new Psr17FactoryProvider();
1✔
37

38
        /** @var Psr17Factory $psr17Factory */
39
        foreach ($psr17FactoryProvider->getFactories() as $psr17Factory) {
1✔
40
            if ($psr17Factory::isServerRequestCreatorAvailable()) {
1✔
41
                $serverRequestCreator = $psr17Factory::getServerRequestCreator();
1✔
42
                return static::attemptServerRequestCreatorDecoration($serverRequestCreator);
1✔
43
            }
44
        }
45

46
        throw new RuntimeException(
×
47
            "Could not detect any ServerRequest creator implementations. " .
×
48
            "Please install a supported implementation in order to use `App::run()` " .
×
49
            "without having to pass in a `ServerRequest` object. " .
×
50
            "See https://github.com/slimphp/Slim/blob/4.x/README.md for a list of supported implementations."
×
51
        );
×
52
    }
53

54
    protected static function attemptServerRequestCreatorDecoration(
1✔
55
        ServerRequestCreatorInterface $serverRequestCreator
56
    ): ServerRequestCreatorInterface {
57
        if (
58
            static::$slimHttpDecoratorsAutomaticDetectionEnabled
1✔
59
            && SlimHttpServerRequestCreator::isServerRequestDecoratorAvailable()
1✔
60
        ) {
61
            return new SlimHttpServerRequestCreator($serverRequestCreator);
×
62
        }
63

64
        return $serverRequestCreator;
1✔
65
    }
66

67
    public static function setPsr17FactoryProvider(Psr17FactoryProviderInterface $psr17FactoryProvider): void
×
68
    {
69
        static::$psr17FactoryProvider = $psr17FactoryProvider;
×
70
    }
71

72
    public static function setServerRequestCreator(ServerRequestCreatorInterface $serverRequestCreator): void
×
73
    {
74
        self::$serverRequestCreator = $serverRequestCreator;
×
75
    }
76

77
    public static function setSlimHttpDecoratorsAutomaticDetection(bool $enabled): void
×
78
    {
79
        static::$slimHttpDecoratorsAutomaticDetectionEnabled = $enabled;
×
80
    }
81
}
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