Completed
Push — master ( f493e8...60bb4c )
by Andrii
03:26
created

BinariesController::exec()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
/*
4
 * Task runner, code generator and build tool for easier continuos integration
5
 *
6
 * @link      https://github.com/hiqdev/hidev
7
 * @package   hidev
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hidev\controllers;
13
14
class BinariesController extends CommonController
15
{
16
    use \hiqdev\yii2\collection\ManagerTrait;
17
18
    protected $_before = ['start'];
19
20
    public $defaultClass = 'hidev\base\BinaryPhp';
21
22
    public function actionMake()
23
    {
24
        foreach ($this->getItems() as $name => $bin) {
25
            if (!$bin->detectPath($name)) {
26
                $exitcode = $bin->install();
27
                if ($exitcode) {
28
                    return $exitcode;
29
                }
30
            }
31
        }
32
    }
33
34
    /**
35
     * Prepares item config.
36
     */
37
    public function getItemConfig($name = null, array $config = [])
38
    {
39
        return array_merge([
40
            'name'  => $name,
41
            'class' => $this->defaultClass,
42
        ], $config);
43
    }
44
45
    /**
46
     * Prepares and runs with passthru. Returns exit code.
47
     * @param string $name binary
48
     * @param string $args
49
     * @return int exit code
50
     */
51
    public function passthru($name, $args = [])
52
    {
53
        return $this->get($name)->passthru($args);
54
    }
55
56
    /**
57
     * Prepares and runs with exec. Returns stdout string.
58
     * @param string $name binary
59
     * @param string $args
60
     * @return array stdout
61
     */
62
    public function exec($name, $args = [])
63
    {
64
        return $this->get($name)->exec($args);
65
    }
66
}
67