示例#1
0
 protected function extract($file, $path)
 {
     $processError = null;
     // Try to use unrar on *nix
     if (!Platform::isWindows()) {
         $command = 'unrar x ' . ProcessExecutor::escape($file) . ' ' . ProcessExecutor::escape($path) . ' >/dev/null && chmod -R u+w ' . ProcessExecutor::escape($path);
         if (0 === $this->process->execute($command, $ignoredOutput)) {
             return;
         }
         $processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput();
     }
     if (!class_exists('RarArchive')) {
         // php.ini path is added to the error message to help users find the correct file
         $iniMessage = IniHelper::getMessage();
         $error = "Could not decompress the archive, enable the PHP rar extension or install unrar.\n" . $iniMessage . "\n" . $processError;
         if (!Platform::isWindows()) {
             $error = "Could not decompress the archive, enable the PHP rar extension.\n" . $iniMessage;
         }
         throw new \RuntimeException($error);
     }
     $rarArchive = RarArchive::open($file);
     if (false === $rarArchive) {
         throw new \UnexpectedValueException('Could not open RAR archive: ' . $file);
     }
     $entries = $rarArchive->getEntries();
     if (false === $entries) {
         throw new \RuntimeException('Could not retrieve RAR archive entries');
     }
     foreach ($entries as $entry) {
         if (false === $entry->extract($path)) {
             throw new \RuntimeException('Could not extract entry');
         }
     }
     $rarArchive->close();
 }
 private function createExtensionHint()
 {
     $paths = IniHelper::getAll();
     if (count($paths) === 1 && empty($paths[0])) {
         return '';
     }
     $text = "\n  To enable extensions, verify that they are enabled in your .ini files:\n    - ";
     $text .= implode("\n    - ", $paths);
     $text .= "\n  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.";
     return $text;
 }
示例#3
0
    public function testWithoutLoadedIni()
    {
        $paths = array(
            '',
            'one.ini',
            'two.ini',
        );

        $this->setEnv($paths);
        $this->assertContains('does not exist', IniHelper::getMessage());
        $this->assertEquals($paths, IniHelper::getAll());
    }
示例#4
0
 /**
  * {@inheritDoc}
  */
 public function download(PackageInterface $package, $path)
 {
     if (null === self::$hasSystemUnzip) {
         $finder = new ExecutableFinder();
         self::$hasSystemUnzip = (bool) $finder->find('unzip');
     }
     if (!class_exists('ZipArchive') && !self::$hasSystemUnzip) {
         // php.ini path is added to the error message to help users find the correct file
         $iniMessage = IniHelper::getMessage();
         $error = "The zip extension and unzip command are both missing, skipping.\n" . $iniMessage;
         throw new \RuntimeException($error);
     }
     return parent::download($package, $path);
 }
