Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Console\Concerns;
4
 
5
use Symfony\Component\Console\Input\ArrayInput;
6
use Symfony\Component\Console\Output\NullOutput;
7
use Symfony\Component\Console\Output\OutputInterface;
8
 
9
trait CallsCommands
10
{
11
    /**
12
     * Resolve the console command instance for the given command.
13
     *
14
     * @param  \Symfony\Component\Console\Command\Command|string  $command
15
     * @return \Symfony\Component\Console\Command\Command
16
     */
17
    abstract protected function resolveCommand($command);
18
 
19
    /**
20
     * Call another console command.
21
     *
22
     * @param  \Symfony\Component\Console\Command\Command|string  $command
23
     * @param  array  $arguments
24
     * @return int
25
     */
26
    public function call($command, array $arguments = [])
27
    {
28
        return $this->runCommand($command, $arguments, $this->output);
29
    }
30
 
31
    /**
32
     * Call another console command without output.
33
     *
34
     * @param  \Symfony\Component\Console\Command\Command|string  $command
35
     * @param  array  $arguments
36
     * @return int
37
     */
38
    public function callSilent($command, array $arguments = [])
39
    {
40
        return $this->runCommand($command, $arguments, new NullOutput);
41
    }
42
 
43
    /**
44
     * Call another console command without output.
45
     *
46
     * @param  \Symfony\Component\Console\Command\Command|string  $command
47
     * @param  array  $arguments
48
     * @return int
49
     */
50
    public function callSilently($command, array $arguments = [])
51
    {
52
        return $this->callSilent($command, $arguments);
53
    }
54
 
55
    /**
56
     * Run the given the console command.
57
     *
58
     * @param  \Symfony\Component\Console\Command\Command|string  $command
59
     * @param  array  $arguments
60
     * @param  \Symfony\Component\Console\Output\OutputInterface  $output
61
     * @return int
62
     */
63
    protected function runCommand($command, array $arguments, OutputInterface $output)
64
    {
65
        $arguments['command'] = $command;
66
 
67
        return $this->resolveCommand($command)->run(
68
            $this->createInputFromArguments($arguments), $output
69
        );
70
    }
71
 
72
    /**
73
     * Create an input instance from the given arguments.
74
     *
75
     * @param  array  $arguments
76
     * @return \Symfony\Component\Console\Input\ArrayInput
77
     */
78
    protected function createInputFromArguments(array $arguments)
79
    {
80
        return tap(new ArrayInput(array_merge($this->context(), $arguments)), function ($input) {
81
            if ($input->getParameterOption('--no-interaction')) {
82
                $input->setInteractive(false);
83
            }
84
        });
85
    }
86
 
87
    /**
88
     * Get all of the context passed to the command.
89
     *
90
     * @return array
91
     */
92
    protected function context()
93
    {
94
        return collect($this->option())->only([
95
            'ansi',
96
            'no-ansi',
97
            'no-interaction',
98
            'quiet',
99
            'verbose',
100
        ])->filter()->mapWithKeys(function ($value, $key) {
101
            return ["--{$key}" => $value];
102
        })->all();
103
    }
104
}