Completed
Push — master ( c331ed...f9d48b )
by Andrii
02:44
created

BinariesController::passthruBinary()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 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) 2015-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
    public $defaultClass = 'hidev\base\BinaryPhp';
19
20
    public function actionMake()
21
    {
22
        foreach ($this->getItems() as $name => $bin) {
23
            if (!$bin->detectPath($name)) {
24
                $exitcode = $bin->install();
25
                if ($exitcode) {
26
                    return $exitcode;
27
                }
28
            }
29
        }
30
    }
31
32
    /**
33
     * Prepares item config.
34
     */
35
    public function getItemConfig($name = null, array $config = [])
36
    {
37
        return array_merge([
38
            'name'  => $name,
39
            'class' => $this->defaultClass,
40
        ], $config);
41
    }
42
43
    /**
44
     * Prepares and runs with passthru. Returns exit code.
45
     * @param string $name binary
46
     * @param string $args
47
     * @return int exit code
48
     */
49
    public function passthruBinary($name, $args = [])
50
    {
51
        return $this->get($name)->passthru($args);
52
    }
53
54
    /**
55
     * Prepares and runs with exec. Returns stdout string.
56
     * @param string $name binary
57
     * @param string $args
58
     * @return array stdout
59
     */
60
    public function execBinary($name, $args = '', $returnExitCode = false)
61
    {
62
        return $this->get($name)->exec($args, $returnExitCode);
63
    }
64
}
65