Пример #1
0
 /**
  * Execute the command
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @throws \Exception
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $projectRepository = $this->getContainer()->get('packy.repository.project');
     $packageRepository = $this->getContainer()->get('packy.repository.package');
     $analyzer = $this->getContainer()->get('packy.analyzer.generic_analyzer');
     $versionFormatter = $this->getContainer()->get('packy.service.version_formatter');
     $fetchers = $this->getContainer()->get('packy.fetchers');
     $fetchers = $fetchers->getFetchers();
     $projects = $projectRepository->findAll();
     foreach ($projects as $project) {
         foreach ($fetchers as $fetcher) {
             $dependencies = $fetcher->fetchDependencies($project);
             foreach ($dependencies as $name => $version) {
                 $package = $packageRepository->findOne($name, $fetcher->getName());
                 if (is_null($package)) {
                     $package = new Package();
                     $package->setName($name);
                     $package->setManager($fetcher->getName());
                     $packageRepository->create($package);
                 }
                 $package = $analyzer->analyzePackage($package, $package->getManager());
                 $packageRepository->update($package);
                 $dependency = new Dependency();
                 $dependency->setPackage($package);
                 $dependency->setRawVersion($version);
                 $dependency->setCurrentVersion($versionFormatter->normalizeVersion($version));
                 $project->addDependency($dependency);
             }
         }
         $projectRepository->update($project);
         $output->writeln("<info>Project " . $project->getName() . " updated!</info>");
     }
 }
Пример #2
0
 /**
  * Add dependencies
  *
  * @TODO: Refactor
  *
  * @param Dependency $dependency
  *
  * @return Project
  */
 public function addDependency(Dependency $dependency)
 {
     $dependency->setProject($this);
     foreach ($this->dependencies as $k => $dep) {
         if ($dep->getPackage()->getName() == $dependency->getPackage()->getName()) {
             $dep->setCurrentVersion($dependency->getCurrentVersion());
             $dep->setRawVersion($dependency->getRawVersion());
             $dep->setRawVersion($dependency->getRawVersion());
             return $this;
         }
     }
     $this->dependencies[] = $dependency;
     return $this;
 }