-
-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathApplication.php
153 lines (131 loc) · 3.7 KB
/
Application.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
declare(strict_types=1);
/**
* This file is part of Laravel Zero.
*
* (c) Nuno Maduro <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace LaravelZero\Framework;
use Illuminate\Events\EventServiceProvider;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\Application as BaseApplication;
use Illuminate\Foundation\Configuration\ApplicationBuilder;
use Illuminate\Foundation\PackageManifest;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use LaravelZero\Framework\Exceptions\ConsoleException;
use Symfony\Component\Console\Exception\CommandNotFoundException;
class Application extends BaseApplication
{
/**
* @{@inheritdoc}
*/
public static function configure(?string $basePath = null): ApplicationBuilder
{
$basePath = match (true) {
is_string($basePath) => $basePath,
default => static::inferBasePath(),
};
$builder = (new ApplicationBuilder(new static($basePath))); // @phpstan-ignore-line
$builder->create()->singleton(
\Illuminate\Contracts\Console\Kernel::class,
\LaravelZero\Framework\Kernel::class
);
$builder->create()->singleton(
\Illuminate\Contracts\Debug\ExceptionHandler::class,
\Illuminate\Foundation\Exceptions\Handler::class
);
return $builder
->withEvents()
->withCommands()
->withProviders();
}
/**
* Get the `builds` path. With, optionally, a path to append to the base path.
*/
public function buildsPath(string $path = ''): string
{
return $this->basePath('builds'.($path ? DIRECTORY_SEPARATOR.$path : $path));
}
/**
* {@inheritdoc}
*/
protected function registerBaseBindings(): void
{
parent::registerBaseBindings();
/*
* Ignores auto-discovery.
*/
$this->make(PackageManifest::class)->manifest = [];
}
/**
* {@inheritdoc}
*/
protected function registerBaseServiceProviders(): void
{
$this->register(new EventServiceProvider($this));
}
/**
* {@inheritdoc}
*/
public function version()
{
return $this['config']->get('app.version');
}
/**
* {@inheritdoc}
*/
public function runningInConsole(): bool
{
return true;
}
/**
* {@inheritdoc}
*/
public function isDownForMaintenance(): bool
{
return false;
}
/**
* {@inheritdoc}
*/
public function configurationIsCached(): bool
{
return false;
}
/**
* Register all the configured providers.
*/
public function registerConfiguredProviders(): void
{
$providers = Collection::make($this['config']['app.providers'])
->partition(
fn ($provider) => Str::startsWith($provider, 'Illuminate\\')
);
$providers->splice(
1,
0,
[
$this->make(PackageManifest::class)
->providers(),
]
);
(new ProviderRepository($this, new Filesystem, $this->getCachedServicesPath()))->load(
$providers->collapse()
->toArray()
);
}
/**
* Throw a Console Exception with the given data unless the given condition is true.
*/
public function abort($code, $message = '', array $headers = []): void
{
if ($code === 404) {
throw new CommandNotFoundException($message);
}
throw new ConsoleException($code, $message, $headers);
}
}