Author: Dariusz Rumiński (dariusz.ruminski@gmail.com)
Esempio n. 1
0
 /**
  * @param ConfigInterface $config
  * @param bool            $isDryRun
  *
  * @return CacheManagerInterface
  */
 private function createCacheManager(ConfigInterface $config, $isDryRun)
 {
     if ($config->usingCache() && (ToolInfo::isInstalledAsPhar() || ToolInfo::isInstalledByComposer())) {
         return new FileCacheManager(new FileHandler($config->getCacheFile()), new Signature(PHP_VERSION, ToolInfo::getVersion(), $config->usingLinter(), $config->getRules()), $isDryRun);
     }
     return new NullCacheManager();
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!ToolInfo::isInstalledAsPhar()) {
         $output->writeln('<error>Self-update is available only for PHAR version.</error>');
         return 1;
     }
     $remoteTag = $this->getLatestTag();
     if (null === $remoteTag) {
         $output->writeln('<error>Unable to determine newest version.</error>');
         return 0;
     }
     $currentVersion = 'v' . $this->getApplication()->getVersion();
     if ($currentVersion === $remoteTag) {
         $output->writeln('<info>php-cs-fixer is already up to date.</info>');
         return 0;
     }
     $remoteVersionParsed = $this->parseVersion($remoteTag);
     $currentVersionParsed = $this->parseVersion($currentVersion);
     if ($remoteVersionParsed[0] > $currentVersionParsed[0] && true !== $input->getOption('force')) {
         $output->writeln(sprintf('<info>A new major version of php-cs-fixer is available</info> (<comment>%s</comment>)', $remoteTag));
         $output->writeln(sprintf('<info>Before upgrading please read</info> https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/%s/UPGRADE.md', $remoteTag));
         $output->writeln('<info>If you are ready to upgrade run this command with</info> <comment>-f</comment>');
         $output->writeln('<info>Checking for new minor/patch version...</info>');
         // test if there is a new minor version available
         $remoteTag = $this->getLatestNotMajorUpdateTag($currentVersion);
         if ($currentVersion === $remoteTag) {
             $output->writeln('<info>no minor update for php-cs-fixer.</info>');
             return 0;
         }
     }
     $remoteFilename = sprintf('https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/%s/php-cs-fixer.phar', $remoteTag);
     $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
     $tempFilename = basename($localFilename, '.phar') . '-tmp.phar';
     try {
         $copyResult = @copy($remoteFilename, $tempFilename);
         if (false === $copyResult) {
             $output->writeln(sprintf('<error>Unable to download new version %s from the server.</error>', $remoteTag));
             return 1;
         }
         chmod($tempFilename, 0777 & ~umask());
         // test the phar validity
         $phar = new \Phar($tempFilename);
         // free the variable to unlock the file
         unset($phar);
         rename($tempFilename, $localFilename);
         $output->writeln(sprintf('<info>php-cs-fixer updated</info> (<comment>%s</comment>)', $remoteTag));
     } catch (\Exception $e) {
         if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) {
             throw $e;
         }
         unlink($tempFilename);
         $output->writeln(sprintf('<error>The download of %s is corrupt (%s).</error>', $remoteTag, $e->getMessage()));
         $output->writeln('<error>Please re-run the self-update command to try again.</error>');
         return 1;
     }
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!ToolInfo::isInstalledAsPhar()) {
         $output->writeln('<error>Self-update is available only for PHAR version.</error>');
         return 1;
     }
     $remoteTag = $this->getRemoteTag();
     if (null === $remoteTag) {
         $output->writeln('<error>Unable to determine newest version.</error>');
         return;
     }
     if ('v' . $this->getApplication()->getVersion() === $remoteTag) {
         $output->writeln('<info>php-cs-fixer is already up to date.</info>');
         return;
     }
     $remoteFilename = $this->buildVersionFileUrl($remoteTag);
     $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
     $tempFilename = basename($localFilename, '.phar') . '-tmp.phar';
     try {
         $copyResult = @copy($remoteFilename, $tempFilename);
         if (false === $copyResult) {
             $output->writeln('<error>Unable to download new versions from the server.</error>');
             return 1;
         }
         chmod($tempFilename, 0777 & ~umask());
         // test the phar validity
         $phar = new \Phar($tempFilename);
         // free the variable to unlock the file
         unset($phar);
         rename($tempFilename, $localFilename);
         $output->writeln(sprintf('<info>php-cs-fixer updated</info> (<comment>%s</comment>)', $remoteTag));
     } catch (\Exception $e) {
         if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) {
             throw $e;
         }
         unlink($tempFilename);
         $output->writeln(sprintf('<error>The download is corrupt (%s).</error>', $e->getMessage()));
         $output->writeln('<error>Please re-run the self-update command to try again.</error>');
         return 1;
     }
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!ToolInfo::isInstalledAsPhar()) {
         $output->writeln('<error>Self-update is available only for PHAR version.</error>');
         return 1;
     }
     if (false !== ($remoteVersion = @file_get_contents('http://get.sensiolabs.org/php-cs-fixer.version'))) {
         if ($this->getApplication()->getVersion() === $remoteVersion) {
             $output->writeln('<info>php-cs-fixer is already up to date.</info>');
             return;
         }
     }
     $remoteFilename = 'http://get.sensiolabs.org/php-cs-fixer.phar';
     $localFilename = $_SERVER['argv'][0];
     $tempFilename = basename($localFilename, '.phar') . '-tmp.phar';
     if (false === @file_get_contents($remoteFilename)) {
         $output->writeln('<error>Unable to download new versions from the server.</error>');
         return 1;
     }
     try {
         copy($remoteFilename, $tempFilename);
         chmod($tempFilename, 0777 & ~umask());
         // test the phar validity
         $phar = new \Phar($tempFilename);
         // free the variable to unlock the file
         unset($phar);
         rename($tempFilename, $localFilename);
         $output->writeln('<info>php-cs-fixer updated.</info>');
     } catch (\Exception $e) {
         if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) {
             throw $e;
         }
         unlink($tempFilename);
         $output->writeln(sprintf('<error>The download is corrupt (%s).</error>', $e->getMessage()));
         $output->writeln('<error>Please re-run the self-update command to try again.</error>');
         return 1;
     }
 }
 private function saveToFile()
 {
     if (!$this->isCacheAvailable()) {
         return;
     }
     $data = serialize(array('version' => ToolInfo::getVersion(), 'rules' => $this->rules, 'hashes' => $this->newHashes));
     if (false === @file_put_contents($this->cacheFile, $data, LOCK_EX)) {
         throw new IOException(sprintf('Failed to write file "%s".', $this->cacheFile), 0, null, $this->cacheFile);
     }
 }
 /**
  * @return CacheManagerInterface
  */
 public function getCacheManager()
 {
     if (null === $this->cacheManager) {
         if ($this->getUsingCache() && (ToolInfo::isInstalledAsPhar() || ToolInfo::isInstalledByComposer())) {
             $this->cacheManager = new FileCacheManager(new FileHandler($this->getCacheFile()), new Signature(PHP_VERSION, ToolInfo::getVersion(), $this->getRules()), $this->isDryRun());
         } else {
             $this->cacheManager = new NullCacheManager();
         }
     }
     return $this->cacheManager;
 }
Esempio n. 7
0
 public function testIsInstallAsPhar()
 {
     $this->assertFalse(ToolInfo::isInstalledAsPhar());
 }