|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Larafast\Fastapi; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Migrations\MigrationCreator; |
|
6
|
|
|
use Illuminate\Support\ServiceProvider; |
|
7
|
|
|
use Larafast\Fastapi\Console\Commands\ControllerMakeCommand; |
|
8
|
|
|
use Larafast\Fastapi\Console\Commands\FactoryMakeCommand; |
|
9
|
|
|
use Larafast\Fastapi\Console\Commands\Fastapi; |
|
|
|
|
|
|
10
|
|
|
use Larafast\Fastapi\Console\Commands\MigrateMakeCommand; |
|
11
|
|
|
use Larafast\Fastapi\Console\Commands\ModelMakeCommand; |
|
12
|
|
|
use Larafast\Fastapi\Console\Commands\RequestMakeCommand; |
|
13
|
|
|
use Larafast\Fastapi\Console\Commands\ResourceMakeCommand; |
|
14
|
|
|
|
|
15
|
|
|
class FastapiServiceProvider extends ServiceProvider |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
protected $commands = [ |
|
19
|
|
|
ControllerMakeCommand::class, |
|
20
|
|
|
FactoryMakeCommand::class, |
|
21
|
|
|
Fastapi::class, |
|
22
|
|
|
MigrateMakeCommand::class, |
|
23
|
|
|
ModelMakeCommand::class, |
|
24
|
|
|
RequestMakeCommand::class, |
|
25
|
|
|
ResourceMakeCommand::class, |
|
26
|
|
|
]; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Bootstrap the application services. |
|
30
|
|
|
*/ |
|
31
|
|
|
public function boot() |
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
|
|
$this->publishes([ |
|
35
|
|
|
__DIR__ . '/../config/config.php' => config_path('fastApi.php'), |
|
36
|
|
|
], 'fastApi'); |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
// $this->publishes([ |
|
40
|
|
|
// __DIR__ . '/../resources/stubs' => resource_path('stubs') |
|
41
|
|
|
// ], 'fastApi'); |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
$this->app->when(MigrationCreator::class) |
|
45
|
|
|
->needs('$customStubPath') |
|
46
|
|
|
->give(function ($app) { |
|
|
|
|
|
|
47
|
|
|
return base_path('vendor/larafast/fastapi/resources/stubs'); |
|
48
|
|
|
}); |
|
49
|
|
|
|
|
50
|
|
|
$this->commands($this->commands); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Register the application services. |
|
55
|
|
|
*/ |
|
56
|
|
|
public function register() |
|
57
|
|
|
{ |
|
58
|
|
|
// Automatically apply the package configuration |
|
59
|
|
|
$this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'fastApi'); |
|
60
|
|
|
|
|
61
|
|
|
// Register the main class to use with the facade |
|
62
|
|
|
$this->app->singleton('fastApi', function () { |
|
63
|
|
|
return new Fastapi; |
|
|
|
|
|
|
64
|
|
|
}); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
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: