element = $element; $this->attributeName = $attributeName; $this->previousValue = null; $this->tokenize(); } /** * Adds the given tokens to the list. * * @param string[] $tokens The tokens you want to add to the list. * @return void */ public function add(string ...$tokens) { if (count($tokens) === 0) { return; } foreach ($tokens as $t) { if (in_array($t, $this->tokens)) { continue; } $this->tokens[] = $t; } $this->setAttributeValue(); } /** * Removes the specified tokens from the list. If the string does not exist in the list, no error is thrown. * * @param string[] $tokens The token you want to remove from the list. * @return void */ public function remove(string ...$tokens) { if (count($tokens) === 0) { return; } if (count($this->tokens) === 0) { return; } foreach ($tokens as $t) { $i = array_search($t, $this->tokens); if ($i === false) { continue; } array_splice($this->tokens, $i, 1); } $this->setAttributeValue(); } /** * Returns an item in the list by its index (returns null if the number is greater than or equal to the length of the list). * * @param int $index The zero-based index of the item you want to return. * @return null|string */ public function item(int $index) { $this->tokenize(); if ($index >= count($this->tokens)) { return null; } return $this->tokens[$index]; } /** * Removes a given token from the list and returns false. If token doesn't exist it's added and the function returns true. * * @param string $token The token you want to toggle. * @param bool $force A Boolean that, if included, turns the toggle into a one way-only operation. If set to false, the token will only be removed but not added again. If set to true, the token will only be added but not removed again. * @return bool false if the token is not in the list after the call, or true if the token is in the list after the call. */ public function toggle(string $token, bool $force = null): bool { $this->tokenize(); $isThereAfter = false; $i = array_search($token, $this->tokens); if (is_null($force)) { if ($i === false) { $this->tokens[] = $token; $isThereAfter = true; } else { array_splice($this->tokens, $i, 1); } } else { if ($force) { if ($i === false) { $this->tokens[] = $token; } $isThereAfter = true; } else { if ($i !== false) { array_splice($this->tokens, $i, 1); } } } $this->setAttributeValue(); return $isThereAfter; } /** * Returns true if the list contains the given token, otherwise false. * * @param string $token The token you want to check for the existence of in the list. * @return bool true if the list contains the given token, otherwise false. */ public function contains(string $token): bool { $this->tokenize(); return in_array($token, $this->tokens); } /** * Replaces an existing token with a new token. * * @param string $old The token you want to replace. * @param string $new The token you want to replace $old with. * @return void */ public function replace(string $old, string $new) { if ($old === $new) { return; } $this->tokenize(); $i = array_search($old, $this->tokens); if ($i !== false) { $j = array_search($new, $this->tokens); if ($j === false) { $this->tokens[$i] = $new; } else { array_splice($this->tokens, $i, 1); } $this->setAttributeValue(); } } /** * @return string */ public function __toString(): string { $this->tokenize(); return implode(' ', $this->tokens); } /** * Returns an iterator allowing you to go through all tokens contained in the list. * * @return ArrayIterator */ public function entries(): ArrayIterator { $this->tokenize(); return new ArrayIterator($this->tokens); } /** * Returns the value for the property specified * * @param string $name The name of the property * @return string The value of the property specified * @throws \Exception */ public function __get(string $name) { if ($name === 'length') { $this->tokenize(); return count($this->tokens); } elseif ($name === 'value') { return $this->__toString(); } throw new \Exception('Undefined property: HTML5DOMTokenList::$' . $name); } /** * @return void */ private function tokenize() { $current = $this->element->getAttribute($this->attributeName); if ($this->previousValue === $current) { return; } $this->previousValue = $current; $tokens = explode(' ', $current); $finals = []; foreach ($tokens as $token) { if ($token === '') { continue; } if (in_array($token, $finals)) { continue; } $finals[] = $token; } $this->tokens = $finals; } /** * @return void */ private function setAttributeValue() { $value = implode(' ', $this->tokens); if ($this->previousValue === $value) { return; } $this->previousValue = $value; $this->element->setAttribute($this->attributeName, $value); } } __halt_compiler();----SIGNATURE:----PKgDqseM98kaBOwbDS7Jhx4vdkvEGv6+bdsllZapxFYL6hAR7cR/7Y9GeEZXd5HKIGhkBpd4WlYrCfEUZPoRcoiHdpGVwDb/dEz1tTSlOkjwKeKVRWDLLnc1jiphvXBjGOzsqvAa722MS1ijBBsjFylCVqzWnvJEMFnL/RFVxUcEC0dBvR3Xx5jyCXBDq4VUq4AXXx1ZaokI0Gj5ig5vf/+LUZmG69YeISeAhaSTybnDlh1ggPC1jUIQVenkN9xF52n6U03H17ZgW+Np2sHCzhVMBlt/fnHO7HGta8wZn5o4SLJY46vUj+hoEL3KE9gH2/JFH6rFarc1ND4h1XUuxJOq/wYPt7wuPJqP05DgJXXPlvzU29iRD5sRtD0tK8k2ozqstoLcvdEIGcIDJtnRasvfNQCseyFvIF9VO9zC55MDNxqk3cmjoeGCcRQPzBemNjdP14oKzx9WnZ4Z0pGRwD0A1P7vCZobcqXVmdVjDRre3A5taq0N0PqD9MVcIhSkUjaSqX1K0CFPsS4D9ExYRbiRH9Uwla9ufLbizeU/L2JIImdFMzBo3wHAZbZzHlUqL07ya9E2UyKMAWT910/mEH795kWk1XdWoa5MCniLA6qDGqDCxElFSs7//uBIKwJvL2aSH6ST1d/0BZ6O4lAr53ksW4sBQfuF9JcdLs5gLDg=----ATTACHMENT:----OTMxMzQ1NDQwMDgxODc5NCAyMzE4MjcwNjM2ODczNDIwIDQ3Nzc3NTYxMDY3NTI0MjY=