Completed
Branch Gutenberg/master (a5e5d1)
by
unknown
147:31 queued 134:10
created

BlockManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 2
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace EventEspresso\core\services\editor;
4
5
use EventEspresso\core\domain\entities\editor\BlockCollection;
6
use EventEspresso\core\domain\entities\editor\BlockInterface;
7
use EventEspresso\core\services\collections\CollectionInterface;
8
use EventEspresso\core\services\request\RequestInterface;
9
10
/**
11
 * Class BlockManager
12
 * Description
13
 *
14
 * @package EventEspresso\core\services\editor
15
 * @author  Brent Christensen
16
 * @since   $VID:$
17
 */
18
abstract class BlockManager
19
{
20
21
    /**
22
     * @var CollectionInterface|BlockInterface[] $blocks
23
     */
24
    protected $blocks;
25
26
    /**
27
     * @var RequestInterface $request
28
     */
29
    protected $request;
30
31
    /**
32
     * the post type that the current request applies to
33
     *
34
     * @var string $request_post_type
35
     */
36
    protected $request_post_type;
37
38
    /**
39
     * value of the 'page' $_GET param
40
     *
41
     * @var string $page
42
     */
43
    protected $page;
44
45
    /**
46
     * value of the 'action' $_GET param
47
     *
48
     * @var string $action
49
     */
50
    protected $action;
51
52
53
    /**
54
     * BlockManager constructor.
55
     *
56
     * @param BlockCollection $blocks
57
     * @param RequestInterface      $request
58
     */
59
    public function __construct(
60
        BlockCollection $blocks,
61
        RequestInterface $request
62
    ) {
63
        $this->blocks            = $blocks;
64
        $this->request           = $request;
65
        $this->request_post_type = $this->request->getRequestParam('post_type', '');
66
        $this->page              = $this->request->getRequestParam('page', '');
67
        $this->action            = $this->request->getRequestParam('action', '');
68
        add_action($this->initHook(), array($this, 'initialize'));
69
    }
70
71
72
    /**
73
     *  Returns the name of a hookpoint to be used to call initialize()
74
     *
75
     * @return string
76
     */
77
    abstract public function initHook();
78
79
80
    /**
81
     * Perform any early setup required for block editors to functions
82
     *
83
     * @return void
84
     */
85
    abstract public function initialize();
86
87
88
    /**
89
     * @return string
90
     */
91
    public function currentRequestPostType()
92
    {
93
        return $this->request_post_type;
94
    }
95
}
96