Exakat\Phpexec::__construct PHP 메소드

__construct() 공개 메소드

public __construct ( $phpversion = null )
    public function __construct($phpversion = null)
    {
        $config = Config::factory();
        if ($phpversion === null) {
            $phpversion = $config->phpversion;
        }
        $this->requestedVersion = substr($phpversion, 0, 3);
        $this->version = $phpversion;
        $phpversion3 = substr($phpversion, 0, 3);
        $this->isCurrentVersion = substr(PHP_VERSION, 0, 3) === $phpversion3;
        if ($this->isCurrentVersion === true) {
            preg_match('/^(\\d\\.\\d+\\.\\d+)$/', PHP_VERSION, $r);
            $this->actualVersion = $r[1];
            if (substr($this->actualVersion, 0, 3) !== $this->requestedVersion) {
                throw new NoPhpBinary('PHP binary for version ' . $this->requestedVersion . ' (' . $_SERVER['_'] . ') doesn\'t have the right middle version : "' . $this->actualVersion . '". Please, check config/exakat.ini');
            }
        }
        switch ($phpversion3) {
            case '5.2':
                $this->phpexec = $config->php52;
                break 1;
            case '5.3':
                $this->phpexec = $config->php53;
                break 1;
            case '5.4':
                $this->phpexec = $config->php54;
                break 1;
            case '5.5':
                $this->phpexec = $config->php55;
                break 1;
            case '5.6':
                $this->phpexec = $config->php56;
                break 1;
            case '7.0':
                $this->phpexec = $config->php70;
                break 1;
            case '7.1':
                $this->phpexec = $config->php71;
                break 1;
            case '7.2':
                $this->phpexec = $config->php72;
                break 1;
            default:
                $this->phpexec = $config->php;
                // PHP will be always valid if we use the one that is currently executing us
                $this->actualVersion = PHP_VERSION;
        }
        if (preg_match('/^php:(.+?)$/', $this->phpexec)) {
            $folder = $config->projects_root;
            $res = shell_exec('docker run -it --rm --name php4exakat -v "$PWD":' . $folder . ' -w ' . $folder . ' ' . $this->phpexec . ' php -v 2>&1');
            if (substr($res, 0, 4) !== 'PHP ') {
                throw new NoPhpBinary('Error when accessing Docker\'s PHP : "' . $res . '". Please, check config/exakat.ini');
            } else {
                $this->phpexec = 'docker run -it --rm --name php4exakat -v "$PWD":' . $folder . ' -w ' . $folder . ' ' . $this->phpexec . ' php ';
            }
        } else {
            if (empty($this->phpexec)) {
                throw new NoPhpBinary('No PHP binary for version ' . $phpversion . ' is available. Please, check config/exakat.ini');
            }
            if (!file_exists($this->phpexec)) {
                throw new NoPhpBinary('PHP binary for version ' . $phpversion . ' is not valid : "' . $this->phpexec . '". Please, check config/exkat.ini');
            }
            if (!is_executable($this->phpexec)) {
                throw new NoPhpBinary('PHP binary for version ' . $phpversion . ' exists but is not executable : "' . $this->phpexec . '". Please, check config/exakat.ini');
            }
        }
    }