Completed
Push — dev ( 344895...8a0e98 )
by Zach
02:16
created

Yarak::getKernel()   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 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Yarak;
4
5
use Phalcon\DI;
6
use Phalcon\DiInterface;
7
use Phalcon\Di\FactoryDefault;
8
use Yarak\Exceptions\FileNotFound;
9
use Symfony\Component\Console\Input\ArrayInput;
10
use Symfony\Component\Console\Output\NullOutput;
11
use Symfony\Component\Console\Output\BufferedOutput;
12
13
class Yarak
14
{
15
    /**
16
     * Call a Yarak console command.
17
     *
18
     * @param string         $command
19
     * @param array          $arguments Argument array.
20
     * @param FactoryDefault $di        DI, may be necessary for php 5.6.
21
     * @param bool           $debug     If true, use and return buffered output.
22
     */
23
    public static function call(
24
        $command,
25
        array $arguments = [],
26
        DiInterface $di = null,
27
        $debug = false
28
    ) {
29
        $di = is_null($di) ? DI::getDefault() : $di;
30
31
        $kernel = $di->get('yarak');
32
33
        $input = new ArrayInput(['command' => $command] + $arguments);
34
35
        if ($debug) {
36
            $kernel->handle($input, $output = new BufferedOutput());
37
38
            return $output;
39
        }
40
41
        $kernel->handle($input, new NullOutput());
42
    }
43
}
44