1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JunaidQadirB\Cray; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Migrations\MigrationCreator; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
use JunaidQadirB\Cray\Console\Commands\ControllerMakeCommand; |
8
|
|
|
use JunaidQadirB\Cray\Console\Commands\FactoryMakeCommand; |
9
|
|
|
use JunaidQadirB\Cray\Console\Commands\Cray; |
|
|
|
|
10
|
|
|
use JunaidQadirB\Cray\Console\Commands\MigrateMakeCommand; |
11
|
|
|
use JunaidQadirB\Cray\Console\Commands\ModelMakeCommand; |
12
|
|
|
use JunaidQadirB\Cray\Console\Commands\RequestMakeCommand; |
13
|
|
|
use JunaidQadirB\Cray\Console\Commands\ViewMakeCommand; |
14
|
|
|
|
15
|
|
|
class CrayServiceProvider extends ServiceProvider |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
protected $commands = [ |
19
|
|
|
ControllerMakeCommand::class, |
20
|
|
|
FactoryMakeCommand::class, |
21
|
|
|
Cray::class, |
22
|
|
|
MigrateMakeCommand::class, |
23
|
|
|
ModelMakeCommand::class, |
24
|
|
|
RequestMakeCommand::class, |
25
|
|
|
ViewMakeCommand::class, |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Bootstrap the application services. |
30
|
|
|
*/ |
31
|
|
|
public function boot() |
32
|
|
|
{ |
33
|
|
|
|
34
|
|
|
/* |
35
|
|
|
* Optional methods to load your package assets |
36
|
|
|
*/ |
37
|
|
|
// $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'cray'); |
38
|
|
|
// $this->loadViewsFrom(__DIR__.'/../resources/views', 'cray'); |
39
|
|
|
// $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); |
40
|
|
|
// $this->loadRoutesFrom(__DIR__.'/routes.php'); |
41
|
|
|
|
42
|
|
|
// if ($this->app->runningInConsole()) { |
43
|
|
|
$this->publishes([ |
44
|
|
|
__DIR__ . '/../config/config.php' => config_path('cray.php'), |
45
|
|
|
], 'cray'); |
46
|
|
|
|
47
|
|
|
// Publishing the views. |
48
|
|
|
/*$this->publishes([ |
49
|
|
|
__DIR__.'/../resources/views' => resource_path('views/vendor/cray'), |
50
|
|
|
], 'views');*/ |
51
|
|
|
|
52
|
|
|
// Publishing assets. |
53
|
|
|
$this->publishes([ |
54
|
|
|
__DIR__ . '/../resources/stubs' => resource_path('stubs') |
55
|
|
|
], 'cray'); |
56
|
|
|
|
57
|
|
|
// Publishing the translation files. |
58
|
|
|
/*$this->publishes([ |
59
|
|
|
__DIR__.'/../resources/lang' => resource_path('lang/vendor/cray'), |
60
|
|
|
], 'lang');*/ |
61
|
|
|
|
62
|
|
|
$this->app->when(MigrationCreator::class) |
63
|
|
|
->needs('$customStubPath') |
64
|
|
|
->give(function ($app) { |
|
|
|
|
65
|
|
|
return resource_path('stubs'); |
66
|
|
|
}); |
67
|
|
|
|
68
|
|
|
// Registering package commands. |
69
|
|
|
$this->commands($this->commands); |
70
|
|
|
// } |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Register the application services. |
75
|
|
|
*/ |
76
|
|
|
public function register() |
77
|
|
|
{ |
78
|
|
|
// Automatically apply the package configuration |
79
|
|
|
$this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'cray'); |
80
|
|
|
|
81
|
|
|
// Register the main class to use with the facade |
82
|
|
|
$this->app->singleton('cray', function () { |
83
|
|
|
return new Cray; |
|
|
|
|
84
|
|
|
}); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
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: