예제 #1
0
 /**
  * This method checks if $value confirms to Type, if $value does not confirm to type, throws an exception or returns null if $soft is true
  *
  * @param            $value
  * @param string     $variableName Used in the message of the Exception, to ease debugging
  * @param bool       $soft
  *
  * @return mixed
  */
 public function check($value, $variableName = "unknown", $soft = false)
 {
     if ($value === null) {
         return null;
     }
     return $this->type->check($value, $variableName, $soft);
 }
예제 #2
0
 /**
  * This method checks if $value confirms to Type, if $value does not confirm to type, throws an exception or returns null if $soft is true
  *
  * @param            $value
  * @param string     $variableName Used in the message of the Exception, to ease debugging
  * @param bool       $soft
  *
  * @return mixed
  */
 public function check($value, $variableName = "unknown", $soft = false)
 {
     if ($value === null && $this->defaultOnNull) {
         return $this->defaultValue;
     }
     $result = $this->type->check($value, $variableName, $this->defaultOnWrongType);
     if ($result instanceof None) {
         return $this->defaultValue;
     }
     return $result;
 }
예제 #3
0
파일: Type.php 프로젝트: itillawarra/cmfive
 function check($value = null, $schema = null, $path = null, $i = null)
 {
     $type = isset($schema->type) ? $schema->type : null;
     $isValid = true;
     if (is_array($type)) {
         $validatedOneType = false;
         $errors = array();
         foreach ($type as $tp) {
             $validator = new Type($this->checkMode);
             $subSchema = new \stdClass();
             $subSchema->type = $tp;
             $validator->check($value, $subSchema, $path, null);
             $error = $validator->getErrors();
             if (!count($error)) {
                 $validatedOneType = true;
                 break;
             } else {
                 $errors = $error;
             }
         }
         if (!$validatedOneType) {
             return $this->addErrors($errors);
         }
     } elseif (is_object($type)) {
         $this->checkUndefined($value, $type, $path);
     } else {
         $isValid = $this->validateType($value, $type);
     }
     if ($isValid === false) {
         $this->addError($path, gettype($value) . " value found, but a " . $type . " is required");
     }
 }
예제 #4
0
 /**
  * validates the type of a property
  *
  * @param mixed $value
  * @param mixed $schema
  * @param mixed $path
  * @param mixed $i
  */
 protected function checkType($value, $schema = null, $path = null, $i = null)
 {
     $validator = new Type($this->checkMode);
     $validator->check($value, $schema, $path, $i);
     $this->addErrors($validator->getErrors());
 }
예제 #5
0
파일: Assert.php 프로젝트: JeCat/framework
 public static function type($Types, &$Variable, $sVarName = null)
 {
     if (!self::$bEnableAssert) {
         return;
     }
     Type::toArray($Types, Type::toArray_ignoreNull);
     if (!Type::check($Types, $Variable)) {
         throw new TypeException($Variable, $Types, $sVarName);
     }
 }
예제 #6
0
파일: Gettext.php 프로젝트: jankal/mvc
 /**
  * @param $context
  * @param $output
  * @return bool|void
  */
 public static function compile($context, $output)
 {
     if (Type::check(Type::STRING, $context) && Type::check(Type::STRING, $output)) {
         $Cparts = explode('.', $context);
         $Cextension = $Cparts[count($Cparts) - 1];
         $Oparts = explode('.', $output);
         $Oextension = $Oparts[count($Oparts) - 1];
         $Cfile = new File($context);
         if ($Cfile->exists()) {
             switch ($Cextension) {
                 case 'po':
                     $translations = Translations::fromPoFile($context);
                     break;
                 case 'mo':
                     $translations = Translations::fromMoFile($context);
                     break;
                 case 'php':
                     $translations = Translations::fromPhpArrayFile($context);
                     break;
             }
             switch ($Oextension) {
                 case 'po':
                     $translations->toPoFile($output);
                     break;
                 case 'mo':
                     $translations->toMoFile($output);
                     break;
                 case 'php':
                     $translations->toPhpArrayFile($output);
                     break;
             }
         }
     } else {
         return false;
     }
 }