Test Failed
Push — stable ( 3c4cff...19e4da )
by Nuno
02:12
created

Application::bootstrap()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace LaravelZero\Framework;
4
5
use Illuminate\Events\Dispatcher;
6
use Symfony\Component\Console\Command\Command;
7
use Illuminate\Support\Traits\CapsuleManagerTrait;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Illuminate\Console\Application as BaseApplication;
11
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
12
use Illuminate\Contracts\Container\Container as ContainerContract;
13
use LaravelZero\Framework\Contracts\Application as ApplicationContract;
14
use LaravelZero\Framework\Contracts\Providers\ErrorHandler as ErrorHandlerContract;
15
16
/**
17
 * This is the Laravel Zero Framework application class.
18
 *
19
 * @author Nuno Maduro <[email protected]>
20
 */
21
class Application extends BaseApplication implements ApplicationContract
22
{
23
    use CapsuleManagerTrait;
24
25
    /**
26
     * The application event dispatcher.
27
     *
28
     * @var \Illuminate\Contracts\Events\Dispatcher
29
     */
30
    protected $dispatcher;
31
32
    /**
33
     * The current running command.
34
     *
35
     * @var \Symfony\Component\Console\Command\Command
36
     */
37
    protected $runningCommand;
38
39
    /**
40
     * Holds an instance of the bootstrapper factory.
41
     *
42
     * @var \LaravelZero\Framework\Bootstrappers\Factory
43
     */
44
    protected $bootstrappersFactory;
45
46
    /**
47
     * Creates a new instance of the application.
48
     *
49
     * @param \Illuminate\Contracts\Container\Container|null $container
50
     * @param \Illuminate\Contracts\Events\Dispatcher|null $dispatcher
51
     * @param \LaravelZero\Framework\Bootstrappers\Factory|null $bootstrappersFactory
52
     */
53
    public function __construct(
54
        ContainerContract $container = null,
55
        DispatcherContract $dispatcher = null,
56
        Bootstrappers\Factory $bootstrappersFactory = null
57
    ) {
58
        $this->setupContainer($container ?: new Container);
59
        $this->dispatcher = $dispatcher ?: new Dispatcher($this->container);
60
        $this->bootstrappersFactory = $bootstrappersFactory ?: new Bootstrappers\Factory;
61
        parent::__construct($this->container, $this->dispatcher, '');
62
63
        $this->setCatchExceptions(true);
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    protected function bootstrap()
70
    {
71
        foreach ($this->bootstrappersFactory->make() as $bootstrapper) {
72
            $bootstrapper($this);
73
        }
74
75
        parent::bootstrap();
76
    }
77
78
    /**
79
     * Gets the name of the command based on input.
80
     *
81
     * Proxies to the Laravel default command if there is no application
82
     * default command.
83
     *
84
     * @param \Symfony\Component\Console\Input\InputInterface $input The input interface
85
     *
86
     * @return string|null
87
     */
88
    protected function getCommandName(InputInterface $input)
89
    {
90
        if (($name = parent::getCommandName($input)) || ($defaultCommand = $this->container->make('config')
91
                ->get('app.default-command')) === null) {
92
            return $name;
93
        }
94
95
        return $this->container->make($defaultCommand)
96
            ->getName();
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
103
    {
104
        $this->container->make(ErrorHandlerContract::class)->setOutput($output);
105
106
        return parent::doRunCommand($this->runningCommand = $command, $input, $output);
107
    }
108
109
    /**
110
     * {@inheritdoc}
111
     */
112
    public function getRunningCommand(): Command
113
    {
114
        return $this->runningCommand;
115
    }
116
}
117