PhpBrew\Utils::findLatestPhpVersion PHP Method

findLatestPhpVersion() public static method

public static findLatestPhpVersion ( $version = null )
    public static function findLatestPhpVersion($version = null)
    {
        $foundVersion = false;
        $buildDir = Config::getBuildDir();
        $hasPrefix = self::startsWith($version, 'php-');
        if (is_dir($buildDir)) {
            if ($hasPrefix == true) {
                $version = str_replace('php-', '', $version);
            }
            $fp = opendir($buildDir);
            if ($fp !== false) {
                while ($file = readdir($fp)) {
                    if ($file === '.' || $file === '..' || is_file($buildDir . DIRECTORY_SEPARATOR . $file)) {
                        continue;
                    }
                    $curVersion = strtolower(preg_replace('/^[\\D]*-/', '', $file));
                    if (self::startsWith($curVersion, $version) && version_compare($curVersion, $foundVersion, '>=')) {
                        $foundVersion = $curVersion;
                        if (version_compare($foundVersion, $version, '=')) {
                            break;
                        }
                    }
                }
                closedir($fp);
            }
            if ($hasPrefix == true && $foundVersion !== false) {
                $foundVersion = 'php-' . $foundVersion;
            }
        }
        return $foundVersion;
    }

Usage Example

Beispiel #1
0
 public function execute($extName, $version = 'stable')
 {
     $logger = $this->getLogger();
     $extensions = array();
     if (Utils::startsWith($extName, '+')) {
         $config = Config::getConfigParam('extensions');
         $extName = ltrim($extName, '+');
         if (isset($config[$extName])) {
             foreach ($config[$extName] as $extensionName => $extOptions) {
                 $args = explode(' ', $extOptions);
                 $extensions[$extensionName] = $this->getExtData($args);
             }
         } else {
             $logger->info('Extension set name not found. Have you configured it at the config.yaml file?');
         }
     } else {
         $args = array_slice(func_get_args(), 1);
         $extensions[$extName] = $this->getExtData($args);
     }
     if ($this->options->{'php-version'} !== null) {
         $phpVersion = Utils::findLatestPhpVersion($this->options->{'php-version'});
         Config::setPhpVersion($phpVersion);
     }
     foreach ($extensions as $extensionName => $extData) {
         $extension = new Extension($extensionName, $logger);
         $extension->install($extData->version, $extData->options);
     }
     Config::useSystemPhpVersion();
 }
All Usage Examples Of PhpBrew\Utils::findLatestPhpVersion