public function setUp()
 {
     $this->workspace = $this->getTempDir('package_installer_');
     $loader = new JsonLoader();
     if (!($this->package = $loader->load(__DIR__ . '/../Fixtures/Package/extension.json'))) {
         $this->markTestSkipped('Unable to load package.');
     }
     $this->repository = new InstalledRepository($this->workspace);
     $this->installer = new PackageInstaller($this->repository, $loader);
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 protected function loadConfig(array $config, $class)
 {
     $package = parent::loadConfig($config, $class);
     if ($package->getType() != 'theme') {
         throw new UnexpectedValueException('Package ' . $config['name'] . ' has no type "theme" defined.');
     }
     return $package;
 }
 /**
  * Creates and uploads a .zip release file.
  *
  * @param string $name
  * @param string $path
  * @param string $json
  */
 protected function upload($name, $path, $json)
 {
     $temp = $this->pagekit['path'] . '/app/temp';
     $api = $this->pagekit['config']['api.url'];
     if (!is_dir($path = "{$path}/{$name}")) {
         $this->error("Can't find {$json} in '{$path}'");
         exit;
     }
     if (!($key = $this->pagekit['option']->get('system:api.key'))) {
         $this->error("Please set your api key");
         exit;
     }
     $loader = new JsonLoader();
     $package = $loader->load("{$path}/{$json}");
     $version = $package->getVersion();
     $zip = new \ZipArchive();
     $zip->open($zipFile = "{$temp}/{$name}-{$version}.zip", \ZipArchive::OVERWRITE);
     $finder = new Finder();
     $finder->files()->in($path)->ignoreVCS(true);
     foreach ($finder as $file) {
         $zip->addFile($file->getPathname(), $file->getRelativePathname());
     }
     $zip->close();
     $time = microtime(true);
     $name = basename($zipFile);
     $size = filesize($zipFile) / 1024 / 1024;
     $this->line(sprintf('Uploading: %s (%.2f MB) ...', $name, $size));
     try {
         $client = new Client();
         $client->post("{$api}/package/upload", ['body' => ['api_key' => $key, 'force' => $this->option('force'), 'file' => new PostFile('file', fopen($zipFile, 'r'))]]);
         $this->line(sprintf('Finished (%d KB/s)', $size * 1024 / (microtime(true) - $time)));
     } catch (BadResponseException $e) {
         $data = json_decode($e->getResponse()->getBody(true), true);
         $this->line(sprintf('Error: %s', $data['error']));
     }
 }
 protected function loadPackage($file)
 {
     try {
         if (is_dir($file)) {
             $json = realpath("{$file}/theme.json") ?: realpath("{$file}/extension.json");
         } elseif (is_file($file)) {
             $zip = new \ZipArchive();
             if ($zip->open($file) === true) {
                 $json = $zip->getFromName("theme.json") ?: $zip->getFromName("extension.json");
                 $zip->close();
             }
         }
         if (isset($json) && $json) {
             $loader = new JsonLoader();
             $package = $loader->load($json);
             return $package;
         }
         throw new Exception();
     } catch (\Exception $e) {
         throw new Exception(__('Can\'t load json file from package.'));
     }
 }