PhpBrew\Config::getInstalledPhpVersions PHP Method

getInstalledPhpVersions() public static method

XXX: This method is now deprecated. use findMatchedBuilds insteads.
Deprecation:
public static getInstalledPhpVersions ( )
    public static function getInstalledPhpVersions()
    {
        $versions = array();
        $path = self::getRoot() . DIRECTORY_SEPARATOR . 'php';
        if (!file_exists($path)) {
            throw new Exception("{$path} doesn't exist.");
        }
        if ($fp = opendir($path)) {
            while (($item = readdir($fp)) !== false) {
                if ($item == '.' || $item == '..') {
                    continue;
                }
                if (file_exists($path . DIRECTORY_SEPARATOR . $item . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'php')) {
                    $versions[] = $item;
                }
            }
            closedir($fp);
        } else {
            throw new Exception('opendir failed');
        }
        rsort($versions);
        return $versions;
    }

Usage Example

Example #1
0
 public function execute()
 {
     $versions = Config::getInstalledPhpVersions();
     $currentVersion = Config::getCurrentPhpName();
     if (empty($versions)) {
         return $this->logger->notice("Please install at least one PHP with your prefered version.");
     }
     if ($currentVersion === false or !in_array($currentVersion, $versions)) {
         $this->logger->writeln("* (system)");
     }
     foreach ($versions as $version) {
         $versionPrefix = Config::getVersionInstallPrefix($version);
         if ($currentVersion == $version) {
             $this->logger->writeln($this->formatter->format(sprintf('* %-15s', $version), 'bold'));
         } else {
             $this->logger->writeln($this->formatter->format(sprintf('  %-15s', $version), 'bold'));
         }
         if ($this->options->dir) {
             $this->logger->writeln(sprintf("    Prefix:   %s", $versionPrefix));
         }
         // TODO: use Build class to get the variants
         if ($this->options->variants && file_exists($versionPrefix . DIRECTORY_SEPARATOR . 'phpbrew.variants')) {
             $info = unserialize(file_get_contents($versionPrefix . DIRECTORY_SEPARATOR . 'phpbrew.variants'));
             echo "    Variants: ";
             echo wordwrap(VariantParser::revealCommandArguments($info), 75, " \\\n              ");
             echo "\n";
         }
     }
 }
All Usage Examples Of PhpBrew\Config::getInstalledPhpVersions