예제 #1
0
파일: TypeTest.php 프로젝트: nochso/omni
 /**
  * @dataProvider summarizeProvider
  */
 public function testSummarize($expected, $input)
 {
     $this->assertSame($expected, Type::summarize($input));
 }
예제 #2
0
파일: Stdio.php 프로젝트: nochso/writeme
 /**
  * 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);
 }