Пример #1
0
 /**
  * Options test
  */
 public function testOptions()
 {
     $this->assertContains((new Naming(['elem' => '==']))->getElem(), '==', 'should provide elem option');
     $naming = new Naming(['mod' => '--']);
     $this->assertContains($naming->getMod()['name'], '--', 'should support mod option as string');
     $this->assertContains($naming->getMod()['value'], '--', 'should support mod option as string');
     $naming = new Naming(['mod' => ['name' => '--', 'value' => '_']]);
     $this->assertContains($naming->getMod()['name'], '--', 'should support mod option as string');
     $this->assertContains($naming->getMod()['value'], '_', 'should support mod option as string');
     $naming = new Naming(['mod' => ['name' => '--']]);
     $this->assertContains($naming->getMod()['name'], '--', 'should support mod option as string');
     $this->assertContains($naming->getMod()['value'], '--', 'should support mod option as string');
 }
Пример #2
0
 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $naming = new Naming();
     $helper = $this->getHelper('question');
     $options = [];
     foreach (['block' => 'Block name: ', 'elem' => 'Element name: ', 'modName' => 'Modifier name: ', 'modVal' => 'Modifier value: '] as $name => $q) {
         $question = new Question($q);
         while (true) {
             $value = $helper->ask($input, $output, $question);
             if ($value === null || preg_match('/^' . $naming->getWordPattern() . '$/', $value)) {
                 $options[$name] = $value;
                 break 1;
             } else {
                 $output->writeln('<error>' . $value . ' is not valid' . '</error>');
             }
         }
     }
     if (($str = (new Naming())->stringify($options)) === null) {
         throw new \Exception('can\'t create');
     }
     $output->writeln("<info>{$str}</info>");
 }
Пример #3
0
 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $naming = new Naming();
     $result = [];
     foreach (explode(' ', $input->getArgument('text')) as $str) {
         $data = $naming->parse($str);
         if ($data === null) {
             continue;
         }
         $result[] = ['str' => $str] + $data;
     }
     if ($result === []) {
         throw new \Exception('cant\\t parse');
     }
     $table = new Table($output);
     $keys = ['str' => null, 'block' => null, 'elem' => null, 'modName' => null, 'modVal' => null];
     $table->setHeaders(array_keys($keys));
     foreach ($result as $key => $r) {
         $table->setRow($key, array_merge($keys, $r));
     }
     $table->render();
 }