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

plank / laravel-mediable / 23991546572

05 Apr 2026 01:22AM UTC coverage: 94.27% (-0.5%) from 94.72%
23991546572

push

github

web-flow
Add support for intervention/image:4.0 (#388)

- Added support for intervention/image:4.0 (#388)
- Dropped support for intervention/image:2.X
- Added ImageManipulation::setOutputOptions(), to support various intervention/image output format settings
- Deprecated ImageManipulation::setOutputQuality(). Use the 'quality' key in setOutputOptions() instead

29 of 38 new or added lines in 2 files covered. (76.32%)

3 existing lines in 1 file now uncovered.

1497 of 1588 relevant lines covered (94.27%)

152.14 hits per line

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

90.24
/src/MediableServiceProvider.php
1
<?php
2
declare(strict_types=1);
3

4
namespace Plank\Mediable;
5

6
use Illuminate\Contracts\Container\Container;
7
use Illuminate\Filesystem\FilesystemManager;
8
use Illuminate\Support\ServiceProvider;
9
use Intervention\Image\ImageManager;
10
use Intervention\Image\Interfaces\DriverInterface;
11
use Plank\Mediable\Commands\ImportMediaCommand;
12
use Plank\Mediable\Commands\PruneMediaCommand;
13
use Plank\Mediable\Commands\SyncMediaCommand;
14
use Plank\Mediable\SourceAdapters\SourceAdapterFactory;
15
use Plank\Mediable\UrlGenerators\UrlGeneratorFactory;
16

17
/**
18
 * Mediable Service Provider.
19
 *
20
 * Registers Laravel-Mediable package functionality
21
 */
22
class MediableServiceProvider extends ServiceProvider
23
{
24
    /**
25
     * Boot the service provider.
26
     *
27
     * @return void
28
     */
29
    public function boot(): void
30
    {
31
        $root = dirname(__DIR__);
1,506✔
32
        $this->publishes(
1,506✔
33
            [
1,506✔
34
                $root . '/config/mediable.php' => config_path('mediable.php'),
1,506✔
35
            ],
1,506✔
36
            'config'
1,506✔
37
        );
1,506✔
38

39
        $time = time();
1,506✔
40

41
        if (empty(glob($this->app->databasePath('migrations/*_create_mediable_tables.php')))) {
1,506✔
42
            $this->publishes(
1,506✔
43
                [
1,506✔
44
                    $root . '/migrations/2016_06_27_000000_create_mediable_tables.php' =>
1,506✔
45
                        $this->app->databasePath(
1,506✔
46
                            'migrations/' . date(
1,506✔
47
                                'Y_m_d_His',
1,506✔
48
                                $time
1,506✔
49
                            ) . '_create_mediable_tables.php'
1,506✔
50
                        )
1,506✔
51
                ],
1,506✔
52
                'mediable-migrations'
1,506✔
53
            );
1,506✔
54
            $time++;
1,506✔
55
        }
56
        if (empty(glob($this->app->databasePath('migrations/*_add_variants_to_media.php')))) {
1,506✔
57
            $this->publishes(
1,506✔
58
                [
1,506✔
59
                    $root . '/migrations/2020_10_12_000000_add_variants_to_media.php' =>
1,506✔
60
                        $this->app->databasePath(
1,506✔
61
                            'migrations/' . date(
1,506✔
62
                                'Y_m_d_His',
1,506✔
63
                                $time
1,506✔
64
                            ) . '_add_variants_to_media.php'
1,506✔
65
                        )
1,506✔
66
                ],
1,506✔
67
                'mediable-migrations'
1,506✔
68
            );
1,506✔
69
            $time++;
1,506✔
70
        }
71

72
        if (empty(glob($this->app->databasePath('migrations/*_add_alt_to_media.php')))) {
1,506✔
73
            $this->publishes(
1,506✔
74
                [
1,506✔
75
                    $root . '/migrations/2024_03_30_000000_add_alt_to_media.php' =>
1,506✔
76
                        $this->app->databasePath(
1,506✔
77
                            'migrations/' . date(
1,506✔
78
                                'Y_m_d_His',
1,506✔
79
                                $time
1,506✔
80
                            ) . '_add_alt_to_media.php'
1,506✔
81
                        ),
1,506✔
82
                ],
1,506✔
83
                'mediable-migrations'
1,506✔
84
            );
1,506✔
85
        }
86

87
        if (!config('mediable.ignore_migrations', false)) {
1,506✔
88
            $this->loadMigrationsFrom($root . '/migrations');
1,506✔
89
        }
90
    }
91

92
    /**
93
     * Register the service provider.
94
     *
95
     * @return void
96
     */
97
    public function register(): void
98
    {
99
        $this->mergeConfigFrom(
1,506✔
100
            dirname(__DIR__) . '/config/mediable.php',
1,506✔
101
            'mediable'
1,506✔
102
        );
1,506✔
103

104
        $this->registerSourceAdapterFactory();
1,506✔
105
        $this->registerImageManipulator();
1,506✔
106
        $this->registerUploader();
1,506✔
107
        $this->registerMover();
1,506✔
108
        $this->registerUrlGeneratorFactory();
1,506✔
109
        $this->registerConsoleCommands();
1,506✔
110
    }
111

112
    /**
113
     * Bind an instance of the Source Adapter Factory to the container.
114
     *
115
     * Attaches the default adapter types
116
     * @return void
117
     */
118
    public function registerSourceAdapterFactory(): void
119
    {
120
        $this->app->singleton('mediable.source.factory', function (Container $app) {
1,506✔
121
            $factory = new SourceAdapterFactory;
900✔
122

123
            $classAdapters = $app['config']->get('mediable.source_adapters.class', []);
900✔
124
            foreach ($classAdapters as $source => $adapter) {
900✔
125
                $factory->setAdapterForClass($adapter, $source);
900✔
126
            }
127

128
            $patternAdapters = $app['config']->get('mediable.source_adapters.pattern', []);
900✔
129
            foreach ($patternAdapters as $source => $adapter) {
900✔
130
                $factory->setAdapterForPattern($adapter, $source);
900✔
131
            }
132

133
            return $factory;
900✔
134
        });
1,506✔
135
        $this->app->alias('mediable.source.factory', SourceAdapterFactory::class);
1,506✔
136
    }
137

138
    /**
139
     * Bind the Media Uploader to the container.
140
     * @return void
141
     */
142
    public function registerUploader(): void
143
    {
144
        $this->app->bind('mediable.uploader', function (Container $app) {
1,506✔
145
            return new MediaUploader(
894✔
146
                $app['filesystem'],
894✔
147
                $app['mediable.source.factory'],
894✔
148
                $app[ImageManipulator::class],
894✔
149
                $app['config']->get('mediable')
894✔
150
            );
894✔
151
        });
1,506✔
152
        $this->app->alias('mediable.uploader', MediaUploader::class);
1,506✔
153
    }
154

155
    /**
156
     * Bind the Media Uploader to the container.
157
     * @return void
158
     */
159
    public function registerMover(): void
160
    {
161
        $this->app->bind('mediable.mover', function (Container $app) {
1,506✔
162
            return new MediaMover($app['filesystem']);
42✔
163
        });
1,506✔
164
        $this->app->alias('mediable.mover', MediaMover::class);
1,506✔
165
    }
166

167
    /**
168
     * Bind the Media Uploader to the container.
169
     * @return void
170
     */
171
    public function registerUrlGeneratorFactory(): void
172
    {
173
        $this->app->singleton('mediable.url.factory', function (Container $app) {
1,506✔
174
            $factory = new UrlGeneratorFactory;
72✔
175

176
            $config = $app['config']->get('mediable.url_generators', []);
72✔
177
            foreach ($config as $driver => $generator) {
72✔
178
                $factory->setGeneratorForFilesystemDriver($generator, $driver);
72✔
179
            }
180

181
            return $factory;
72✔
182
        });
1,506✔
183
        $this->app->alias('mediable.url.factory', UrlGeneratorFactory::class);
1,506✔
184
    }
185

186
    public function registerImageManipulator(): void
187
    {
188
        $this->app->singleton(ImageManipulator::class, function (Container $app) {
1,506✔
189
            return new ImageManipulator(
900✔
190
                $this->getInterventionImageManagerConfiguration($app),
900✔
191
                $app->get(FilesystemManager::class),
900✔
192
                $app->get(ImageOptimizer::class)
900✔
193
            );
900✔
194
        });
1,506✔
195
    }
196

197
    /**
198
     * Add package commands to artisan console.
199
     * @return void
200
     */
201
    public function registerConsoleCommands(): void
202
    {
203
        $this->commands([
1,506✔
204
            ImportMediaCommand::class,
1,506✔
205
            PruneMediaCommand::class,
1,506✔
206
            SyncMediaCommand::class,
1,506✔
207
        ]);
1,506✔
208
    }
209

210
    private function getInterventionImageManagerConfiguration(Container $app): ?ImageManager
211
    {
212
        $imageManager = null;
900✔
213
        if ($app->has(ImageManager::class)
900✔
214
            || (
215
                class_exists(DriverInterface::class) // intervention >= 3.0
900✔
216
                && $app->has(DriverInterface::class)
900✔
217
            )
218
        ) {
219
            // use whatever the user has bound to the container if available
220
            $imageManager = $app->get(ImageManager::class);
900✔
UNCOV
221
        } elseif (extension_loaded('imagick')) {
×
222
            // attempt to automatically configure for imagick
UNCOV
223
            if (class_exists(\Intervention\Image\Drivers\Imagick\Driver::class)) {
×
224
                // intervention/image >=3.0
225
                $imageManager = new ImageManager(
×
226
                    new \Intervention\Image\Drivers\Imagick\Driver()
×
227
                );
×
228
            } else {
229
                // intervention/image <3.0
UNCOV
230
                $imageManager = new ImageManager(['driver' => 'imagick']);
×
231
            }
232
        } elseif (extension_loaded('gd')) {
×
233
            // attempt to automatically configure for gd
234
            if (class_exists(\Intervention\Image\Drivers\Gd\Driver::class)) {
×
235
                // intervention/image >=3.0
236
                $imageManager = new ImageManager(
×
237
                    new \Intervention\Image\Drivers\Gd\Driver()
×
238
                );
×
239
            } else {
240
                // intervention/image <3.0
241
                $imageManager = new ImageManager(['driver' => 'gd']);
×
242
            }
243
        }
244

245
        return $imageManager;
900✔
246
    }
247
}
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