setOperator($operator); } /** * Gets supported operators. * * @return array */ protected static function operators() { return self::getConstants(static::$operators); } /** * Gets friendly representations. * * @return array */ protected static function friendlyRepresentations() { return static::$friendlyRepresentations; } /** * Sets the operator. * * @param string $operator The operator to set. */ protected function setOperator($operator) { if (in_array($operator, self::operators(), false)) { $this->operator = $operator; return; } $friendlyRepresentations = static::friendlyRepresentations(); if (isset($operator, $friendlyRepresentations)) { $this->operator = $friendlyRepresentations[$operator]; return; } throw new UnexpectedValueException('Invalid ' . ClassUtils::getBaseName(static::class) . " $operator"); } /** * Serializes to string. * * @return string */ public function __toString() { return $this->operator; } /** * Serializes to json. * * @return mixed */ public function jsonSerialize() { return ['operator' => $this->operator]; } }