예제 #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
파일: Stringify.php 프로젝트: bashkarev/bem
 /**
  * @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
파일: Parse.php 프로젝트: bashkarev/bem
 /**
  * @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();
 }