コード例 #1
0
ファイル: _Model.php プロジェクト: adrian-enspired/ADR
 /**
  * validates a literal offset value based on defined TYPE rules.
  *
  * @param string $offset       name of offset to validate against
  * @param mixed  $value        the value to test
  * @throws ModelableException  if offset does not exist
  * @return bool                true if validation succeeds; false otherwise
  */
 protected function _literalOffsetValid(string $offset, $value)
 {
     if (!isset($this->_prop[$offset])) {
         $context = ['tr' => ['offset' => $offset]];
         throw new ModelableException(ModelableException::INVALID_LITERAL, $context);
     }
     $type = $this::TYPE[$offset] ?? null;
     return $value === null || $type === null || gettype($value) === $type || $value instanceof $type || is_scalar($value) && Vars::is_regex($type) && preg_match($type, (string) $value);
 }