public function selfUpdate($phar)
 {
     if (!defined('COMACO_FILE')) {
         throw new \RuntimeException('Own filename is not provided, do you run update from phar?');
     }
     $filesystem = new Filesystem(new LocalAdapter(getcwd()));
     $file = $filesystem->getFile(COMACO_FILE);
     if (!$file->exists()) {
         throw new \RuntimeException('Could not find own file in filesystem, are you running phar from current working directory?');
     }
     if (!$file->isWritable()) {
         throw new \RuntimeException(COMACO_FILE . ' is not writeable!');
     }
     $tempDir = sys_get_temp_dir();
     $tempFilesystem = new Filesystem(new LocalAdapter($tempDir));
     $root = $tempFilesystem->getRoot();
     if (!$root->isWritable()) {
         throw new \RuntimeException('Temporary directory is not writeable!');
     }
     $tempFileIndex = 0;
     do {
         $tempFile = $tempFilesystem->getFile('/comaco' . ($tempFileIndex > 0 ? '_' . $tempFileIndex : '') . '.phar');
         $tempFileIndex++;
     } while ($tempFile->exists());
     $phar = base64_decode($phar);
     $tempFile->setContents($phar);
     // test the archive
     $realPath = $tempDir . '/' . $tempFile->getBasename();
     new \Phar($realPath);
     $tempFile->moveTo($file, File::OPERATION_REPLACE);
     return $file->getMD5();
 }
 protected function getContaoVersion()
 {
     if ($this->prepareFilesystemAccess()) {
         /* ***** Read constants like VERSION, BUILD and LONG_TERM_SUPPORT ******************************************* */
         /* Contao 3+ */
         $constantsFile = $this->contaoInstallation->getFile('system/config/constants.php');
         /* Contao 2+ */
         if (!$constantsFile->exists()) {
             $constantsFile = $this->contaoInstallation->getFile('system/constants.php');
         }
         if ($constantsFile->exists()) {
             $constants = $constantsFile->getContents();
             $version = '';
             $build = '';
             if (preg_match('#define\\(\\s*["\']VERSION["\']\\s*,\\s*["\']([^"\']+)["\']\\s*\\)#', $constants, $match)) {
                 $version = $match[1];
             }
             if (preg_match('#define\\(\\s*["\']BUILD["\']\\s*,\\s*["\']([^"\']+)["\']\\s*\\)#', $constants, $match)) {
                 $build = $match[1];
             }
             if ($version && $build) {
                 return $version . '.' . $build;
             }
         }
     }
     return null;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!defined('COMACO_FILE')) {
         throw new \RuntimeException('Own filename is not provided, do you run update from phar?');
     }
     $filesystem = new Filesystem(new LocalAdapter(getcwd()));
     $file = $filesystem->getFile(COMACO_FILE);
     if (!$file->exists()) {
         throw new \RuntimeException('Could not find own file in filesystem, are you running phar from current working directory?');
     }
     $phar = $file->getContents();
     $phar = base64_encode($phar);
     $settings = $this->createSettings($input);
     $endpoint = $this->createEndpoint($settings);
     $result = $endpoint->selfUpdate($phar);
     $output->writeln('  <info>*</info> Updated remote hash ' . $result);
 }
Ejemplo n.º 4
0
 /**
  * Search for the filesystem and open a file from stream url.
  *
  * @param string $url
  *
  * @return \Filicious\File
  */
 protected function openFile($url)
 {
     $this->url = (object) array_merge(array('scheme' => 'filicious', 'host' => '', 'port' => '', 'user' => '', 'pass' => '', 'path' => '', 'query' => '', 'fragment' => ''), parse_url($url));
     if ($this->url->scheme == 'filicious-streams') {
         $stream = StreamManager::searchStream($this->url->host);
         if (!$stream) {
             throw new \InvalidArgumentException();
             // TODO
         }
         $this->file = $stream->getFile();
         $this->stream = $stream;
         return $this->file;
     }
     $host = $this->url->host;
     if (strlen($this->url->port)) {
         $host .= ':' . $this->url->port;
     }
     // search the filesystem bound to the scheme+host
     $this->fs = StreamManager::searchFilesystem($host, $this->url->scheme);
     // get the file from the filesystem
     $this->file = $this->fs->getFile($this->url->path);
     return $this->file;
 }
 protected function addDependencies(File $composerJsonFile, &$addedDependencies = array())
 {
     $composerJson = $composerJsonFile->getContents();
     $composerConfig = json_decode($composerJson);
     if (isset($composerConfig->require)) {
         foreach ($composerConfig->require as $packageName => $packageConstraint) {
             if ($packageName == 'php' || in_array($packageName, $addedDependencies)) {
                 continue;
             }
             $addedDependencies[] = $packageName;
             $packageDir = $this->filesystem->getFile($this->vendorDir . '/' . $packageName);
             if ($packageDir->isDirectory()) {
                 $this->addFilesFrom($packageDir, 'vendor/' . $packageName);
             } else {
                 $this->output->writeln(' <comment>*</comment> Package ' . $packageName . ' does not exist in ' . $packageDir->getPathname());
             }
             $composerJsonFile = $this->filesystem->getFile($this->vendorDir . '/' . $packageName . '/composer.json');
             if ($composerJsonFile->exists()) {
                 $this->addDependencies($composerJsonFile, $addedDependencies);
             }
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * Return a plugin for the filesystem.
  *
  * @param string $name
  *
  * @return FilePluginInterface|null
  *
  * @api
  */
 public function getPlugin($name)
 {
     $pluginManager = $this->filesystem->getPluginManager();
     if ($pluginManager && $pluginManager->hasPlugin($name)) {
         $plugin = $pluginManager->getPlugin($name);
         if ($plugin->providesFilePlugin($this)) {
             return $plugin->getFilePlugin($this);
         }
     }
     return null;
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function setFilesystem(Filesystem $filesystem = null)
 {
     $this->filesystem = $filesystem;
     $this->root = $filesystem->getRootAdapter();
     return $this;
 }