Ejemplo n.º 1
0
 /**
  * Returns true if and only if $value contains only alphabetic characters
  *
  * @param  string $value
  * @return boolean
  */
 public function isValid($value)
 {
     if (!is_string($value)) {
         $this->error(self::INVALID);
         return false;
     }
     $this->setValue($value);
     if ('' === $value) {
         $this->error(self::STRING_EMPTY);
         return false;
     }
     if (null === self::$filter) {
         self::$filter = new AlphaFilter();
     }
     //self::$filter->setAllowWhiteSpace($this->allowWhiteSpace);
     self::$filter->setAllowWhiteSpace($this->options['allowWhiteSpace']);
     if ($value !== self::$filter->filter($value)) {
         $this->error(self::NOT_ALPHA);
         return false;
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return null
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $transformer = new DashToCamelCase();
     $filter = new Alpha();
     $name = $input->getArgument('name');
     $className = $filter->filter($transformer->filter(ucfirst($name)));
     $description = $input->getArgument('description');
     $filesystem = new Filesystem(new Adapter(dirname(dirname(dirname(dirname(dirname(__DIR__)))))));
     $template = $filesystem->read('vendor/middleout/mdo-bundle-zf2-cli/templates/Command/TemplateCommand.php');
     $template = str_replace(['TemplateCommandName', 'TemplateCommandDescription', 'TemplateCommandLiteralName'], [$className . 'Command', $description, $name], $template);
     $filesystem->write('module/Cli/src/Command/' . $className . 'Command.php', $template);
     $output->writeln('');
     $output->writeln('Created command succesfully in path "module/Cli/src/Command/' . $className . 'Command.php"');
     $output->writeln('');
 }
Ejemplo n.º 3
0
 /**
  * Ensures that the filter follows expected behavior
  *
  * @return void
  */
 public function testAllowWhiteSpace()
 {
     $this->filter->setAllowWhiteSpace(true);
     if (!self::$unicodeEnabled) {
         // POSIX named classes are not supported, use alternative a-zA-Z match
         $valuesExpected = array('abc123' => 'abc', 'abc 123' => 'abc ', 'abcxyz' => 'abcxyz', '' => '', "\n" => "\n", " \t " => " \t ");
     }
     if (self::$meansEnglishAlphabet) {
         //The Alphabet means english alphabet.
         $valuesExpected = array('a B' => 'a B', 'zY x' => 'zx');
     } else {
         //The Alphabet means each language's alphabet.
         $valuesExpected = array('abc123' => 'abc', 'abc 123' => 'abc ', 'abcxyz' => 'abcxyz', 'četně' => 'četně', 'لعربية' => 'لعربية', 'grzegżółka' => 'grzegżółka', 'België' => 'België', '' => '', "\n" => "\n", " \t " => " \t ");
     }
     foreach ($valuesExpected as $input => $expected) {
         $actual = $this->filter->filter($input);
         $this->assertEquals($expected, $actual);
     }
 }
Ejemplo n.º 4
0
 /**
  * @dataProvider returnUnfilteredDataProvider
  * @return void
  */
 public function testReturnUnfiltered($input)
 {
     $filter = new AlphaFilter();
     $this->assertEquals($input, $filter->filter($input));
 }