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

Dropelikeit / laravel-responsefactory / 21842377146

09 Feb 2026 09:58PM UTC coverage: 97.101% (-2.9%) from 100.0%
21842377146

Pull #23

github

web-flow
Merge b32f14181 into 97b3a4be8
Pull Request #23: Add custom `ControllerDispatcher` with `#[HandledByResponseFactory]` …

20 of 20 new or added lines in 2 files covered. (100.0%)

8 existing lines in 1 file now uncovered.

268 of 276 relevant lines covered (97.1%)

4.25 hits per line

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

84.0
/src/ServiceProvider.php
1
<?php
2
declare(strict_types=1);
3

4
namespace Dropelikeit\ResponseFactory;
5

6
use Dropelikeit\ResponseFactory\Configuration\Configuration;
7
use Dropelikeit\ResponseFactory\Contracts\Configuration\CustomHandlerConfiguration;
8
use Dropelikeit\ResponseFactory\Contracts\Decorators\MimetypeFromFileInformationDetector;
9
use Dropelikeit\ResponseFactory\Contracts\Factories\Transformers\InputToStringTransformerFactory as TransformerFactoryContract;
10
use Dropelikeit\ResponseFactory\Contracts\Http\ResponseFactory as ResponseFactoryContract;
11
use Dropelikeit\ResponseFactory\Contracts\Services\MimeTypeDetector as MimeTypeDetectorContract;
12
use Dropelikeit\ResponseFactory\Decorators\FileInfo;
13
use Dropelikeit\ResponseFactory\Factories\Http\SerializerFactory;
14
use Dropelikeit\ResponseFactory\Factories\Transformers\InputToStringTransformerFactory;
15
use Dropelikeit\ResponseFactory\Http\Dispatcher\ControllerDispatcher;
16
use Dropelikeit\ResponseFactory\Http\ResponseFactory;
17
use Dropelikeit\ResponseFactory\Services\MimeTypeDetector;
18
use Illuminate\Config\Repository;
19
use Illuminate\Contracts\Routing\ControllerDispatcher as ControllerDispatcherContract;
20
use Illuminate\Foundation\Application;
21
use Illuminate\Support\Facades\Storage;
22
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
23

24
use Override;
25
use Webmozart\Assert\Assert;
26

27
/**
28
 * @author Marcel Strahl <info@marcel-strahl.de>
29
 */
30
final class ServiceProvider extends BaseServiceProvider
31
{
32
    private const string CONFIGURATION_FILE_NAME = 'responsefactory.php';
33
    private const string CONFIGURATION_KEY_PACKAGE = 'responsefactory';
34
    private const string CONFIGURATION_DIR_PATH = __DIR__ . '/../config/' . self::CONFIGURATION_FILE_NAME;
35
    private const string RESPONSE_FACTORY_CONTAINER_KEY = 'ResponseFactory';
36
    private const string STORAGE_PATH = 'framework/cache/data';
37
    private const string LARAVEL_CONFIG_REPOSITORY_KEY = 'config';
38

39
    /**
40
     * @description Register any application services.
41
     */
42
    #[Override]
3✔
43
    public function register(): void
44
    {
45
        $this->mergeConfigFrom(self::CONFIGURATION_DIR_PATH, self::CONFIGURATION_KEY_PACKAGE);
3✔
46

47
        /** @var Repository $configRepository */
48
        $configRepository = $this->app->get(self::LARAVEL_CONFIG_REPOSITORY_KEY);
3✔
49

50
        $cacheDir = $this->app->storagePath(self::STORAGE_PATH);
3✔
51
        if (!Storage::exists($cacheDir)) {
3✔
UNCOV
52
            Storage::makeDirectory($cacheDir);
×
53
        }
54

55
        $shouldSerializeNull = (bool) $configRepository
3✔
56
            ->get('responsefactory.serialize_null', true);
3✔
57
        $serializeType = $configRepository
3✔
58
            ->get('responsefactory.serialize_type', Configuration::SERIALIZE_TYPE_JSON);
3✔
59
        Assert::stringNotEmpty($serializeType);
3✔
60
        $debug = (bool) $configRepository->get('laravel-jms-serializer.debug', false);
3✔
61
        $addDefaultHandlers = (bool) $configRepository->get(
3✔
62
            'laravel-jms-serializer.add_default_handlers',
3✔
63
            true
3✔
64
        );
3✔
65
        /** @var array<int, CustomHandlerConfiguration> $customHandlers */
66
        $customHandlers = (array) $configRepository->get('laravel-jms-serializer.custom_handlers', []);
3✔
67

68
        $config = Configuration::fromArray([
3✔
69
            'serialize_null' => $shouldSerializeNull,
3✔
70
            'cache_dir' => $cacheDir,
3✔
71
            'serialize_type' => $serializeType,
3✔
72
            'debug' => $debug,
3✔
73
            'add_default_handlers' => $addDefaultHandlers,
3✔
74
            'custom_handlers' => $customHandlers,
3✔
75
        ]);
3✔
76

77
        $this->app->bind(TransformerFactoryContract::class, InputToStringTransformerFactory::class);
3✔
78
        $this->app->bind(MimetypeFromFileInformationDetector::class, FileInfo::class);
3✔
79

80
        $this->app->singleton(ResponseFactory::class, static function (Application $app) use ($config): ResponseFactory {
3✔
81
            $mimetypeDetector = $app->get(MimeTypeDetector::class);
3✔
82
            Assert::isInstanceOf($mimetypeDetector, MimeTypeDetectorContract::class);
3✔
83

84
            return new ResponseFactory(
3✔
85
                (new SerializerFactory())->getSerializer($config),
3✔
86
                $config,
3✔
87
                $mimetypeDetector,
3✔
88
            );
3✔
89
        });
3✔
90

91
        $this->app->bind(ResponseFactoryContract::class, ResponseFactory::class);
3✔
92

93
        $this->app->bind(self::RESPONSE_FACTORY_CONTAINER_KEY, static fn (Application $app): ResponseFactory => $app->get(ResponseFactory::class));
3✔
94

95
        // Register the custom ControllerDispatcher
96
        $this->app->bind(ControllerDispatcherContract::class, static function (Application $app): ControllerDispatcher {
3✔
97
            $responseFactory = $app->get(ResponseFactory::class);
1✔
98
            Assert::isInstanceOf($responseFactory, ResponseFactoryContract::class);
1✔
99

100
            return new ControllerDispatcher($app, $responseFactory);
1✔
101
        });
3✔
102
    }
103

104
    /**
105
     * @description Bootstrap the application events.
106
     */
UNCOV
107
    public function boot(): void
×
108
    {
UNCOV
109
        $this->publishes(
×
UNCOV
110
            [self::CONFIGURATION_DIR_PATH => $this->getConfigPath()],
×
UNCOV
111
            self::CONFIGURATION_KEY_PACKAGE,
×
UNCOV
112
        );
×
113
    }
114

115
    /**
116
     * @description Get the config path
117
     *
118
     * @return string
119
     */
UNCOV
120
    private function getConfigPath(): string
×
121
    {
UNCOV
122
        return config_path(self::CONFIGURATION_FILE_NAME);
×
123
    }
124
}
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