Issues (1519)

system/Inji/BowerCmd.php (7 issues)

1
<?php
2
namespace Inji;
3
/**
4
 * Composer command tool
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
class BowerCmd {
12
13
    public static $appInstance = null;
14
15
    public static function getInstance() {
16
        if (!self::$appInstance) {
17
            self::$appInstance = new Bowerphp\Console\Application();
0 ignored issues
show
The type Inji\Bowerphp\Console\Application was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
        }
19
        return self::$appInstance;
20
    }
21
22
    public static function check() {
23
        if (!file_exists(INJI_BASE_DIR . Cache::folder() . "static/bowerLibs/bower.json")) {
24
            BowerCmd::initBower();
25
        }
26
    }
27
28
    public static function initBower($path = '') {
29
        while (!Inji::$inst->blockParallel()) {
30
            sleep(2);
31
        }
32
        if (!$path) {
33
            $path = INJI_BASE_DIR . Cache::folder() . "static/bowerLibs/";
34
        }
35
        $json = [
36
            "name" => get_current_user() . "/" . $_SERVER['SERVER_NAME'],
37
            "config" => [
38
                "cache-dir" => INJI_BASE_DIR . Cache::folder() . "bower/"
39
            ],
40
            "authors" => [
41
                [
42
                    get_current_user() . ' <' . get_current_user() . "@" . $_SERVER['SERVER_NAME'] . '>'
43
                ]
44
            ],
45
            'private' => true,
46
            "dependencies" => [],
47
        ];
48
        Tools::createDir($path);
49
        file_put_contents($path . 'bower.json', json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
50
51
        if (!file_exists($path . '.bowerrc')) {
52
            $json = [
53
                "directory" => './',
54
                "interactive" => false
55
            ];
56
            Tools::createDir($path);
57
            file_put_contents($path . '.bowerrc', json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
58
        }
59
        self::command('install', false, $path);
60
        gc_collect_cycles();
61
        Inji::$inst->unBlockParallel();
62
    }
63
64
    public static function command($command, $needOutput = true, $path = null) {
65
        while (!Inji::$inst->blockParallel()) {
66
            sleep(2);
67
        }
68
        ComposerCmd::requirePackage("injitools/bowerphp", "dev-master", '.');
69
        include_once 'vendor/injitools/bowerphp/src/bootstrap.php';
70
        if ($needOutput) {
71
            $output = new Symfony\Component\Console\Output\StreamOutput(fopen('php://output', 'w'));
0 ignored issues
show
The type Inji\Symfony\Component\Console\Output\StreamOutput was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
72
        } else {
73
            $output = new Symfony\Component\Console\Output\NullOutput();
0 ignored issues
show
The type Inji\Symfony\Component\Console\Output\NullOutput was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
74
        }
75
        $path = str_replace('\\', '/', $path === null ? INJI_BASE_DIR . Cache::folder() . "static/bowerLibs/" : $path);
76
        $input = new Symfony\Component\Console\Input\StringInput($command);
0 ignored issues
show
The type Inji\Symfony\Component\Console\Input\StringInput was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
77
        $app = self::getInstance();
78
        chdir($path);
79
        putenv('HOME=' . getcwd());
80
        $app->doRun($input, $output);
81
        $output = null;
0 ignored issues
show
The assignment to $output is dead and can be removed.
Loading history...
82
        $input = null;
0 ignored issues
show
The assignment to $input is dead and can be removed.
Loading history...
83
        chdir(INJI_BASE_DIR);
84
        gc_collect_cycles();
85
        Inji::$inst->unBlockParallel();
86
    }
87
88
    public static function requirePackage($packageName, $version = '', $path = '') {
89
        if (!$path) {
90
            $path = INJI_BASE_DIR . Cache::folder() . "static/bowerLibs/";
91
        }
92
        $bowerJson = json_decode(file_get_contents($path . 'bower.json'), true);
0 ignored issues
show
The assignment to $bowerJson is dead and can be removed.
Loading history...
93
        if (strpos($packageName, 'github') !== false) {
94
            $needPackageName = basename($packageName);
95
        } else {
96
            $needPackageName = $packageName;
97
        }
98
        if (file_exists(Cache::folder() . 'static/bowerLibs/' . $needPackageName)) {
99
            return true;
100
        }
101
        set_time_limit(0);
102
        ini_set('memory_limit', '4000M');
103
        self::command('install ' . $packageName . ($version ? '#' . $version : '') . ' --save', false, $path);
104
        return true;
105
    }
106
}