| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types = 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace Drupal\mongodb\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Drupal\Component\Serialization\SerializationInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Drupal\mongodb\Install\Tools; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Symfony\Component\Console\Input\InputArgument; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Symfony\Component\Console\Input\InputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Drupal\Console\Core\Command\ContainerAwareCommand; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | // @codingStandardsIgnoreLine | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Drupal\Console\Annotations\DrupalCommand; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * Class FindCommand. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @DrupalCommand ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  *     extension="mongodb", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  *     extensionType="module" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | class FindCommand extends ContainerAwareCommand { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |   const NAME = 'commands.mongodb.find'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |    * The mongodb.tools service. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |    * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |    * @var \Drupal\mongodb\Install\Tools | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |   protected $tools; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |    * The serialization.yaml service. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |    * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |    * @var \Drupal\Component\Serialization\SerializationInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |   protected $serialization; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |    * FindCommand constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |    * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |    * @param \Drupal\mongodb\Install\Tools $tools | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |    *   The mongodb.tools service. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |    * @param \Drupal\Component\Serialization\SerializationInterface $yaml | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |    *   The serialization.yaml service. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |   public function __construct(Tools $tools, SerializationInterface $yaml) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     parent::__construct(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     $this->serialization = $yaml; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     $this->tools = $tools; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |    * {@inheritdoc} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 58 |  |  |    */ | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |   protected function configure() { | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |     $name = static::NAME; | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |     $arguments = "${name}.arguments"; | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |     $usageGeneric = <<<USAGE | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  | <collection> <query> | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |     <query> is a single JSON selector in single string format. Quote it. | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  | USAGE; | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |     $usageNoSelector = <<<USAGE | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  | logger watchdog | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |     Get the logger/watchdog error-level templates | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  | USAGE; | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |     $usageStringInt = <<<USAGE | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  | logger watchdog '{ "severity": 3 }' | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |     Get all the logger/watchdog entries tracking rows. | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  | USAGE; | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |     $usageTwoStrings = <<<USAGE | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  | keyvalue kvp_state '{ "_id": "system.theme_engine.files" }' | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |     Get a specific State entry. Note how escaping needs to be performed in the shell. | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  | USAGE; | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |     $this | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |       ->setName('mongodb:find') | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |       ->setAliases(['mdbf', 'mo-find']) | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |       ->setDescription($this->trans("${name}.description")) | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |       ->setHelp($this->trans("${name}.help")) | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |       ->addUsage($usageGeneric) | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |       ->addUsage($usageNoSelector) | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |       ->addUsage($usageStringInt) | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |       ->addUsage($usageTwoStrings) | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |       ->addArgument('alias', InputArgument::REQUIRED, "${arguments}.alias") | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |       ->addArgument('collection', InputArgument::REQUIRED, "${arguments}.collection") | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |       ->addArgument('selector', InputArgument::OPTIONAL, "${arguments}.selector", '{ }'); | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |    * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |   protected function execute(InputInterface $input, OutputInterface $output) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     // PHP 7.1 list('alias' => $alias ...) syntax is no yet supported in PHPMD. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     $arguments = $input->getArguments(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     // These are declared arguments, so they're known to have a value. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     $alias = $arguments['alias']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     $collection = $arguments['collection']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     $selector = $arguments['selector']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |       ->getIo() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |       ->write( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         $this->serialization->encode( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |           $this->tools->find($alias, $collection, $selector) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |       ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 116 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 117 |  |  |  |