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