class FindCommand in MongoDB 8.2
Class FindCommand provides the 'commands.mongodb.find' command.
@DrupalCommand ( extension="mongodb", extensionType="module" )
Hierarchy
- class \Drupal\mongodb\Command\FindCommand extends \Drupal\Console\Core\Command\ContainerAwareCommand
Expanded class hierarchy of FindCommand
1 string reference to 'FindCommand'
- console.services.yml in modules/
mongodb/ console.services.yml - modules/mongodb/console.services.yml
1 service uses FindCommand
- mongodb.mongodb_find in modules/
mongodb/ console.services.yml - \Drupal\mongodb\Command\FindCommand
File
- modules/
mongodb/ src/ Command/ FindCommand.php, line 24
Namespace
Drupal\mongodb\CommandView source
class FindCommand extends ContainerAwareCommand {
const NAME = 'commands.mongodb.find';
/**
* The mongodb.tools service.
*
* @var \Drupal\mongodb\Install\Tools
*/
protected $tools;
/**
* The serialization.yaml service.
*
* @var \Drupal\Component\Serialization\SerializationInterface
*/
protected $serialization;
/**
* FindCommand constructor.
*
* @param \Drupal\mongodb\Install\Tools $tools
* The mongodb.tools service.
* @param \Drupal\Component\Serialization\SerializationInterface $yaml
* The serialization.yaml service.
*/
public function __construct(Tools $tools, SerializationInterface $yaml) {
parent::__construct();
$this->serialization = $yaml;
$this->tools = $tools;
}
/**
* {@inheritdoc}
*/
protected function configure() {
$name = static::NAME;
$arguments = "{$name}.arguments";
$usageGeneric = <<<USAGE
<collection> <query>
<query> is a single JSON selector in single string format. Quote it.
USAGE;
$usageNoSelector = <<<USAGE
logger watchdog
Get the logger/watchdog error-level templates
USAGE;
$usageStringInt = <<<USAGE
logger watchdog '{ "severity": 3 }'
Get all the logger/watchdog entries tracking rows.
USAGE;
$usageTwoStrings = <<<USAGE
keyvalue kvp_state '{ "_id": "system.theme_engine.files" }'
Get a specific State entry. Note how escaping needs to be performed in the shell.
USAGE;
$this
->setName('mongodb:find')
->setAliases([
'mdbf',
'mo-find',
])
->setDescription($this
->trans("{$name}.description"))
->setHelp($this
->trans("{$name}.help"))
->addUsage($usageGeneric)
->addUsage($usageNoSelector)
->addUsage($usageStringInt)
->addUsage($usageTwoStrings)
->addArgument('alias', InputArgument::REQUIRED, "{$arguments}.alias")
->addArgument('collection', InputArgument::REQUIRED, "{$arguments}.collection")
->addArgument('selector', InputArgument::OPTIONAL, "{$arguments}.selector", '{ }');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output) {
// PHP 7.1 list('alias' => $alias ...) syntax is no yet supported in PHPMD.
$arguments = $input
->getArguments();
// These are declared arguments, so they're known to have a value.
$alias = $arguments['alias'];
$collection = $arguments['collection'];
$selector = $arguments['selector'];
$this
->getIo()
->write($this->serialization
->encode($this->tools
->find($alias, $collection, $selector)));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FindCommand:: |
protected | property | The serialization.yaml service. | |
FindCommand:: |
protected | property | The mongodb.tools service. | |
FindCommand:: |
protected | function | ||
FindCommand:: |
protected | function | ||
FindCommand:: |
constant | |||
FindCommand:: |
public | function | FindCommand constructor. |