Last active
August 29, 2015 14:11
-
-
Save noxify/44855c222050e973d427 to your computer and use it in GitHub Desktop.
Packagist Search Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Artisan::add(new PackagistSearchCommand); | |
Artisan::add(new PackagistListCommand); | |
Artisan::add(new PackagistDetailCommand); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Console\Command; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Input\InputArgument; | |
class PackagistDetailCommand extends Command { | |
/** | |
* The console command name. | |
* | |
* @var string | |
*/ | |
protected $name = 'packagist:detail'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Detail Command'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function fire() | |
{ | |
$client = new Packagist\Api\Client(); | |
$package = $client->get( $this->argument('name') ); | |
$this->info('Package Name: '.$package->getName()); | |
$this->info('Package Description: '.$package->getDescription()); | |
/* | |
//Currently not supported from the Package | |
$this->info('Package Keywords: '.$package->getKeywords()); | |
$this->info('Package Homepage: '.$package->getHomepage()); | |
$this->info('Package version: '.$package->getVersion()); | |
$this->info('Package versionNormalized: '.$package->getVersionNormalized()); | |
$this->info('Package license: '.$package->getLicense()); | |
$this->info('Package authors: '.$package->getAuthors()); | |
$this->info('Package Source: '.$package->getSource()); | |
*/ | |
} | |
/** | |
* Get the console command arguments. | |
* | |
* @return array | |
*/ | |
protected function getArguments() | |
{ | |
return array( | |
array('name', InputArgument::REQUIRED, 'Name of the Package to search for.'), | |
); | |
} | |
protected function getOptions() | |
{ | |
return array(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Console\Command; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Input\InputArgument; | |
class PackagistListCommand extends Command { | |
/** | |
* The console command name. | |
* | |
* @var string | |
*/ | |
protected $name = 'packagist:list'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'List Command'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function fire() | |
{ | |
$client = new Packagist\Api\Client(); | |
$filters = array(); | |
//add defined tags | |
foreach( $this->option('tag') as $tagKey => $tagValue ) { | |
$filters['tags['.$tagKey.']'] = $tagValue; | |
} | |
//add type parameter if defined | |
if( null !== $this->option('type') ) { | |
$filters['type'] = $this->option('type'); | |
} | |
//add vendor parameter if defined | |
if( null !== $this->option('vendor') ) { | |
$filters['vendor'] = $this->option('vendor'); | |
} | |
//we will show all found packages | |
//instead of only 15 records in the browser preview | |
foreach ($client->all( $filters ) as $result) { | |
$this->info($result->getName()); | |
} | |
} | |
/** | |
* Get the console command arguments. | |
* | |
* @return array | |
*/ | |
protected function getArguments() | |
{ | |
return array(); | |
} | |
protected function getOptions() | |
{ | |
return array( | |
array('tag', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Package Tags', []), | |
array('type', null, InputOption::VALUE_REQUIRED, 'Package Type', null), | |
array('vendor', null, InputOption::VALUE_REQUIRED, 'Package Vendor', null), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Console\Command; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Input\InputArgument; | |
class PackagistSearchCommand extends Command { | |
/** | |
* The console command name. | |
* | |
* @var string | |
*/ | |
protected $name = 'packagist:search'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Search Command'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function fire() | |
{ | |
$client = new Packagist\Api\Client(); | |
$filters = array(); | |
//add defined tags | |
foreach( $this->option('tag') as $tagKey => $tagValue ) { | |
$filters['tags['.$tagKey.']'] = $tagValue; | |
} | |
//add type parameter if defined | |
if( null !== $this->option('type') ) { | |
$filters['type'] = $this->option('type'); | |
} | |
//add vendor parameter if defined | |
if( null !== $this->option('vendor') ) { | |
$filters['vendor'] = $this->option('vendor'); | |
} | |
//we will show all found packages | |
//instead of only 15 records in the browser preview | |
foreach ($client->search( $this->argument('name'), $filters ) as $result) { | |
$this->info($result->getName()); | |
} | |
} | |
/** | |
* Get the console command arguments. | |
* | |
* @return array | |
*/ | |
protected function getArguments() | |
{ | |
return array( | |
array('name', InputArgument::REQUIRED, 'Name of the Package to search for.'), | |
); | |
} | |
protected function getOptions() | |
{ | |
return array( | |
array('tag', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Package Tags', []), | |
array('type', null, InputOption::VALUE_REQUIRED, 'Package Type', null), | |
array('vendor', null, InputOption::VALUE_REQUIRED, 'Package Vendor', null), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment