type = $params['type'] ?? null; $object->attribute = $params['attribute'] ?? $params['field'] ?? null; $object->value = $params['value'] ?? null; $object->dateTime = $params['dateTime'] ?? false; $object->timeZone = $params['timeZone'] ?? null; unset($params['field']); foreach ($params as $key => $value) { if (!property_exists($object, $key)) { throw new InvalidArgumentException("Unknown parameter '{$key}'."); } } if (!$object->type) { throw new InvalidArgumentException("No 'type' in where item."); } if ( !$object->attribute && !in_array($object->type, $object->noAttributeTypeList) ) { throw new InvalidArgumentException("No 'attribute' in where item."); } return $object; } public static function fromRawAndGroup(array $paramList) : self { return self::fromRaw([ 'type' => 'and', 'value' => $paramList, ]); } public function getRaw() : array { $raw = [ 'type' => $this->type, 'value' => $this->value, ]; if ($this->attribute) { $raw['attribute'] = $this->attribute; } if ($this->dateTime) { $raw['dateTime'] = $this->dateTime; } if ($this->timeZone) { $raw['timeZone'] = $this->timeZone; } return $raw; } public function getType() : string { return $this->type; } public function getAttribute() : ?string { return $this->attribute; } /** * @return mixed */ public function getValue() { return $this->value; } public function isDateTime() : bool { return $this->dateTime; } public function getTimeZone() : ?string { return $this->timeZone; } }