/** * Check if token is equals to given one. * * If tokens are arrays, then only keys defined in parameter token are checked. * * @param Token|array|string $other token or it's prototype * @param bool $caseSensitive perform a case sensitive comparison * * @return bool */ public function equals($other, $caseSensitive = true) { $otherPrototype = $other instanceof Token ? $other->getPrototype() : $other; if ($this->isArray() !== is_array($otherPrototype)) { return false; } if (!$this->isArray()) { return $this->content === $otherPrototype; } $selfPrototype = $this->getPrototype(); foreach ($otherPrototype as $key => $val) { // make sure the token has such key if (!isset($selfPrototype[$key])) { return false; } if (1 === $key && !$caseSensitive) { // case-insensitive comparison only applies to the content (key 1) if (0 !== strcasecmp($val, $selfPrototype[1])) { return false; } } else { // regular comparison if ($selfPrototype[$key] !== $val) { return false; } } } return true; }
public static function fromBaseToken(BaseToken $token) { $extended = new self($token->getPrototype()); if ($token->isChanged()) { $extended->setContent('__CHANGE_HOLDER__' . $token->getContent()); $extended->setContent($token->getContent()); } return $extended; }
/** * Override token. * * If called on Token inside Tokens collection please use `Tokens::overrideAt` instead. * * @param Token|array|string $other token prototype */ public function override($other) { $prototype = $other instanceof self ? $other->getPrototype() : $other; if ($this->equals($prototype)) { return; } $this->changed = true; if (is_array($prototype)) { $this->isArray = true; $this->id = $prototype[0]; $this->content = $prototype[1]; return; } $this->isArray = false; $this->id = null; $this->content = $prototype; }