Exakat\Phpexec::isValid PHP Method

isValid() public method

public isValid ( )
    public function isValid()
    {
        if (empty($this->phpexec)) {
            return false;
        }
        $res = shell_exec($this->phpexec . ' -v 2>&1');
        if (preg_match('/PHP ([0-9\\.]+)/', $res, $r)) {
            $this->actualVersion = $r[1];
            if (substr($this->actualVersion, 0, 3) !== $this->requestedVersion) {
                throw new NoPhpBinary('PHP binary for version ' . $this->requestedVersion . ' doesn\'t have the right middle version : "' . $this->actualVersion . '" is provided. Please, check config/exakat.ini');
            }
            return strpos($res, 'The PHP Group') !== false;
        } else {
            return false;
        }
    }

Usage Example

Exemplo n.º 1
0
 private function readProjectConfig($project)
 {
     if (!file_exists($this->projects_root . '/projects/' . $project . '/config.ini')) {
         $this->projectConfig = array();
     } else {
         $this->projectConfig = parse_ini_file($this->projects_root . '/projects/' . $project . '/config.ini');
     }
     // removing empty values in the INI file
     foreach ($this->projectConfig as &$value) {
         if (is_array($value) && empty($value[0])) {
             unset($value[0]);
         }
     }
     unset($value);
     $other_php_versions = array();
     foreach (array('52', '53', '54', '55', '56', '70', '71', '72') as $version) {
         if (empty($this->configFile['php' . $version])) {
             continue;
         }
         $php = new Phpexec($version[0] . '.' . $version[1]);
         if ($php->isValid()) {
             $other_php_versions[] = $version;
         }
     }
     // check and default values
     $defaults = array('ignore_dirs' => array('/test', '/tests', '/Tests', '/Test', '/example', '/examples', '/docs', '/doc', '/tmp', '/version', '/vendor', '/js', '/lang', '/data', '/css', '/cache', '/vendor', '/assets', '/spec', '/sql'), 'other_php_versions' => $other_php_versions, 'phpversion' => PHP_VERSION, 'file_extensions' => array('php', 'php3', 'inc', 'tpl', 'phtml', 'tmpl', 'phps', 'ctp'));
     foreach ($defaults as $name => $value) {
         if (empty($this->projectConfig[$name])) {
             $this->projectConfig[$name] = $value;
         }
     }
     if (is_string($this->projectConfig['other_php_versions'])) {
         $this->projectConfig['other_php_versions'] = explode(',', $this->projectConfig['other_php_versions']);
         foreach ($this->projectConfig['other_php_versions'] as &$version) {
             $version = str_replace('.', '', trim($version));
         }
         unset($version);
     }
     if (is_string($this->projectConfig['file_extensions'])) {
         $this->projectConfig['file_extensions'] = explode(',', $this->projectConfig['file_extensions']);
         foreach ($this->projectConfig['file_extensions'] as &$ext) {
             $ext = trim($ext, '. ');
         }
         unset($ext);
     }
 }