private function saveToFile()
 {
     if (!$this->isCacheAvailable()) {
         return;
     }
     $data = serialize(array('version' => ToolInfo::getVersion(), 'checkers' => $this->checkers, 'messages' => $this->messages));
     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);
     }
 }
Beispiel #2
0
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());


 $phar = new \Phar($tempFilename);

 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;
}
}
 /**
  * {@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('<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->isEnabled) {
         return;
     }
     $data = serialize(array('version' => ToolInfo::getVersion(), 'fixers' => $this->fixers, 'header' => $this->header, '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);
     }
 }
Beispiel #5
0
 public function testIsInstallAsPhar()
 {
     $this->assertFalse(ToolInfo::isInstalledAsPhar());
 }