Exemplo n.º 1
0
 /**
  * @dataProvider summarizeProvider
  */
 public function testSummarize($expected, $input)
 {
     $this->assertSame($expected, Type::summarize($input));
 }
Exemplo n.º 2
0
 /**
  * Validate user input using regular expressions or callable (must return true if valid).
  *
  * @param string               $input
  * @param string|callable|null $validator
  *
  * @return bool True if valid, false otherwise.
  */
 private function validate($input, $validator = null)
 {
     // Always valid when there's no validator.
     if ($validator === null) {
         return true;
     }
     if (is_string($validator)) {
         $regex = $validator;
         $validator = function ($input) use($regex) {
             return preg_match($regex, $input) === 1;
         };
     }
     if (!is_callable($validator)) {
         throw new \RuntimeException(sprintf("Stdio::validate must be called with a regular expression or callable. '%s' given.", Type::summarize($validator)));
     }
     return $validator($input);
 }