コード例 #1
0
ファイル: Archive.php プロジェクト: gummibeer/backuplay
 /**
  * @return \Alchemy\Zippy\Zippy
  */
 public static function load()
 {
     $zippy = Zippy::load();
     $adapters = AdapterContainer::load();
     $zippy->addStrategy(new ZipExtensionFileStrategy($adapters));
     return $zippy;
 }
コード例 #2
0
 /** @test */
 public function itShouldRegisterAdaptersOnload()
 {
     $container = AdapterContainer::load();
     $this->assertInstanceOf('Alchemy\\Zippy\\Adapter\\ZipAdapter', $container['Alchemy\\Zippy\\Adapter\\ZipAdapter']);
     $this->assertInstanceOf('Alchemy\\Zippy\\Adapter\\GNUTar\\TarGNUTarAdapter', $container['Alchemy\\Zippy\\Adapter\\GNUTar\\TarGNUTarAdapter']);
     $this->assertInstanceOf('Alchemy\\Zippy\\Adapter\\GNUTar\\TarGzGNUTarAdapter', $container['Alchemy\\Zippy\\Adapter\\GNUTar\\TarGzGNUTarAdapter']);
     $this->assertInstanceOf('Alchemy\\Zippy\\Adapter\\GNUTar\\TarBz2GNUTarAdapter', $container['Alchemy\\Zippy\\Adapter\\GNUTar\\TarBz2GNUTarAdapter']);
     $this->assertInstanceOf('Alchemy\\Zippy\\Adapter\\BSDTar\\TarGzBSDTarAdapter', $container['Alchemy\\Zippy\\Adapter\\BSDTar\\TarGzBSDTarAdapter']);
     $this->assertInstanceOf('Alchemy\\Zippy\\Adapter\\BSDTar\\TarBSDTarAdapter', $container['Alchemy\\Zippy\\Adapter\\BSDTar\\TarBSDTarAdapter']);
     $this->assertInstanceOf('Alchemy\\Zippy\\Adapter\\BSDTar\\TarBz2BSDTarAdapter', $container['Alchemy\\Zippy\\Adapter\\BSDTar\\TarBz2BSDTarAdapter']);
 }
コード例 #3
0
 /**
  * @return AdapterInterface
  */
 protected function getAdapter()
 {
     if (false === getenv('ZIPPY_ADAPTER')) {
         throw new \RuntimeException('ZIPPY_ADAPTER environment variable is not set');
     }
     $adapter = 'Alchemy\\Zippy\\Adapter\\' . getenv('ZIPPY_ADAPTER');
     if (!class_exists($adapter)) {
         throw new \InvalidArgumentException(sprintf('class %s does not exist', $adapter));
     }
     $container = AdapterContainer::load();
     $adapter = $container[$adapter];
     if (!$adapter->isSupported()) {
         $this->markTestSkipped(sprintf('Adapter %s is not supported', $adapter->getName()));
     }
     return $adapter;
 }
コード例 #4
0
 /**
  * @param \Drupal\Console\Style\DrupalStyle $io
  * @param $project
  * @param $version
  * @param $type
  * @param $path
  *
  * @return string
  */
 public function downloadProject(DrupalStyle $io, $project, $version, $type, $path = null)
 {
     $commandKey = str_replace(':', '.', $this->getName());
     $io->comment(sprintf($this->trans('commands.' . $commandKey . '.messages.downloading'), $project, $version));
     try {
         $destination = $this->getApplication()->getDrupalApi()->downloadProjectRelease($project, $version);
         if (!$path) {
             $path = $this->getExtractPath($type);
         }
         $drupal = $this->get('site');
         $projectPath = sprintf('%s/%s', $drupal->isValidInstance() ? $drupal->getRoot() : getcwd(), $path);
         if (!file_exists($projectPath)) {
             if (!mkdir($projectPath, 0777, true)) {
                 $io->error($this->trans('commands.' . $commandKey . '.messages.error-creating-folder') . ': ' . $projectPath);
                 return null;
             }
         }
         $zippy = Zippy::load();
         if (PHP_OS === "WIN32" || PHP_OS === "WINNT") {
             $container = AdapterContainer::load();
             $container['Drupal\\Console\\Zippy\\Adapter\\TarGzGNUTarForWindowsAdapter'] = function ($container) {
                 return TarGzGNUTarForWindowsAdapter::newInstance($container['executable-finder'], $container['resource-manager'], $container['gnu-tar.inflator'], $container['gnu-tar.deflator']);
             };
             $zippy->addStrategy(new TarGzFileForWindowsStrategy($container));
         }
         $archive = $zippy->open($destination);
         if ($type == 'core') {
             $archive->extract(getenv('MSYSTEM') ? null : $projectPath);
         } elseif (getenv('MSYSTEM')) {
             $current_dir = getcwd();
             $temp_dir = sys_get_temp_dir();
             chdir($temp_dir);
             $archive->extract();
             $fileSystem = new Filesystem();
             $fileSystem->rename($temp_dir . '/' . $project, $projectPath . '/' . $project);
             chdir($current_dir);
         } else {
             $archive->extract($projectPath);
         }
         unlink($destination);
         if ($type != 'core') {
             $io->success(sprintf($this->trans('commands.' . $commandKey . '.messages.downloaded'), $project, $version, sprintf('%s/%s', $projectPath, $project)));
         }
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return null;
     }
     return $projectPath;
 }
コード例 #5
0
 /**
  * Creates Zippy and loads default strategies
  *
  * @return Zippy
  */
 public static function load()
 {
     $adapters = AdapterContainer::load();
     $factory = new static($adapters);
     $factory->addStrategy(new ZipFileStrategy($adapters));
     $factory->addStrategy(new TarFileStrategy($adapters));
     $factory->addStrategy(new TarGzFileStrategy($adapters));
     $factory->addStrategy(new TarBz2FileStrategy($adapters));
     $factory->addStrategy(new TB2FileStrategy($adapters));
     $factory->addStrategy(new TBz2FileStrategy($adapters));
     $factory->addStrategy(new TGzFileStrategy($adapters));
     return $factory;
 }
コード例 #6
0
 public function __construct()
 {
     $this->container = AdapterContainer::load();
 }