/** * Checks values to see if they fit the restrictions defined for the * Restricted object * * This goes through each value, grabs its type, and compares it * against the Restrictions * * @static * * @param array $values The values to check against the restrictions * @param Resource\FilterInerface The filter to run them through * @param bool $strict Throw errors? * * @return bool Valid types? * * @throws \InvalidArgumentException if the value is untypeable, or illegal (only strict) * */ public static function checkElements(array $values, Resource\FilterInterface $filter, $strict = null) { foreach ($values as $value) { if (($typeEnum = Type\getValueType($value)) === false) { throw new Exception\InvalidArgumentException('Restrictions->checkElements: Untypeable Value'); } if ($filter->isAllowed($typeEnum) == false) { if ($strict) { throw new Exception\InvalidArgumentException('Restrictions->checkElements: Illegal Value'); } return false; } } return true; }
echo "Matched\n"; } else { echo "Mismatched\n"; } echo "Array -- "; if (Type\getValueType($array)->get() === Types\Type::BASIC_ARRAY) { echo "Matched\n"; } else { echo "Mismatched\n"; } echo "Object -- "; if (Type\getValueType($object)->get() === Types\Type::BASIC_OBJECT) { echo "Matched\n"; } else { echo "Mismatched\n"; } echo "Function -- "; if (Type\getValueType('Falcraft\\tests\\Data\\Types\\testCustomFunction')->get() === Types\Type::BASIC_FUNCTION) { echo "Matched\n"; } else { echo "Mismatched\n"; } echo "Closure -- "; if (Type\getValueType($closure)->get() === Types\Type::BASIC_CLOSURE) { echo "Matched\n"; } else { echo "Mismatched\n"; } echo "Typed Object (Range) -- "; var_dump(Type\getValueType($typedObject));