protected function execute(InputInterface $input, OutputInterface $output)
 {
     // init repos
     $platformRepo = new PlatformRepository();
     if ($composer = $this->getComposer(false)) {
         $localRepo = $composer->getRepositoryManager()->getLocalRepository();
         $installedRepo = new CompositeRepository(array($localRepo, $platformRepo));
         $repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
     } else {
         $output->writeln('No composer.json found in the current directory, showing packages from packagist.org');
         $installedRepo = $platformRepo;
         $repos = new CompositeRepository(array($installedRepo, new ComposerRepository(array('url' => 'http://packagist.org'))));
     }
     $tokens = array_map('strtolower', $input->getArgument('tokens'));
     foreach ($repos->getPackages() as $package) {
         foreach ($tokens as $token) {
             if (false === ($pos = strpos($package->getName(), $token))) {
                 continue;
             }
             if ($platformRepo->hasPackage($package)) {
                 $type = '<info>platform: </info> ';
             } elseif ($installedRepo->hasPackage($package)) {
                 $type = '<info>installed:</info> ';
             } else {
                 $type = '<comment>available:</comment> ';
             }
             $name = substr($package->getPrettyName(), 0, $pos) . '<highlight>' . substr($package->getPrettyName(), $pos, strlen($token)) . '</highlight>' . substr($package->getPrettyName(), $pos + strlen($token));
             $output->writeln($type . ': ' . $name . ' <comment>' . $package->getPrettyVersion() . '</comment>');
             continue 2;
         }
     }
 }
Exemple #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // init repos
     $platformRepo = new PlatformRepository();
     if ($composer = $this->getComposer(false)) {
         $localRepo = $composer->getRepositoryManager()->getLocalRepository();
         $installedRepo = new CompositeRepository(array($localRepo, $platformRepo));
         $repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
     } else {
         $output->writeln('No composer.json found in the current directory, showing packages from packagist.org');
         $installedRepo = $platformRepo;
         $packagist = new ComposerRepository(array('url' => 'http://packagist.org'), $this->getIO(), Factory::createConfig());
         $repos = new CompositeRepository(array($installedRepo, $packagist));
     }
     $tokens = $input->getArgument('tokens');
     $packages = array();
     $maxPackageLength = 0;
     foreach ($repos->getPackages() as $package) {
         if ($package instanceof AliasPackage || isset($packages[$package->getName()])) {
             continue;
         }
         foreach ($tokens as $token) {
             if (!($score = $this->matchPackage($package, $token))) {
                 continue;
             }
             if (false !== ($pos = stripos($package->getName(), $token))) {
                 $name = substr($package->getPrettyName(), 0, $pos) . '<highlight>' . substr($package->getPrettyName(), $pos, strlen($token)) . '</highlight>' . substr($package->getPrettyName(), $pos + strlen($token));
             } else {
                 $name = $package->getPrettyName();
             }
             $description = strtok($package->getDescription(), "\r\n");
             if (false !== ($pos = stripos($description, $token))) {
                 $description = substr($description, 0, $pos) . '<highlight>' . substr($description, $pos, strlen($token)) . '</highlight>' . substr($description, $pos + strlen($token));
             }
             $packages[$package->getName()] = array('name' => $name, 'description' => $description, 'length' => $length = strlen($package->getPrettyName()), 'score' => $score);
             $maxPackageLength = max($maxPackageLength, $length);
             continue 2;
         }
     }
     usort($packages, function ($a, $b) {
         if ($a['score'] === $b['score']) {
             return 0;
         }
         return $a['score'] > $b['score'] ? -1 : 1;
     });
     foreach ($packages as $details) {
         $extraSpaces = $maxPackageLength - $details['length'];
         $output->writeln($details['name'] . str_repeat(' ', $extraSpaces) . ' <comment>:</comment> ' . $details['description']);
     }
 }
 public function testGetPackages()
 {
     $arrayRepoOne = new ArrayRepository();
     $arrayRepoOne->addPackage($this->getPackage('foo', '1'));
     $arrayRepoTwo = new ArrayRepository();
     $arrayRepoTwo->addPackage($this->getPackage('bar', '1'));
     $repo = new CompositeRepository(array($arrayRepoOne, $arrayRepoTwo));
     $packages = $repo->getPackages();
     $this->assertCount(2, $packages, "Should get two packages");
     $this->assertEquals("foo", $packages[0]->getName(), "First package should have name of 'foo'");
     $this->assertEquals("1", $packages[0]->getPrettyVersion(), "First package should have pretty version of '1'");
     $this->assertEquals("bar", $packages[1]->getName(), "Second package should have name of 'bar'");
     $this->assertEquals("1", $packages[1]->getPrettyVersion(), "Second package should have pretty version of '1'");
 }
Exemple #4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // init repos
     $platformRepo = new PlatformRepository();
     if ($composer = $this->getComposer(false)) {
         $localRepo = $composer->getRepositoryManager()->getLocalRepository();
         $installedRepo = new CompositeRepository(array($localRepo, $platformRepo));
         $repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
     } else {
         $output->writeln('No composer.json found in the current directory, showing packages from packagist.org');
         $installedRepo = $platformRepo;
         $packagist = new ComposerRepository(array('url' => 'http://packagist.org'), $this->getIO());
         $repos = new CompositeRepository(array($installedRepo, $packagist));
     }
     $tokens = $input->getArgument('tokens');
     $packages = array();
     foreach ($repos->getPackages() as $package) {
         if ($package instanceof AliasPackage || isset($packages[$package->getName()])) {
             continue;
         }
         foreach ($tokens as $token) {
             if (!$this->matchPackage($package, $token)) {
                 continue;
             }
             if (false !== ($pos = stripos($package->getName(), $token))) {
                 $name = substr($package->getPrettyName(), 0, $pos) . '<highlight>' . substr($package->getPrettyName(), $pos, strlen($token)) . '</highlight>' . substr($package->getPrettyName(), $pos + strlen($token));
             } else {
                 $name = $package->getPrettyName();
             }
             $packages[$package->getName()] = array('name' => $name, 'description' => strtok($package->getDescription(), "\r\n"));
             continue 2;
         }
     }
     foreach ($packages as $details) {
         $output->writeln($details['name'] . ' <comment>:</comment> ' . $details['description']);
     }
 }