Issues (67)

src/Console/Application.php (1 issue)

Severity
1
<?php
2
3
/*
4
 * Pickle
5
 *
6
 *
7
 * @license
8
 *
9
 * New BSD License
10
 *
11
 * Copyright © 2015-2015, Pickle community. All rights reserved.
12
 *
13
 * Redistribution and use in source and binary forms, with or without
14
 * modification, are permitted provided that the following conditions are met:
15
 *     * Redistributions of source code must retain the above copyright
16
 *       notice, this list of conditions and the following disclaimer.
17
 *     * Redistributions in binary form must reproduce the above copyright
18
 *       notice, this list of conditions and the following disclaimer in the
19
 *       documentation and/or other materials provided with the distribution.
20
 *     * Neither the name of the Hoa nor the names of its contributors may be
21
 *       used to endorse or promote products derived from this software without
22
 *       specific prior written permission.
23
 *
24
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
 * POSSIBILITY OF SUCH DAMAGE.
35
 */
36
37
namespace Pickle\Console;
38
39
use Exception;
40
use Phar;
41
use Symfony\Component\Console\Application as BaseApplication;
42
43
class Application extends BaseApplication
44
{
45
    public const NAME = 'pickle';
46
47
    public const VERSION = '@pickle-version@';
48
49
    public function __construct($name = null, $version = null)
50
    {
51
        self::checkExtensions();
52
53
        parent::__construct($name ?: static::NAME, $version ?: (static::VERSION === '@' . 'pickle-version@' ? 'source' : static::VERSION));
0 ignored issues
show
The condition static::VERSION === '@' . 'pickle-version@' is always true.
Loading history...
54
    }
55
56
    protected function getDefaultHelperSet()
57
    {
58
        $helperSet = parent::getDefaultHelperSet();
59
60
        $helperSet->set(new Helper\PackageHelper());
61
62
        return $helperSet;
63
    }
64
65
    protected function getDefaultCommands()
66
    {
67
        $commands = parent::getDefaultCommands();
68
69
        $commands[] = new Command\ValidateCommand();
70
        $commands[] = new Command\ConvertCommand();
71
        $commands[] = new Command\ReleaseCommand();
72
        $commands[] = new Command\InstallerCommand();
73
        $commands[] = new Command\InfoCommand();
74
75
        if (Phar::running() !== '') {
76
            $commands[] = new Command\SelfUpdateCommand();
77
        }
78
79
        return $commands;
80
    }
81
82
    private static function checkExtensions()
83
    {
84
        $required_exts = [
85
            'zlib',
86
            'mbstring',
87
            'simplexml',
88
            'json',
89
            'dom',
90
            'openssl',
91
            'phar',
92
        ];
93
94
        foreach ($required_exts as $ext) {
95
            if (!extension_loaded($ext)) {
96
                throw new Exception("Extension '{$ext}' required but not loaded, full required list: " . implode(', ', $required_exts));
97
            }
98
        }
99
    }
100
}
101