Ejemplo n.º 1
0
 public function test_regReplace()
 {
     $alpha = F\regReplace('/[^a-z]+/i', '');
     $this->assertEquals('AbFd', $alpha('A12;b_{F}|d'));
 }
Ejemplo n.º 2
0
 /**
  * Converts the given syntax to a string.
  *
  * @param  Tarsana\Syntax\Syntax $value the data to encode
  * @return string
  */
 protected function doDump($value)
 {
     $result = '';
     if ($value instanceof StringSyntax) {
         $result = F\regReplace('/[^a-zA-Z-_]+/', '', $value->description());
     } else {
         if ($value instanceof NumberSyntax) {
             $result = '#' . F\regReplace('/[^a-zA-Z-_]+/', '', $value->description());
         } else {
             if ($value instanceof BooleanSyntax) {
                 $result = F\regReplace('/[^a-zA-Z-_]+/', '', $value->description()) . '?';
             } else {
                 if ($value instanceof ArraySyntax) {
                     $item = $value->itemSyntax();
                     $oldDescription = $item->description();
                     $text = $this->dump($item->description($value->description()));
                     $item->description($oldDescription);
                     $result = "{$text}[{$value->separator()}]";
                 } else {
                     if ($value instanceof ObjectSyntax) {
                         $fields = [];
                         foreach ($value->fields() as $name => $item) {
                             $oldDescription = $item->description();
                             $item->description($name);
                             $fields[] = $this->dump($item);
                             $item->description($oldDescription);
                         }
                         $fields = F\join($this->fieldsSeparator, $fields);
                         $name = F\regReplace('/[^a-zA-Z-_]+/', '', $value->description());
                         $result = "{$name}{{$value->separator()}{$this->fieldsSeparator}{$fields}}";
                     }
                 }
             }
         }
     }
     if (!$value->isRequired()) {
         $result = "[{$result}]";
     }
     return $result;
 }