/**
  * @param \App\Satis\Collections\RepositoryCollection $repositoryCollection
  * @param string $repositoryId
  * @param \Illuminate\Support\Collection $input
  * @return \App\Satis\Collections\RepositoryCollection
  * @throws \App\Satis\Exceptions\RepositoryNotFoundException
  */
 protected function _addOrUpdateRepository(RepositoryCollection $repositoryCollection, $repositoryId, Collection $input)
 {
     $repository = new Repository();
     $repository->setUrl($input->get('url'));
     $repository->setType($input->get('type', config('satis.default_repository_type')));
     if ($input->has('async_mode')) {
         $this->configBuilder->setAsyncMode(filter_var($input->get('async_mode'), FILTER_VALIDATE_BOOLEAN));
     }
     if ($input->has('disable_build')) {
         $this->setDisableBuild(filter_var($input->get('disable_build'), FILTER_VALIDATE_BOOLEAN));
     }
     if ($repositoryId !== null) {
         if ($repositoryCollection->has($repositoryId)) {
             $repositoryCollection->put($repositoryId, $repository);
         } else {
             throw new RepositoryNotFoundException('Repository with ID "' . $repositoryId . '" does not exist.');
         }
     } else {
         $repositoryId = static::nameToId($repository->getUrl());
         $repositoryCollection->put($repositoryId, $repository);
     }
     $buildContext = new PrivateRepository();
     $buildContext->setItemId($repositoryId)->setItemName($repository->getUrl());
     $this->configBuilder->setBuildContext($buildContext);
     return $repositoryCollection;
 }
 /**
  * Register any application services.
  *
  * @return void
  */
 public function register()
 {
     $serializer = SerializerBuilder::create()->configureHandlers(function (HandlerRegistry $registry) {
         $registry->registerHandler('serialization', 'App\\Satis\\Collections\\RepositoryCollection', 'json', function (VisitorInterface $visitor, Collection $collection, array $type, Context $context) {
             return $visitor->visitArray($collection->values(), $type, $context);
         });
         $registry->registerHandler('serialization', 'App\\Satis\\Collections\\PackageCollection', 'json', function (VisitorInterface $visitor, Collection $collection, array $type, Context $context) {
             $output = [];
             foreach ($collection->values() as $package) {
                 /** @var Package $package */
                 $output[$package->getName()] = $package->getVersion();
             }
             if (!$output) {
                 return null;
             }
             $type = array('name' => 'array');
             return $visitor->visitArray($output, $type, $context);
         });
     })->configureHandlers(function (HandlerRegistry $registry) {
         $registry->registerHandler('deserialization', 'App\\Satis\\Collections\\RepositoryCollection', 'json', function (VisitorInterface $visitor, array $data, array $type, Context $context) {
             /** @var \App\Satis\Model\Repository[] $repositories */
             $repositories = $visitor->visitArray($data, $type, $context);
             $collection = new RepositoryCollection();
             foreach ($repositories as $repository) {
                 $collection->put($repository->getId(), $repository);
             }
             return $collection;
         });
         $registry->registerHandler('deserialization', 'App\\Satis\\Collections\\PackageCollection', 'json', function (VisitorInterface $visitor, array $data, array $type, Context $context) {
             $temp = [];
             foreach ($data as $name => $version) {
                 $temp[] = ['name' => $name, 'version' => $version];
             }
             /** @var \App\Satis\Model\Package[] $packages */
             $packages = $visitor->visitArray($temp, $type, $context);
             $collection = new PackageCollection();
             foreach ($packages as $package) {
                 $collection->put($package->getId(), $package);
             }
             return $collection;
         });
     })->build();
     $this->app->bind('App\\Satis\\ConfigMirror', function ($app) use($serializer) {
         return new ConfigMirror($serializer);
     });
     $this->app->bind('App\\Satis\\ConfigManager', function ($app) use($serializer) {
         $configPersister = $this->app->make('App\\Satis\\ConfigPersister');
         return new ConfigManager($configPersister, new ConfigBuilder($configPersister), $serializer);
     });
     $this->app->bind('App\\Satis\\ConfigPersister', function ($app) use($serializer) {
         $filesystem = new Filesystem();
         $configLock = new ConfigLock();
         $configMirror = $this->app->make('App\\Satis\\ConfigMirror');
         return new ConfigPersister($filesystem, $configLock, $configMirror, $serializer);
     });
     $this->app->bind('JMS\\Serializer\\Serializer', function ($app) use($serializer) {
         return $serializer;
     });
 }