aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/mikespub/php-epub-meta/src/Contents/NavPointList.php
blob: 540d2f87638c54548da5585adb45f215c1beb994 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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;
    }
}