/** * 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); }
/** * 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; }
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"); } }
/** * 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()); }
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); } }
/** * @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; } }