FindCommand.php in MongoDB 8.2
File
modules/mongodb/src/Command/FindCommand.php
View source
<?php
declare (strict_types=1);
namespace Drupal\mongodb\Command;
use Drupal\Component\Serialization\SerializationInterface;
use Drupal\mongodb\Install\Tools;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Core\Command\ContainerAwareCommand;
use Drupal\Console\Annotations\DrupalCommand;
class FindCommand extends ContainerAwareCommand {
const NAME = 'commands.mongodb.find';
protected $tools;
protected $serialization;
public function __construct(Tools $tools, SerializationInterface $yaml) {
parent::__construct();
$this->serialization = $yaml;
$this->tools = $tools;
}
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", '{ }');
}
protected function execute(InputInterface $input, OutputInterface $output) {
$arguments = $input
->getArguments();
$alias = $arguments['alias'];
$collection = $arguments['collection'];
$selector = $arguments['selector'];
$this
->getIo()
->write($this->serialization
->encode($this->tools
->find($alias, $collection, $selector)));
}
}
Classes
Name |
Description |
FindCommand |
Class FindCommand provides the 'commands.mongodb.find' command. |