示例#5
0
 private function checkPlatform()
 {
     $output = '';
     $out = function ($msg, $style) use(&$output) {
         $output .= '<' . $style . '>' . $msg . '</' . $style . '>' . PHP_EOL;
     };
     // code below taken from getcomposer.org/installer, any changes should be made there and replicated here
     $errors = array();
     $warnings = array();
     $displayIniMessage = false;
     $iniMessage = PHP_EOL . PHP_EOL . IniHelper::getMessage();
     $iniMessage .= PHP_EOL . 'If you can not modify the ini file, you can also run `php -d option=value` to modify ini values on the fly. You can use -d multiple times.';
     if (!function_exists('json_decode')) {
         $errors['json'] = true;
     }
     if (!extension_loaded('Phar')) {
         $errors['phar'] = true;
     }
     if (!extension_loaded('filter')) {
         $errors['filter'] = true;
     }
     if (!extension_loaded('hash')) {
         $errors['hash'] = true;
     }
     if (!extension_loaded('iconv') && !extension_loaded('mbstring')) {
         $errors['iconv_mbstring'] = true;
     }
     if (!ini_get('allow_url_fopen')) {
         $errors['allow_url_fopen'] = true;
     }
     if (extension_loaded('ionCube Loader') && ioncube_loader_iversion() < 40009) {
         $errors['ioncube'] = ioncube_loader_version();
     }
     if (PHP_VERSION_ID < 50302) {
         $errors['php'] = PHP_VERSION;
     }
     if (!isset($errors['php']) && PHP_VERSION_ID < 50304) {
         $warnings['php'] = PHP_VERSION;
     }
     if (!extension_loaded('openssl')) {
         $errors['openssl'] = true;
     }
     if (extension_loaded('openssl') && OPENSSL_VERSION_NUMBER < 0x1000100f) {
         $warnings['openssl_version'] = true;
     }
     if (!defined('HHVM_VERSION') && !extension_loaded('apcu') && ini_get('apc.enable_cli')) {
         $warnings['apc_cli'] = true;
     }
     if (!extension_loaded('zlib')) {
         $warnings['zlib'] = true;
     }
     ob_start();
     phpinfo(INFO_GENERAL);
     $phpinfo = ob_get_clean();
     if (preg_match('{Configure Command(?: *</td><td class="v">| *=> *)(.*?)(?:</td>|$)}m', $phpinfo, $match)) {
         $configure = $match[1];
         if (false !== strpos($configure, '--enable-sigchild')) {
             $warnings['sigchild'] = true;
         }
         if (false !== strpos($configure, '--with-curlwrappers')) {
             $warnings['curlwrappers'] = true;
         }
     }
     if (ini_get('xdebug.profiler_enabled')) {
         $warnings['xdebug_profile'] = true;
     } elseif (extension_loaded('xdebug')) {
         $warnings['xdebug_loaded'] = true;
     }
     if (!empty($errors)) {
         foreach ($errors as $error => $current) {
             switch ($error) {
                 case 'json':
                     $text = PHP_EOL . "The json extension is missing." . PHP_EOL;
                     $text .= "Install it or recompile php without --disable-json";
                     break;
                 case 'phar':
                     $text = PHP_EOL . "The phar extension is missing." . PHP_EOL;
                     $text .= "Install it or recompile php without --disable-phar";
                     break;
                 case 'filter':
                     $text = PHP_EOL . "The filter extension is missing." . PHP_EOL;
                     $text .= "Install it or recompile php without --disable-filter";
                     break;
                 case 'hash':
                     $text = PHP_EOL . "The hash extension is missing." . PHP_EOL;
                     $text .= "Install it or recompile php without --disable-hash";
                     break;
                 case 'iconv_mbstring':
                     $text = PHP_EOL . "The iconv OR mbstring extension is required and both are missing." . PHP_EOL;
                     $text .= "Install either of them or recompile php without --disable-iconv";
                     break;
                 case 'unicode':
                     $text = PHP_EOL . "The detect_unicode setting must be disabled." . PHP_EOL;
                     $text .= "Add the following to the end of your `php.ini`:" . PHP_EOL;
                     $text .= "    detect_unicode = Off";
                     $displayIniMessage = true;
                     break;
                 case 'suhosin':
                     $text = PHP_EOL . "The suhosin.executor.include.whitelist setting is incorrect." . PHP_EOL;
                     $text .= "Add the following to the end of your `php.ini` or suhosin.ini (Example path [for Debian]: /etc/php5/cli/conf.d/suhosin.ini):" . PHP_EOL;
                     $text .= "    suhosin.executor.include.whitelist = phar " . $current;
                     $displayIniMessage = true;
                     break;
                 case 'php':
                     $text = PHP_EOL . "Your PHP ({$current}) is too old, you must upgrade to PHP 5.3.2 or higher.";
                     break;
                 case 'allow_url_fopen':
                     $text = PHP_EOL . "The allow_url_fopen setting is incorrect." . PHP_EOL;
                     $text .= "Add the following to the end of your `php.ini`:" . PHP_EOL;
                     $text .= "    allow_url_fopen = On";
                     $displayIniMessage = true;
                     break;
                 case 'ioncube':
                     $text = PHP_EOL . "Your ionCube Loader extension ({$current}) is incompatible with Phar files." . PHP_EOL;
                     $text .= "Upgrade to ionCube 4.0.9 or higher or remove this line (path may be different) from your `php.ini` to disable it:" . PHP_EOL;
                     $text .= "    zend_extension = /usr/lib/php5/20090626+lfs/ioncube_loader_lin_5.3.so";
                     $displayIniMessage = true;
                     break;
                 case 'openssl':
                     $text = PHP_EOL . "The openssl extension is missing, which means that secure HTTPS transfers are impossible." . PHP_EOL;
                     $text .= "If possible you should enable it or recompile php with --with-openssl";
                     break;
             }
             $out($text, 'error');
         }
         $output .= PHP_EOL;
     }
     if (!empty($warnings)) {
         foreach ($warnings as $warning => $current) {
             switch ($warning) {
                 case 'apc_cli':
                     $text = "The apc.enable_cli setting is incorrect." . PHP_EOL;
                     $text .= "Add the following to the end of your `php.ini`:" . PHP_EOL;
                     $text .= "  apc.enable_cli = Off";
                     $displayIniMessage = true;
                     break;
                 case 'zlib':
                     $text = 'The zlib extension is not loaded, this can slow down Composer a lot.' . PHP_EOL;
                     $text .= 'If possible, enable it or recompile php with --with-zlib' . PHP_EOL;
                     $displayIniMessage = true;
                     break;
                 case 'sigchild':
                     $text = "PHP was compiled with --enable-sigchild which can cause issues on some platforms." . PHP_EOL;
                     $text .= "Recompile it without this flag if possible, see also:" . PHP_EOL;
                     $text .= "  https://bugs.php.net/bug.php?id=22999";
                     break;
                 case 'curlwrappers':
                     $text = "PHP was compiled with --with-curlwrappers which will cause issues with HTTP authentication and GitHub." . PHP_EOL;
                     $text .= " Recompile it without this flag if possible";
                     break;
                 case 'php':
                     $text = "Your PHP ({$current}) is quite old, upgrading to PHP 5.3.4 or higher is recommended." . PHP_EOL;
                     $text .= " Composer works with 5.3.2+ for most people, but there might be edge case issues.";
                     break;
                 case 'openssl_version':
                     // Attempt to parse version number out, fallback to whole string value.
                     $opensslVersion = strstr(trim(strstr(OPENSSL_VERSION_TEXT, ' ')), ' ', true);
                     $opensslVersion = $opensslVersion ?: OPENSSL_VERSION_TEXT;
                     $text = "The OpenSSL library ({$opensslVersion}) used by PHP does not support TLSv1.2 or TLSv1.1." . PHP_EOL;
                     $text .= "If possible you should upgrade OpenSSL to version 1.0.1 or above.";
                     break;
                 case 'xdebug_loaded':
                     $text = "The xdebug extension is loaded, this can slow down Composer a little." . PHP_EOL;
                     $text .= " Disabling it when using Composer is recommended.";
                     break;
                 case 'xdebug_profile':
                     $text = "The xdebug.profiler_enabled setting is enabled, this can slow down Composer a lot." . PHP_EOL;
                     $text .= "Add the following to the end of your `php.ini` to disable it:" . PHP_EOL;
                     $text .= "  xdebug.profiler_enabled = 0";
                     $displayIniMessage = true;
                     break;
             }
             $out($text, 'comment');
         }
     }
     if ($displayIniMessage) {
         $out($iniMessage, 'comment');
     }
     return !$warnings && !$errors ? true : $output;
 }
示例#6
0
 /**
  * Returns true if everything was written for the restart
  *
  * If any of the following fails (however unlikely) we must return false to
  * stop potential recursion:
  *   - tmp ini file creation
  *   - environment variable creation
  *
  * @param null|string $command The command to run, set by method
  *
  * @return bool
  */
 private function prepareRestart(&$command)
 {
     $this->tmpIni = '';
     $iniPaths = IniHelper::getAll();
     $files = $this->getWorkingSet($iniPaths, $replace);
     if ($this->writeTmpIni($files, $replace)) {
         $command = $this->getCommand();
         return $this->setEnvironment($iniPaths);
     }
     return false;
 }