1 | <?php |
||
2 | |||
3 | namespace OwenIt\Auditing; |
||
4 | |||
5 | use Illuminate\Contracts\Support\DeferrableProvider; |
||
6 | use Illuminate\Support\ServiceProvider; |
||
7 | |||
8 | use OwenIt\Auditing\Contracts\Auditor; |
||
0 ignored issues
–
show
|
|||
9 | use OwenIt\Auditing\Console\AuditDriverCommand; |
||
10 | use OwenIt\Auditing\Console\InstallCommand; |
||
11 | |||
12 | class AuditingServiceProvider extends ServiceProvider implements DeferrableProvider |
||
13 | { |
||
14 | /** |
||
15 | * Bootstrap the service provider. |
||
16 | * |
||
17 | * @return void |
||
18 | */ |
||
19 | 96 | public function boot() |
|
20 | { |
||
21 | 96 | $this->registerPublishing(); |
|
22 | 96 | $this->mergeConfigFrom(__DIR__.'/../config/audit.php', 'audit'); |
|
23 | 96 | } |
|
24 | |||
25 | /** |
||
26 | * Register the service provider. |
||
27 | * |
||
28 | * @return void |
||
29 | */ |
||
30 | 96 | public function register() |
|
31 | { |
||
32 | 96 | $this->commands([ |
|
33 | 96 | AuditDriverCommand::class, |
|
34 | InstallCommand::class, |
||
35 | ]); |
||
36 | |||
37 | $this->app->singleton(Auditor::class, function ($app) { |
||
38 | 50 | return new \OwenIt\Auditing\Auditor($app); |
|
39 | 96 | }); |
|
40 | 96 | } |
|
41 | |||
42 | /** |
||
43 | * Register the package's publishable resources. |
||
44 | * |
||
45 | * @return void |
||
46 | */ |
||
47 | 96 | private function registerPublishing() |
|
48 | { |
||
49 | 96 | if ($this->app->runningInConsole()) { |
|
50 | // Lumen lacks a config_path() helper, so we use base_path() |
||
51 | 96 | $this->publishes([ |
|
52 | 96 | __DIR__.'/../config/audit.php' => base_path('config/audit.php'), |
|
53 | 96 | ], 'config'); |
|
54 | |||
55 | 96 | $this->publishes([ |
|
56 | 96 | __DIR__.'/../database/migrations/audits.stub' => database_path( |
|
57 | 96 | sprintf('migrations/%s_create_audits_table.php', date('Y_m_d_His')) |
|
58 | ), |
||
59 | 96 | ], 'migrations'); |
|
60 | } |
||
61 | 96 | } |
|
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | 1 | public function provides() |
|
67 | { |
||
68 | return [ |
||
69 | 1 | Auditor::class, |
|
70 | ]; |
||
71 | } |
||
72 | } |
||
73 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are 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.php
However, as
OtherDir/Foo.php
does 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: