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

plank / laravel-mediable / 5664244419

pending completion
5664244419

push

github

web-flow
Merge pull request #322 from Sparclex/master

Prevent duplicated migration and publish as migration with current time

10 of 11 new or added lines in 1 file covered. (90.91%)

1365 of 1425 relevant lines covered (95.79%)

128.76 hits per line

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

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

4
namespace Plank\Mediable;
5

6
use CreateMediableTables;
7
use Illuminate\Contracts\Container\Container;
8
use Illuminate\Support\ServiceProvider;
9
use Plank\Mediable\Commands\ImportMediaCommand;
10
use Plank\Mediable\Commands\PruneMediaCommand;
11
use Plank\Mediable\Commands\SyncMediaCommand;
12
use Plank\Mediable\SourceAdapters\SourceAdapterFactory;
13
use Plank\Mediable\UrlGenerators\UrlGeneratorFactory;
14

15
/**
16
 * Mediable Service Provider.
17
 *
18
 * Registers Laravel-Mediable package functionality
19
 */
20
class MediableServiceProvider extends ServiceProvider
21
{
22
    /**
23
     * Boot the service provider.
24
     *
25
     * @return void
26
     */
27
    public function boot(): void
28
    {
29
        if (!$this->app->runningInConsole()) {
1,950✔
NEW
30
            return;
×
31
        }
32

33
        $root = dirname(__DIR__);
1,950✔
34
        $this->publishes(
1,950✔
35
            [
975✔
36
                $root . '/config/mediable.php' => config_path('mediable.php'),
1,950✔
37
            ],
975✔
38
            'config'
1,950✔
39
        );
975✔
40

41
        if (empty(glob($this->app->databasePath('migrations/*_create_mediable_tables.php'))) && empty(glob($this->app->databasePath('migrations/*_add_variants_to_media.php')))) {
1,950✔
42
            $this->publishes([
1,950✔
43
                $root . '/migrations/2016_06_27_000000_create_mediable_tables.php' => $this->app->databasePath('migrations/'.date('Y_m_d_His', time()).'_create_mediable_tables.php'),
1,950✔
44
            ], 'mediable-migrations');
1,950✔
45
            $this->publishes([
1,950✔
46
                $root . '/migrations/2020_10_12_000000_add_variants_to_media.php' => $this->app->databasePath('migrations/'.date('Y_m_d_His', time() + 1).'_add_variants_to_media.php'),
1,950✔
47
            ], 'mediable-migrations');
1,950✔
48
        }
49

50
        if (!config('mediable.ignore_migrations', false)) {
1,950✔
51
            $this->loadMigrationsFrom($root . '/migrations');
1,950✔
52
        }
53
    }
975✔
54

55
    /**
56
     * Register the service provider.
57
     *
58
     * @return void
59
     */
60
    public function register(): void
61
    {
62
        $this->mergeConfigFrom(
1,950✔
63
            dirname(__DIR__) . '/config/mediable.php',
1,950✔
64
            'mediable'
1,950✔
65
        );
975✔
66

67
        $this->registerSourceAdapterFactory();
1,950✔
68
        $this->registerUploader();
1,950✔
69
        $this->registerMover();
1,950✔
70
        $this->registerUrlGeneratorFactory();
1,950✔
71
        $this->registerConsoleCommands();
1,950✔
72
        $this->registerImageManipulator();
1,950✔
73
    }
975✔
74

75
    /**
76
     * Bind an instance of the Source Adapter Factory to the container.
77
     *
78
     * Attaches the default adapter types
79
     * @return void
80
     */
81
    public function registerSourceAdapterFactory(): void
82
    {
83
        $this->app->singleton('mediable.source.factory', function (Container $app) {
1,950✔
84
            $factory = new SourceAdapterFactory;
864✔
85

86
            $classAdapters = $app['config']->get('mediable.source_adapters.class', []);
864✔
87
            foreach ($classAdapters as $source => $adapter) {
864✔
88
                $factory->setAdapterForClass($adapter, $source);
864✔
89
            }
90

91
            $patternAdapters = $app['config']->get('mediable.source_adapters.pattern', []);
864✔
92
            foreach ($patternAdapters as $source => $adapter) {
864✔
93
                $factory->setAdapterForPattern($adapter, $source);
864✔
94
            }
95

96
            return $factory;
864✔
97
        });
1,950✔
98
        $this->app->alias('mediable.source.factory', SourceAdapterFactory::class);
1,950✔
99
    }
975✔
100

101
    /**
102
     * Bind the Media Uploader to the container.
103
     * @return void
104
     */
105
    public function registerUploader(): void
106
    {
107
        $this->app->bind('mediable.uploader', function (Container $app) {
1,950✔
108
            return new MediaUploader(
858✔
109
                $app['filesystem'],
858✔
110
                $app['mediable.source.factory'],
858✔
111
                $app['config']->get('mediable')
858✔
112
            );
429✔
113
        });
1,950✔
114
        $this->app->alias('mediable.uploader', MediaUploader::class);
1,950✔
115
    }
975✔
116

117
    /**
118
     * Bind the Media Uploader to the container.
119
     * @return void
120
     */
121
    public function registerMover(): void
122
    {
123
        $this->app->bind('mediable.mover', function (Container $app) {
1,950✔
124
            return new MediaMover($app['filesystem']);
42✔
125
        });
1,950✔
126
        $this->app->alias('mediable.mover', MediaMover::class);
1,950✔
127
    }
975✔
128

129
    /**
130
     * Bind the Media Uploader to the container.
131
     * @return void
132
     */
133
    public function registerUrlGeneratorFactory(): void
134
    {
135
        $this->app->singleton('mediable.url.factory', function (Container $app) {
1,950✔
136
            $factory = new UrlGeneratorFactory;
72✔
137

138
            $config = $app['config']->get('mediable.url_generators', []);
72✔
139
            foreach ($config as $driver => $generator) {
72✔
140
                $factory->setGeneratorForFilesystemDriver($generator, $driver);
72✔
141
            }
142

143
            return $factory;
72✔
144
        });
1,950✔
145
        $this->app->alias('mediable.url.factory', UrlGeneratorFactory::class);
1,950✔
146
    }
975✔
147

148
    public function registerImageManipulator(): void
149
    {
150
        $this->app->singleton(ImageManipulator::class);
1,950✔
151
    }
975✔
152

153
    /**
154
     * Add package commands to artisan console.
155
     * @return void
156
     */
157
    public function registerConsoleCommands(): void
158
    {
159
        $this->commands([
1,950✔
160
            ImportMediaCommand::class,
1,950✔
161
            PruneMediaCommand::class,
975✔
162
            SyncMediaCommand::class,
975✔
163
        ]);
975✔
164
    }
975✔
165
}
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