Binaries::passthruBinary()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Automation tool mixed with code generator for easier continuous development
4
 *
5
 * @link      https://github.com/hiqdev/hidev
6
 * @package   hidev
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hidev\components;
12
13
use hidev\base\BinaryPhp;
14
15
class Binaries extends \hidev\base\Component
16
{
17
    use \hiqdev\yii2\collection\ManagerTrait;
18
19
    public $defaultClass = BinaryPhp::class;
20
21
    public function actionMake()
22
    {
23
        foreach ($this->getItems() as $name => $bin) {
24
            if (!$bin->detectPath($name)) {
25
                $exitcode = $bin->install();
26
                if ($exitcode) {
27
                    return $exitcode;
28
                }
29
            }
30
        }
31
    }
32
33
    /**
34
     * Prepares item config.
35
     */
36
    public function getItemConfig($name = null, array $config = [])
37
    {
38
        return array_merge([
39
            'name'  => $name,
40
            'class' => $this->defaultClass,
41
            'binaries' => $this,
42
        ], $config);
43
    }
44
45
    /**
46
     * Prepares and runs with passthru. Returns exit code.
47
     * @param string $name binary
48
     * @param array|string $args
49
     * @return int exit code
50
     */
51
    public function passthruBinary($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 execBinary($name, $args = '', $returnExitCode = false)
63
    {
64
        return $this->get($name)->exec($args, $returnExitCode);
65
    }
66
}
67