diff options
Diffstat (limited to 'vendor/mikespub/php-epub-meta/src/Contents/NavPointList.php')
-rw-r--r-- | vendor/mikespub/php-epub-meta/src/Contents/NavPointList.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/vendor/mikespub/php-epub-meta/src/Contents/NavPointList.php b/vendor/mikespub/php-epub-meta/src/Contents/NavPointList.php new file mode 100644 index 000000000..540d2f876 --- /dev/null +++ b/vendor/mikespub/php-epub-meta/src/Contents/NavPointList.php @@ -0,0 +1,65 @@ +<?php + +namespace SebLucas\EPubMeta\Contents; + +use ArrayIterator; + +/** + * A list of EPUB TOC navigation points. + * + * @author Simon Schrape <simon@epubli.com> + * @author mikespub + * @extends ArrayIterator<int, NavPoint> + */ +class NavPointList extends ArrayIterator +{ + public function __construct() {} + + /** + * @return NavPoint + */ + public function first() + { + $this->rewind(); + return $this->current(); + } + + /** + * @return NavPoint + */ + public function last() + { + $this->seek($this->count() - 1); + return $this->current(); + } + + /** + * @param NavPoint $navPoint + * @return void + * @deprecated 2.1.0 use normal append() instead + */ + public function addNavPoint(NavPoint $navPoint) + { + $this->append($navPoint); + } + + /** + * @param string $file + * + * @return array|NavPoint[] + */ + public function findNavPointsForFile($file) + { + $matches = []; + foreach ($this as $navPoint) { + if ($navPoint->getContentSourceFile() == $file) { + $matches[] = $navPoint; + } + $childMatches = $navPoint->getChildren()->findNavPointsForFile($file); + if (count($childMatches)) { + $matches = array_merge($matches, $childMatches); + } + } + return $matches; + } +} |