Completed
Pull Request — stable (#381)
by
unknown
04:23 queued 01:37
created

Application::runningInConsole()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Laravel Zero.
7
 *
8
 * (c) Nuno Maduro <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace LaravelZero\Framework;
15
16
use Illuminate\Events\EventServiceProvider;
17
use Illuminate\Filesystem\Filesystem;
18
use Illuminate\Foundation\Application as BaseApplication;
19
use Illuminate\Foundation\PackageManifest;
20
use Illuminate\Support\Collection;
21
use Illuminate\Support\Str;
22
use LaravelZero\Framework\Exceptions\ConsoleException;
23
use Symfony\Component\Console\Exception\CommandNotFoundException;
24
25
class Application extends BaseApplication
26
{
27
    /**
28
     * Get the builds path. With, optionally, a path to append to the base path.
29
     */
30
    public function buildsPath(string $path = ''): string
31
    {
32
        return $this->basePath('builds'.($path ? DIRECTORY_SEPARATOR.$path : $path));
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 38
    protected function registerBaseBindings(): void
39
    {
40 38
        parent::registerBaseBindings();
41
42
        /*
43
         * Ignores auto-discovery.
44
         */
45 38
        $this->make(PackageManifest::class)->manifest = [];
46 38
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 38
    protected function registerBaseServiceProviders(): void
52
    {
53 38
        $this->register(new EventServiceProvider($this));
54 38
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 38
    public function version()
60
    {
61 38
        return $this['config']->get('app.version');
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 38
    public function runningInConsole(): bool
68
    {
69 38
        return true;
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75 1
    public function isDownForMaintenance(): bool
76
    {
77 1
        return false;
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83 38
    public function configurationIsCached(): bool
84
    {
85 38
        return false;
86
    }
87
88
    /**
89
     * Register all of the configured providers.
90
     */
91 38
    public function registerConfiguredProviders(): void
92
    {
93 38
        $providers = Collection::make($this['config']['app.providers'])
94 38
            ->partition(
95
                function ($provider) {
96 38
                    return Str::startsWith($provider, 'Illuminate\\');
97 38
                }
98
            );
99
100 38
        $providers->splice(
101 38
            1,
102 38
            0,
103
            [
104 38
                $this->make(PackageManifest::class)
105 38
                    ->providers(),
106
            ]
107
        );
108
109 38
        (new ProviderRepository($this, new Filesystem, $this->getCachedServicesPath()))->load(
110 38
            $providers->collapse()
111 38
                ->toArray()
112
        );
113 38
    }
114
115
    /**
116
     * Throw an Console Exception with the given data unless the given condition is true.
117
     */
118 1
    public function abort($code, $message = '', array $headers = []): void
119
    {
120 1
        if ($code === 404) {
121 1
            throw new CommandNotFoundException($message);
122
        }
123
124 1
        throw new ConsoleException($code, $message, $headers);
125
    }
126
}
127