Completed
Branch BUG/reg-status-change-recursio... (2db0c9)
by
unknown
20:03 queued 10:32
created

BlockCollection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace EventEspresso\core\domain\entities\editor;
4
5
use EventEspresso\core\exceptions\InvalidInterfaceException;
6
use EventEspresso\core\services\collections\Collection;
7
8
/**
9
 * Class BlockCollection
10
 * a Collection of Block objects
11
 *
12
 * @package EventEspresso\core\services\editor
13
 * @author  Brent Christensen
14
 * @since   $VID:$
15
 */
16
class BlockCollection extends Collection
17
{
18
19
    /**
20
     * Collection constructor
21
     *
22
     * @throws InvalidInterfaceException
23
     */
24
    public function __construct()
25
    {
26
        parent::__construct('EventEspresso\core\domain\entities\editor\BlockInterface');
27
    }
28
29
30
    /**
31
     * unRegisterBlock
32
     * finds block in the Collection based on the identifier that was set using addObject()
33
     * and calls unRegisterBlock() on it. Returns block if successful and false if block was not found.
34
     * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards
35
     *
36
     * @param mixed $identifier
37
     * @return boolean
38
     */
39 View Code Duplication
    public function unRegisterBlock($identifier)
40
    {
41
        $this->rewind();
42
        while ($this->valid()) {
43
            if ($identifier === $this->getInfo()) {
44
                $object = $this->current();
45
                $this->rewind();
46
                return $object->unRegisterBlock();
47
            }
48
            $this->next();
49
        }
50
        return false;
51
    }
52
53
54
    /**
55
     * unRegisterAllBlocks
56
     * calls unRegisterBlock() on all blocks in Collection.
57
     * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards
58
     *
59
     * @return void
60
     */
61
    public function unRegisterAllBlocks()
62
    {
63
        $this->rewind();
64
        while ($this->valid()) {
65
            $this->current()->unRegisterBlock();
66
            $this->next();
67
        }
68
        $this->rewind();
69
    }
70
}
71