1 | <?php |
||
2 | |||
3 | namespace OwenIt\Auditing; |
||
4 | |||
5 | use Illuminate\Support\Facades\Event; |
||
6 | use Illuminate\Support\ServiceProvider; |
||
7 | use OwenIt\Auditing\Console\AuditDriverCommand; |
||
8 | use OwenIt\Auditing\Console\AuditResolverCommand; |
||
9 | use OwenIt\Auditing\Console\InstallCommand; |
||
10 | use OwenIt\Auditing\Contracts\Auditor; |
||
0 ignored issues
–
show
|
|||
11 | use OwenIt\Auditing\Events\AuditCustom; |
||
12 | use OwenIt\Auditing\Events\DispatchAudit; |
||
13 | use OwenIt\Auditing\Listeners\ProcessDispatchAudit; |
||
14 | use OwenIt\Auditing\Listeners\RecordCustomAudit; |
||
15 | |||
16 | class AuditingServiceProvider extends ServiceProvider |
||
17 | { |
||
18 | /** |
||
19 | * Bootstrap the service provider. |
||
20 | * |
||
21 | * @return void |
||
22 | */ |
||
23 | 17 | public function boot() |
|
24 | { |
||
25 | 17 | $this->registerPublishing(); |
|
26 | 17 | $this->mergeConfigFrom(__DIR__ . '/../config/audit.php', 'audit'); |
|
27 | |||
28 | 17 | Event::listen(AuditCustom::class, RecordCustomAudit::class); |
|
29 | 17 | Event::listen(DispatchAudit::class, ProcessDispatchAudit::class); |
|
30 | } |
||
31 | |||
32 | /** |
||
33 | * Register the service provider. |
||
34 | * |
||
35 | * @return void |
||
36 | */ |
||
37 | 17 | public function register() |
|
38 | { |
||
39 | 17 | $this->commands([ |
|
40 | 17 | AuditDriverCommand::class, |
|
41 | 17 | AuditResolverCommand::class, |
|
42 | 17 | InstallCommand::class, |
|
43 | 17 | ]); |
|
44 | |||
45 | 17 | $this->app->singleton(Auditor::class, function ($app) { |
|
46 | 15 | return new \OwenIt\Auditing\Auditor($app); |
|
47 | 17 | }); |
|
48 | } |
||
49 | |||
50 | /** |
||
51 | * Register the package's publishable resources. |
||
52 | * |
||
53 | * @return void |
||
54 | */ |
||
55 | 17 | private function registerPublishing() |
|
56 | { |
||
57 | 17 | if ($this->app->runningInConsole()) { |
|
58 | // Lumen lacks a config_path() helper, so we use base_path() |
||
59 | 17 | $this->publishes([ |
|
60 | 17 | __DIR__ . '/../config/audit.php' => base_path('config/audit.php'), |
|
61 | 17 | ], 'config'); |
|
62 | |||
63 | 17 | if (!class_exists('CreateAuditsTable')) { |
|
64 | 2 | $this->publishes([ |
|
65 | 2 | __DIR__ . '/../database/migrations/audits.stub' => database_path( |
|
66 | 2 | sprintf('migrations/%s_create_audits_table.php', date('Y_m_d_His')) |
|
67 | 2 | ), |
|
68 | 2 | ], 'migrations'); |
|
69 | } |
||
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: