|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ProtoneMedia\LaravelFFMpeg\Support; |
|
4
|
|
|
|
|
5
|
|
|
use FFMpeg\Driver\FFMpegDriver; |
|
6
|
|
|
use FFMpeg\FFMpeg; |
|
|
|
|
|
|
7
|
|
|
use FFMpeg\FFProbe; |
|
8
|
|
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
|
9
|
|
|
use ProtoneMedia\LaravelFFMpeg\Drivers\PHPFFMpeg; |
|
10
|
|
|
use ProtoneMedia\LaravelFFMpeg\Filesystem\TemporaryDirectories; |
|
11
|
|
|
use Psr\Log\LoggerInterface; |
|
12
|
|
|
|
|
13
|
|
|
class ServiceProvider extends BaseServiceProvider |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Bootstrap the application services. |
|
17
|
|
|
*/ |
|
18
|
|
|
public function boot() |
|
19
|
|
|
{ |
|
20
|
|
|
if ($this->app->runningInConsole()) { |
|
21
|
|
|
$this->publishes([ |
|
22
|
|
|
__DIR__ . '/../../config/config.php' => config_path('laravel-ffmpeg.php'), |
|
23
|
|
|
], 'config'); |
|
24
|
|
|
} |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Register the application services. |
|
29
|
|
|
*/ |
|
30
|
|
|
public function register() |
|
31
|
|
|
{ |
|
32
|
|
|
// Automatically apply the package configuration |
|
33
|
|
|
$this->mergeConfigFrom(__DIR__ . '/../../config/config.php', 'laravel-ffmpeg'); |
|
34
|
|
|
|
|
35
|
|
|
$this->app->singleton('laravel-ffmpeg-logger', function () { |
|
36
|
|
|
return $this->app['config']->get('laravel-ffmpeg.enable_logging', true) |
|
37
|
|
|
? app(LoggerInterface::class) |
|
38
|
|
|
: null; |
|
39
|
|
|
}); |
|
40
|
|
|
|
|
41
|
|
|
$this->app->singleton('laravel-ffmpeg-configuration', function () { |
|
42
|
|
|
$config = $this->app['config']; |
|
43
|
|
|
|
|
44
|
|
|
return [ |
|
45
|
|
|
'ffmpeg.binaries' => $config->get('laravel-ffmpeg.ffmpeg.binaries'), |
|
46
|
|
|
'ffmpeg.threads' => $config->get('laravel-ffmpeg.ffmpeg.threads', 12), |
|
47
|
|
|
'ffprobe.binaries' => $config->get('laravel-ffmpeg.ffprobe.binaries'), |
|
48
|
|
|
'timeout' => $config->get('laravel-ffmpeg.timeout'), |
|
49
|
|
|
]; |
|
50
|
|
|
}); |
|
51
|
|
|
|
|
52
|
|
|
$this->app->singleton(FFProbe::class, function () { |
|
53
|
|
|
return FFProbe::create( |
|
54
|
|
|
$this->app->make('laravel-ffmpeg-configuration'), |
|
55
|
|
|
$this->app->make('laravel-ffmpeg-logger') |
|
56
|
|
|
); |
|
57
|
|
|
}); |
|
58
|
|
|
|
|
59
|
|
|
$this->app->singleton(FFMpegDriver::class, function () { |
|
60
|
|
|
return FFMpegDriver::create( |
|
61
|
|
|
$this->app->make('laravel-ffmpeg-logger'), |
|
62
|
|
|
$this->app->make('laravel-ffmpeg-configuration') |
|
63
|
|
|
); |
|
64
|
|
|
}); |
|
65
|
|
|
|
|
66
|
|
|
$this->app->singleton(FFMpeg::class, function () { |
|
67
|
|
|
return new FFMpeg( |
|
68
|
|
|
$this->app->make(FFMpegDriver::class), |
|
69
|
|
|
$this->app->make(FFProbe::class) |
|
70
|
|
|
); |
|
71
|
|
|
}); |
|
72
|
|
|
|
|
73
|
|
|
$this->app->singleton(PHPFFMpeg::class, function () { |
|
74
|
|
|
return new PHPFFMpeg($this->app->make(FFMpeg::class)); |
|
75
|
|
|
}); |
|
76
|
|
|
|
|
77
|
|
|
$this->app->singleton(TemporaryDirectories::class, function () { |
|
78
|
|
|
return new TemporaryDirectories( |
|
79
|
|
|
$this->app['config']->get('laravel-ffmpeg.temporary_files_root', sys_get_temp_dir()), |
|
80
|
|
|
); |
|
81
|
|
|
}); |
|
82
|
|
|
|
|
83
|
|
|
// Register the main class to use with the facade |
|
84
|
|
|
$this->app->singleton('laravel-ffmpeg', function () { |
|
85
|
|
|
return new MediaOpenerFactory( |
|
86
|
|
|
$this->app['config']->get('filesystems.default'), |
|
87
|
|
|
$this->app->make(PHPFFMpeg::class) |
|
88
|
|
|
); |
|
89
|
|
|
}); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: