getCurrentPhpName() публичный статический Метод

getCurrentPhpName return the current php version from self::$currentPhpVersion or from environment variable PHPBREW_PHP.
public static getCurrentPhpName ( ) : string
Результат string
Пример #1
0
 public function execute()
 {
     $root = Config::getPhpbrewRoot();
     $php = Config::getCurrentPhpName();
     $file = "{$root}/php/{$php}/etc/php.ini";
     Utils::editor($file);
 }
Пример #2
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";
         }
     }
 }
Пример #3
0
 public function arguments($args)
 {
     $args->add('extensions')->suggestions(function () {
         $extdir = Config::getBuildDir() . '/' . Config::getCurrentPhpName() . '/ext';
         return array_filter(scandir($extdir), function ($d) use($extdir) {
             return $d != '.' && $d != '..' && is_dir($extdir . DIRECTORY_SEPARATOR . $d);
         });
     });
 }
Пример #4
0
 public function execute()
 {
     $file = php_ini_loaded_file();
     if (!file_exists($file)) {
         $php = Config::getCurrentPhpName();
         $this->logger->warn("Sorry, I can't find the {$file} file for php {$php}.");
         return;
     }
     Utils::editor($file);
 }
Пример #5
0
 public function purgeExtension(Extension $ext)
 {
     if ($sourceDir = $ext->getSourceDirectory()) {
         $currentPhpExtensionDirectory = Config::getBuildDir() . '/' . Config::getCurrentPhpName() . '/ext';
         $extName = $ext->getExtensionName();
         $extensionDir = $currentPhpExtensionDirectory . DIRECTORY_SEPARATOR . $extName;
         if (file_exists($extensionDir)) {
             Utils::system("rm -rvf {$extensionDir}");
         }
     }
 }
Пример #6
0
 public function execute()
 {
     if ($this->options->{'php'} !== null) {
         $php = Utils::findLatestPhpVersion($this->options->{'php'});
     } else {
         $php = Config::getCurrentPhpName();
     }
     $buildDir = Config::getBuildDir();
     $extDir = $buildDir . DIRECTORY_SEPARATOR . $php . DIRECTORY_SEPARATOR . 'ext';
     // listing all local extensions
     if (version_compare('php-' . phpversion(), $php, '==')) {
         $loaded = array_map('strtolower', get_loaded_extensions());
     } else {
         $this->logger->info('PHP version is different from current active version.');
         $this->logger->info('Only available extensions are listed.');
         $this->logger->info('You will not see which of them are loaded.');
         $loaded = array();
     }
     // list for extensions which are not enabled
     $extensions = array();
     if (is_dir($extDir)) {
         $fp = opendir($extDir);
         if ($fp !== false) {
             while ($file = readdir($fp)) {
                 if ($file === '.' || $file === '..') {
                     continue;
                 }
                 if (is_file($extDir . '/' . $file)) {
                     continue;
                 }
                 $n = strtolower(preg_replace('#-[\\d\\.]+$#', '', $file));
                 if (in_array($n, $loaded)) {
                     continue;
                 }
                 $extensions[] = $n;
             }
             sort($loaded);
             sort($extensions);
             closedir($fp);
         }
     }
     $this->logger->info('Loaded extensions:');
     foreach ($loaded as $ext) {
         $this->logger->info("  [*] {$ext}");
     }
     $this->logger->info('Available extensions:');
     foreach ($extensions as $ext) {
         $this->logger->info("  [ ] {$ext}");
     }
 }
Пример #7
0
 public function renameSourceDirectory(Extension $ext)
 {
     $currentPhpExtensionDirectory = Config::getBuildDir() . '/' . Config::getCurrentPhpName() . '/ext';
     $extName = $ext->getExtensionName();
     $name = $ext->getName();
     $extensionDir = $currentPhpExtensionDirectory . DIRECTORY_SEPARATOR . $extName;
     $extensionExtractDir = $currentPhpExtensionDirectory . DIRECTORY_SEPARATOR . $name;
     if ($name != $extName) {
         $this->logger->info("===> Rename source directory to {$extensionDir}...");
         $cmds = array("rm -rf {$extensionDir}", "mv {$extensionExtractDir} {$extensionDir}");
         foreach ($cmds as $cmd) {
             $this->logger->debug($cmd);
             Utils::system($cmd);
         }
         // replace source directory to new source directory
         $sourceDir = str_replace($extensionExtractDir, $extensionDir, $ext->getSourceDirectory());
         $ext->setSourceDirectory($sourceDir);
         $ext->setName($extName);
     }
 }
Пример #8
0
 public function execute($name)
 {
     switch ($name) {
         case 'home':
             echo Config::getPhpbrewRoot();
             break;
         case 'build':
             echo Config::getBuildDir();
             break;
         case 'bin':
             echo Config::getCurrentPhpBin();
             break;
         case 'include':
             echo Config::getVersionBuildPrefix(Config::getCurrentPhpName()) . DIRECTORY_SEPARATOR . 'include';
             break;
         case 'etc':
             echo Config::getVersionBuildPrefix(Config::getCurrentPhpName()) . DIRECTORY_SEPARATOR . 'etc';
             break;
     }
 }
Пример #9
0
 public function execute()
 {
     $versions = Config::getInstalledPhpVersions();
     $currentVersion = Config::getCurrentPhpName();
     // var_dump( $versions );
     echo "Installed versions:\n";
     if ($currentVersion === false or in_array($currentVersion, $versions) === false) {
         echo "* (system)\n";
     }
     foreach ($versions as $version) {
         $versionPrefix = Config::getVersionBuildPrefix($version);
         printf('  %-15s  (%-10s)', $version, $versionPrefix);
         if (file_exists($versionPrefix . DIRECTORY_SEPARATOR . 'phpbrew.variants')) {
             $info = unserialize(file_get_contents($versionPrefix . DIRECTORY_SEPARATOR . 'phpbrew.variants'));
             echo "\n";
             echo str_repeat(' ', 19);
             echo VariantParser::revealCommandArguments($info);
         }
         echo "\n";
     }
 }
Пример #10
0
 public function setup($options)
 {
     $phpConfigFile = $options->production ? 'php.ini-production' : 'php.ini-development';
     $this->logger->info("---> Copying config file for " . $options->production ? 'production' : 'development');
     if (file_exists($phpConfigFile)) {
         $this->logger->info("Found config file: {$phpConfigFile}");
         $version = Config::getCurrentPhpName();
         if (!file_exists(Config::getVersionEtcPath($version))) {
             $dir = Config::getVersionEtcPath($version);
             $this->logger->debug("Creating config directory");
             mkdir($dir, 0755, true);
         }
         $targetConfigPath = Config::getVersionEtcPath($version) . DIRECTORY_SEPARATOR . 'php.ini';
         if (file_exists($targetConfigPath)) {
             $this->logger->notice("{$targetConfigPath} exists, do not overwrite.");
         } else {
             // TODO: Move this to PhpConfigPatchTask
             // move config file to target location
             copy($phpConfigFile, $targetConfigPath);
             // replace current timezone
             $timezone = ini_get('date.timezone');
             $pharReadonly = ini_get('phar.readonly');
             if ($timezone || $pharReadonly) {
                 // patch default config
                 $content = file_get_contents($targetConfigPath);
                 if ($timezone) {
                     $this->logger->info("---> Found date.timezone, patch config timezone with {$timezone}");
                     $content = preg_replace('/^date.timezone\\s*=\\s*.*/im', "date.timezone = {$timezone}", $content);
                 }
                 if (!$pharReadonly) {
                     $this->logger->info("---> Disable phar.readonly option.");
                     $content = preg_replace('/^phar.readonly\\s*=\\s*.*/im', "phar.readonly = 0", $content);
                 }
                 file_put_contents($targetConfigPath, $content);
             }
         }
     }
 }
Пример #11
0
 public function execute($name)
 {
     switch ($name) {
         case 'root':
             echo Config::getRoot();
             break;
         case 'home':
             echo Config::getHome();
             break;
         case 'config-scan':
             echo Config::getCurrentPhpConfigScanPath();
             break;
         case 'dist':
             echo Config::getDistFileDir();
             break;
         case 'build':
             echo Config::getCurrentBuildDir();
             break;
         case 'bin':
             echo Config::getCurrentPhpBin();
             break;
         case 'include':
             echo Config::getVersionInstallPrefix(Config::getCurrentPhpName()) . DIRECTORY_SEPARATOR . 'include';
             break;
         case 'extension-src':
         case 'ext-src':
             echo Config::getCurrentBuildDir() . DIRECTORY_SEPARATOR . 'ext';
             break;
         case 'extension-dir':
         case 'ext-dir':
         case 'ext':
             echo ini_get('extension_dir');
             break;
         case 'etc':
             echo Config::getVersionInstallPrefix(Config::getCurrentPhpName()) . DIRECTORY_SEPARATOR . 'etc';
             break;
     }
 }
Пример #12
0
 public function buildMetaFromName($name)
 {
     $path = Config::getBuildDir() . '/' . Config::getCurrentPhpName() . '/ext/' . $name;
     $xml = $path . '/package.xml';
     $m4 = $path . '/config.m4';
     if (file_exists($xml)) {
         $this->logger->warning("===> Using xml extension meta");
         $meta = new ExtensionMetaXml($xml);
     } elseif (file_exists($m4)) {
         $this->logger->warning("===> Using m4 extension meta");
         $meta = new ExtensionMetaM4($m4);
     } else {
         $this->logger->warning("===> Using polyfill extension meta");
         $meta = new ExtensionMetaPolyfill($name);
     }
     return $meta;
 }
Пример #13
0
 public static function lookup($packageName, array $lookupDirectories = array(), $fallback = true)
 {
     if ($fallback) {
         // Always push the PHP source directory to the end of the list for the fallback.
         $lookupDirectories[] = Config::getBuildDir() . '/' . Config::getCurrentPhpName() . '/ext';
     }
     foreach ($lookupDirectories as $lookupDir) {
         if (!file_exists($lookupDir)) {
             continue;
         }
         $extensionDir = $lookupDir . DIRECTORY_SEPARATOR . $packageName;
         if ($ext = self::createFromDirectory($packageName, $extensionDir)) {
             return $ext;
         }
     }
     return new Extension($packageName);
 }
Пример #14
0
 public function execute($extName, $version = 'stable')
 {
     if ((preg_match('#^git://#', $extName) || preg_match('#\\.git$#', $extName)) && !preg_match("#github|bitbucket#", $extName)) {
         $pathinfo = pathinfo($extName);
         $repoUrl = $extName;
         $extName = $pathinfo['filename'];
         $extDir = Config::getBuildDir() . DIRECTORY_SEPARATOR . Config::getCurrentPhpName() . DIRECTORY_SEPARATOR . 'ext' . DIRECTORY_SEPARATOR . $extName;
         if (!file_exists($extDir)) {
             passthru("git clone {$repoUrl} {$extDir}", $ret);
             if ($ret != 0) {
                 return $this->logger->error('Clone failed.');
             }
         }
     }
     $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->getExtConfig($args);
             }
         } else {
             $this->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->getExtConfig($args);
     }
     $extensionList = new ExtensionList();
     $manager = new ExtensionManager($this->logger);
     foreach ($extensions as $extensionName => $extConfig) {
         $provider = $extensionList->exists($extensionName);
         if (!$provider) {
             throw new Exception("Could not find provider for {$extensionName}.");
         }
         $extensionName = $provider->getPackageName();
         $ext = ExtensionFactory::lookupRecursive($extensionName);
         $always_redownload = $this->options->{'pecl'} || $this->options->{'redownload'} || !$provider->isBundled($extensionName);
         // Extension not found, use pecl to download it.
         if (!$ext || $always_redownload) {
             // not every project has stable branch, using master as default version
             $args = array_slice(func_get_args(), 1);
             if (!isset($args[0]) || $args[0] != $extConfig->version) {
                 $extConfig->version = $provider->getDefaultVersion();
             }
             $extensionDownloader = new ExtensionDownloader($this->logger, $this->options);
             $extensionDownloader->download($provider, $extConfig->version);
             // Reload the extension
             if ($provider->shouldLookupRecursive()) {
                 $ext = ExtensionFactory::lookupRecursive($extensionName);
             } else {
                 $ext = ExtensionFactory::lookup($extensionName);
             }
             if ($ext) {
                 $extensionDownloader->renameSourceDirectory($ext);
             }
         }
         if (!$ext) {
             throw new Exception("{$extensionName} not found.");
         }
         $manager->installExtension($ext, $extConfig->options);
     }
 }
Пример #15
0
 public function execute($buildName = null)
 {
     if (!$buildName) {
         $buildName = Config::getCurrentPhpName();
     }
     if (!$buildName) {
         throw new Exception("PHPBREW_PHP is not set. You should provide the build name in the command.");
     }
     fprintf(STDERR, "*WARNING* php-fpm --pid option requires php >= 5.6, you need to update your php-fpm.conf for the pid file location.\n");
     $root = Config::getRoot();
     $fpmBin = "{$root}/php/{$buildName}/sbin/php-fpm";
     if (!file_exists($fpmBin)) {
         throw new Exception("{$fpmBin} doesn't exist.");
     }
     // TODO: require sudo permission
     if ($this->options->systemctl) {
         $content = $this->generateSystemctlService($buildName, $fpmBin);
         if ($this->options->stdout) {
             echo $content;
             return;
         }
         $file = '/lib/systemd/system/phpbrew-fpm.service';
         if (!is_writable(dirname($file))) {
             $this->logger->error("{$file} is not writable.");
             return;
         }
         $this->logger->info("Writing systemctl service entry: {$file}");
         file_put_contents($file, $content);
         $this->logger->info("To reload systemctl service:");
         $this->logger->info("    systemctl daemon-reload");
         $this->logger->info("Ensure that {$buildName} was built with --fpm-systemd option");
     } elseif ($this->options->initd) {
         $content = $this->generateInitD($buildName, $fpmBin);
         if ($this->options->stdout) {
             echo $content;
             return;
         }
         $file = '/etc/init.d/phpbrew-fpm';
         if (!is_writable(dirname($file))) {
             $this->logger->error("{$file} is not writable.");
             return;
         }
         $this->logger->info("Writing init.d script: {$file}");
         file_put_contents($file, $content);
         chmod($file, 0755);
         // make it executable
         $this->logger->info("To setup the startup item, remember to run update-rc.d to link the init script:");
         $this->logger->info("    sudo update-rc.d phpbrew-fpm defaults");
     } elseif ($this->options->launchctl) {
         $content = $this->generateLaunchctlService($buildName, $fpmBin);
         if ($this->options->stdout) {
             echo $content;
             return;
         }
         $file = '/Library/LaunchDaemons/org.phpbrew.fpm.plist';
         if (!is_writable(dirname($file))) {
             $this->logger->error("{$file} is not writable.");
             return;
         }
         $this->logger->info("Writing launchctl plist file: {$file}");
         file_put_contents($file, $content);
         $this->logger->info("To load the service:");
         $this->logger->info("    sudo launchctl load {$file}");
     } else {
         $this->logger->info('Please use one of the options [--systemctl, --initd, --launchctl] to setup system fpm service.');
     }
 }
Пример #16
0
 public function execute($extName, $version = 'stable')
 {
     if (version_compare(PHP_VERSION, '7.0.0') > 0) {
         $this->logger->warn("Warning: Some extension won't be able to be built with php7. If the extension\nsupports php7 in another branch or new major version, you will need to specify\nthe branch name or version name explicitly.\n\nFor example, to install memcached extension for php7, use:\n\n    phpbrew ext install github:php-memcached-dev/php-memcached php7 -- --disable-memcached-sasl\n");
     }
     if (strtolower($extName) === 'apc' && version_compare(PHP_VERSION, '5.6.0') > 0) {
         $this->logger->warn('apc is not compatible with php 5.6+ versions, install apcu instead.');
     }
     // Detect protocol
     if ((preg_match('#^git://#', $extName) || preg_match('#\\.git$#', $extName)) && !preg_match('#github|bitbucket#', $extName)) {
         $pathinfo = pathinfo($extName);
         $repoUrl = $extName;
         $extName = $pathinfo['filename'];
         $extDir = Config::getBuildDir() . DIRECTORY_SEPARATOR . Config::getCurrentPhpName() . DIRECTORY_SEPARATOR . 'ext' . DIRECTORY_SEPARATOR . $extName;
         if (!file_exists($extDir)) {
             passthru("git clone {$repoUrl} {$extDir}", $ret);
             if ($ret != 0) {
                 return $this->logger->error('Clone failed.');
             }
         }
     }
     // Expand extensionset from config
     $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->getExtConfig($args);
             }
         } else {
             $this->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->getExtConfig($args);
     }
     $extensionList = new ExtensionList($this->logger, $this->options);
     $manager = new ExtensionManager($this->logger);
     foreach ($extensions as $extensionName => $extConfig) {
         $provider = $extensionList->exists($extensionName);
         if (!$provider) {
             throw new Exception("Could not find provider for {$extensionName}.");
         }
         $extensionName = $provider->getPackageName();
         $ext = ExtensionFactory::lookupRecursive($extensionName);
         $always_redownload = $this->options->{'pecl'} || $this->options->{'redownload'} || !$provider->isBundled($extensionName);
         // Extension not found, use pecl to download it.
         if (!$ext || $always_redownload) {
             // not every project has stable branch, using master as default version
             $args = array_slice(func_get_args(), 1);
             if (!isset($args[0]) || $args[0] != $extConfig->version) {
                 $extConfig->version = $provider->getDefaultVersion();
             }
             $extensionDownloader = new ExtensionDownloader($this->logger, $this->options);
             $extensionDownloader->download($provider, $extConfig->version);
             // Reload the extension
             if ($provider->shouldLookupRecursive()) {
                 $ext = ExtensionFactory::lookupRecursive($extensionName);
             } else {
                 $ext = ExtensionFactory::lookup($extensionName);
             }
             if ($ext) {
                 $extensionDownloader->renameSourceDirectory($ext);
             }
         }
         if (!$ext) {
             throw new Exception("{$extensionName} not found.");
         }
         $manager->installExtension($ext, $extConfig->options);
     }
 }