summaryrefslogtreecommitdiff
path: root/app/EventBuilder/EventIteratorBuilder.php
blob: ba8217532d8ab08dc79a769e33fcba76d32616e3 (plain)
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
<?php

namespace Kanboard\EventBuilder;

use Iterator;

/**
 * Class EventIteratorBuilder
 *
 * @package Kanboard\EventBuilder
 * @author  Frederic Guillot
 */
class EventIteratorBuilder implements Iterator {
    private $position = 0;
    private $builders = array();

    /**
     * Set builder
     *
     * @access public
     * @param  BaseEventBuilder $builder
     * @return $this
     */
    public function withBuilder(BaseEventBuilder $builder)
    {
        $this->builders[] = $builder;
        return $this;
    }

    public function rewind() {
        $this->position = 0;
    }

    /**
     * @return BaseEventBuilder
     */
    public function current() {
        return $this->builders[$this->position];
    }

    public function key() {
        return $this->position;
    }

    public function next() {
        ++$this->position;
    }

    public function valid() {
        return isset($this->builders[$this->position]);
    }
}