コード例 #1
0
ファイル: Validator.php プロジェクト: crysalead/validator
 /**
  * Constructor
  *
  * @param array $config The config array. Possible values are:
  *                      - `'handlers'` _array_ : Some custom handlers.
  */
 public function __construct($config = [])
 {
     $defaults = ['meta' => [], 'handlers' => [], 'classes' => $this->_classes, 'error' => function ($name, $options, $meta = []) {
         return Text::insert($options['message'] ?: $this->message($name), $options);
     }];
     $config = Set::merge($defaults, $config);
     $this->_classes = $config['classes'];
     $this->set($config['handlers']);
     $this->error($config['error']);
     $this->meta($config['meta']);
 }
コード例 #2
0
ファイル: Text.spec.php プロジェクト: crysalead/string
            $result = Text::clean('{:a}, 3, {:b}');
            expect($result)->toBe('3');
            $result = Text::clean('{:a}, {:b}, {:c}');
            expect($result)->toBe('');
        });
        it("cleans placeholder and adjacent `'and'`", function () {
            $result = Text::clean('{:a} and 2 and 3');
            expect($result)->toBe('2 and 3');
            $result = Text::clean('2 and {:a} and 3');
            expect($result)->toBe('2 and 3');
            $result = Text::clean('{:a} and {:b} and 3');
            expect($result)->toBe('3');
            $result = Text::clean('{:a} and 3 and {:b}');
            expect($result)->toBe('3');
            $result = Text::clean('{:a} and {:b} and {:c}');
            expect($result)->toBe('');
        });
        it("cleans placeholder and adjacent comma and `'and'`", function () {
            $result = Text::clean('{:a}, 2 and 3');
            expect($result)->toBe('2 and 3');
            $result = Text::clean('{:a}, 2 and {:c}');
            expect($result)->toBe('2');
        });
        it("cleans placeholder with special chars", function () {
            $string = '${a} ${b}';
            $expected = '';
            $result = Text::clean($string, ['before' => '${', 'after' => '}']);
            expect($result)->toBe($expected);
        });
    });
});
コード例 #3
0
ファイル: Dialect.php プロジェクト: crysalead/sql
 /**
  * Build a SQL column constraint
  *
  * @param  string $name       The name of the meta to build.
  * @param  mixed  $constraint The constraint value.
  * @param  array  $options    The constraint options.
  * @return string             The SQL meta string.
  */
 public function constraint($name, $value, $options = [])
 {
     $value += ['options' => []];
     $meta = isset($this->_constraints[$name]) ? $this->_constraints[$name] : null;
     if (!($template = isset($meta['template']) ? $meta['template'] : null)) {
         throw new SqlException("Invalid constraint template `'{$name}'`.");
     }
     $data = [];
     foreach ($value as $name => $value) {
         switch ($name) {
             case 'key':
             case 'index':
                 if (isset($meta[$name])) {
                     $data['index'] = $meta[$name];
                 }
                 break;
             case 'to':
                 $data[$name] = $this->name($value);
                 break;
             case 'on':
                 $data[$name] = "ON {$value}";
                 break;
             case 'constraint':
                 $data[$name] = "CONSTRAINT " . $this->name($value);
                 break;
             case 'expr':
                 $data[$name] = $this->conditions(is_array($value) ? $value : [$value], $options);
                 break;
             case 'column':
             case 'primaryKey':
             case 'foreignKey':
                 $data[$name] = join(', ', array_map([$this, 'name'], (array) $value));
                 break;
         }
     }
     return trim(Text::insert($template, $data, ['clean' => ['method' => 'text']]));
 }