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

Dropelikeit / laravel-jms-serializer / 9061598919

pending completion
9061598919

Pull #35

github

web-flow
Merge 58ccece97 into b55457268
Pull Request #35: Feature/add laravel 11 support and improve test quality

1 of 4 new or added lines in 1 file covered. (25.0%)

171 of 175 relevant lines covered (97.71%)

6.47 hits per line

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

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

4
namespace Dropelikeit\LaravelJmsSerializer;
5

6
use Dropelikeit\LaravelJmsSerializer\Config\Config;
7
use Dropelikeit\LaravelJmsSerializer\Contracts\CustomHandlerConfiguration;
8
use Dropelikeit\LaravelJmsSerializer\Contracts\ResponseBuilder;
9
use Dropelikeit\LaravelJmsSerializer\Http\Responses\ResponseFactory;
10
use Dropelikeit\LaravelJmsSerializer\Serializer\Factory;
11
use Illuminate\Config\Repository;
12
use Illuminate\Foundation\Application;
13
use Illuminate\Support\Facades\Storage;
14
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
15
use function sprintf;
16

17
use Webmozart\Assert\Assert;
18

19
/**
20
 * @author Marcel Strahl <info@marcel-strahl.de>
21
 */
22
final class ServiceProvider extends BaseServiceProvider
23
{
24
    /**
25
     * @description Register any application services.
26
     */
27
    public function register(): void
28
    {
29
        $configPath = __DIR__ . '/../config/laravel-jms-serializer.php';
2✔
30
        $this->mergeConfigFrom($configPath, 'laravel-jms-serializer');
2✔
31

32
        /** @var Repository $configRepository */
33
        $configRepository = $this->app->get('config');
2✔
34

35
        $cacheDir = $this->app->storagePath('framework/cache/data');
2✔
36
        if (!Storage::exists($cacheDir)) {
2✔
37
            Storage::makeDirectory($cacheDir);
2✔
38
        }
39

40
        $shouldSerializeNull = (bool) $configRepository
2✔
41
            ->get('laravel-jms-serializer.serialize_null', true);
2✔
42
        $serializeType = $configRepository
2✔
43
            ->get('laravel-jms-serializer.serialize_type', Contracts\Config::SERIALIZE_TYPE_JSON);
2✔
44
        Assert::stringNotEmpty($serializeType);
2✔
45
        $debug = (bool) $configRepository->get('laravel-jms-serializer.debug', false);
2✔
46
        $addDefaultHandlers = (bool) $configRepository->get(
2✔
47
            'laravel-jms-serializer.add_default_handlers',
2✔
48
            true
2✔
49
        );
2✔
50
        /** @var array<int, CustomHandlerConfiguration> $customHandlers */
51
        $customHandlers = (array) $configRepository->get('laravel-jms-serializer.custom_handlers', []);
2✔
52

53
        $config = Config::fromConfig([
2✔
54
            'serialize_null' => $shouldSerializeNull,
2✔
55
            'cache_dir' => $cacheDir,
2✔
56
            'serialize_type' => $serializeType,
2✔
57
            'debug' => $debug,
2✔
58
            'add_default_handlers' => $addDefaultHandlers,
2✔
59
            'custom_handlers' => $customHandlers,
2✔
60
        ]);
2✔
61

62
        $this->app->singleton(ResponseFactory::class, static function () use ($config): ResponseFactory {
2✔
63
            return new ResponseFactory((new Factory())->getSerializer($config), $config);
×
64
        });
2✔
65

66
        $this->app->bind(ResponseBuilder::class, ResponseFactory::class);
2✔
67

68
        $this->app->bind('ResponseFactory', static function (Application $app): ResponseFactory {
2✔
NEW
69
            $responseFactory = $app->get(ResponseFactory::class);
×
NEW
70
            Assert::isInstanceOf($responseFactory, ResponseFactory::class);
×
71

NEW
72
            return $responseFactory;
×
73
        });
2✔
74
    }
75

76
    /**
77
     * @description Bootstrap the application events.
78
     */
79
    public function boot(): void
80
    {
81
        $configPath = sprintf('%s/../config/laravel-jms-serializer.php', __DIR__);
2✔
82
        Assert::stringNotEmpty($configPath);
2✔
83

84
        $this->publishes([$configPath => $this->getConfigPath()], 'laravel-jms');
2✔
85
    }
86

87
    /**
88
     * @description Get the config path
89
     *
90
     * @return string
91
     */
92
    private function getConfigPath(): string
93
    {
94
        return config_path('laravel-jms-serializer.php');
2✔
95
    }
96
}
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