diff options
author | Nils Gotzhein <[email protected]> | 2021-08-17 22:18:46 +0200 |
---|---|---|
committer | Nils Gotzhein <[email protected]> | 2021-08-17 22:18:46 +0200 |
commit | b6b6771d8d7dcf13938d1578099074b0123a5d5e (patch) | |
tree | efd9e28718eff791dcaa7ffddbac44c38deedfb8 /plugins/af_readability/vendor/fivefilters/readability.php/src/Nodes/DOM/DOMNodeList.php | |
parent | a73e3bec45c5523910c711cf882976b71781ac9e (diff) |
pull latest readability-php via composer
Diffstat (limited to 'plugins/af_readability/vendor/fivefilters/readability.php/src/Nodes/DOM/DOMNodeList.php')
-rw-r--r-- | plugins/af_readability/vendor/fivefilters/readability.php/src/Nodes/DOM/DOMNodeList.php | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/plugins/af_readability/vendor/fivefilters/readability.php/src/Nodes/DOM/DOMNodeList.php b/plugins/af_readability/vendor/fivefilters/readability.php/src/Nodes/DOM/DOMNodeList.php new file mode 100644 index 000000000..5149c0b98 --- /dev/null +++ b/plugins/af_readability/vendor/fivefilters/readability.php/src/Nodes/DOM/DOMNodeList.php @@ -0,0 +1,82 @@ +<?php + +namespace andreskrey\Readability\Nodes\DOM; + +/** + * Class DOMNodeList. + * + * This is a fake DOMNodeList class that allows adding items to the list. The original class is static and the nodes + * are defined automagically when instantiating it. This fake version behaves exactly the same way but adds the function + * add() that allows to insert new DOMNodes into the DOMNodeList. + * + * It cannot extend the original DOMNodeList class because the functionality behind the property ->length is hidden + * from the user and cannot be extended, changed, or tweaked. + */ +class DOMNodeList implements \Countable, \IteratorAggregate +{ + /** + * @var array + */ + protected $items = []; + + /** + * @var int + */ + protected $length = 0; + + /** + * To allow access to length in the same way that DOMNodeList allows. + * + * {@inheritdoc} + */ + public function __get($name) + { + switch ($name) { + case 'length': + return $this->length; + default: + trigger_error(sprintf('Undefined property: %s::%s', static::class, $name)); + } + } + + /** + * @param DOMNode|DOMElement|DOMComment $node + * + * @return DOMNodeList + */ + public function add($node) + { + $this->items[] = $node; + $this->length++; + + return $this; + } + + /** + * @param int $offset + * + * @return DOMNode|DOMElement|DOMComment + */ + public function item(int $offset) + { + return $this->items[$offset]; + } + + /** + * @return int|void + */ + public function count(): int + { + return $this->length; + } + + /** + * To make it compatible with iterator_to_array() function. + * + * {@inheritdoc} + */ + public function getIterator(): \ArrayIterator + { + return new \ArrayIterator($this->items); + } +} |