本文整理汇总了PHP中Type::check方法的典型用法代码示例。如果您正苦于以下问题:PHP Type::check方法的具体用法?PHP Type::check怎么用?PHP Type::check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type::check方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: check
/**
* 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: check
/**
* 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: check
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: checkType
/**
* 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: type
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: compile
/**
* @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;
}
}