Issues (59)

src/ChunkyServiceProvider.php (1 issue)

1
<?php
2
3
namespace Jobtech\LaravelChunky;
4
5
use Illuminate\Contracts\Container\Container;
6
use Illuminate\Contracts\Filesystem\Factory;
7
use Illuminate\Foundation\Application as LaravelApplication;
8
use Illuminate\Support\ServiceProvider;
9
use Jobtech\LaravelChunky\Commands\ClearChunks;
10
use Jobtech\LaravelChunky\Contracts\ChunkyManager as ChunkyManagerContract;
11
use Jobtech\LaravelChunky\Support\ChunksFilesystem;
12
use Jobtech\LaravelChunky\Support\MergeFilesystem;
13
use Jobtech\LaravelChunky\Support\TempFilesystem;
14
use Laravel\Lumen\Application as LumenApplication;
15
16
class ChunkyServiceProvider extends ServiceProvider
17
{
18
    /**
19
     * Boot the application services.
20
     *
21
     * @return void
22
     */
23
    public function boot()
24
    {
25
        $this->setupConfig();
26
    }
27
28
    /**
29
     * Register any application services.
30
     *
31
     * @return void
32
     */
33
    public function register()
34
    {
35
        $this->registerBindings();
36
        $this->registerCommands();
37
38
        $this->app->alias(ChunkyManagerContract::class, 'chunky');
39
    }
40
41
    protected function setupConfig()
42
    {
43
        $source = realpath(__DIR__.'/../config/chunky.php');
44
45
        if ($this->app instanceof LaravelApplication) {
46
            $this->publishes([
47
                $source => config_path('chunky.php'),
0 ignored issues
show
The function config_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
                $source => /** @scrutinizer ignore-call */ config_path('chunky.php'),
Loading history...
48
            ], 'config');
49
        } elseif ($this->app instanceof LumenApplication) {
50
            $this->app->configure('chunky');
51
        }
52
53
        $this->mergeConfigFrom($source, 'chunky');
54
    }
55
56
    private function registerCommands()
57
    {
58
        $this->app->bind('command.chunky:clear', ClearChunks::class);
59
60
        $this->commands([
61
            'command.chunky:clear',
62
        ]);
63
    }
64
65
    private function registerBindings()
66
    {
67
        $this->app->singleton(TempFilesystem::class, function () {
68
            $config = $this->app->make('config');
69
            $filesystem = new TempFilesystem(app()->make(Factory::class));
70
71
            $filesystem->disk($config->get('chunky.disks.tmp.disk', $config->get('filesystems.default')));
72
            $filesystem->folder($config->get('chunky.disks.tmp.folder'));
73
74
            return $filesystem;
75
        });
76
77
        $this->app->bind(ChunksFilesystem::class, ChunksFilesystem::class);
78
        $this->app->bind(MergeFilesystem::class, MergeFilesystem::class);
79
80
        $this->app->singleton(ChunkySettings::class, function (Container $app) {
81
            return new ChunkySettings($app->make('config'));
82
        });
83
84
        $this->app->singleton(ChunkyManagerContract::class, function (Container $app) {
85
            return new ChunkyManager($app->make(ChunkySettings::class));
86
        });
87
    }
88
}
89