1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types=1 ); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Abstract class for configuring BladeOne |
7
|
|
|
* |
8
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
9
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
10
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
11
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
12
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
13
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
14
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
15
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
16
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
17
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
18
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
19
|
|
|
* |
20
|
|
|
* @author Glynn Quelch <[email protected]> |
21
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License |
22
|
|
|
* @package PinkCrab\BladeOne_Provider |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace PinkCrab\BladeOne; |
26
|
|
|
|
27
|
|
|
use PinkCrab\Perique\Interfaces\Hookable; |
28
|
|
|
use PinkCrab\BladeOne\BladeOne_Provider; |
29
|
|
|
use PinkCrab\Loader\Hook_Loader; |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
abstract class Abstract_BladeOne_Config implements Hookable { |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The current view model. |
36
|
|
|
* |
37
|
|
|
* @var BladeOne_Provider|null |
38
|
|
|
*/ |
39
|
|
|
protected $renderable; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Registers the hook to configure bladeone |
43
|
|
|
* |
44
|
|
|
* @param Hook_Loader $loader |
45
|
|
|
* @return void |
46
|
|
|
*/ |
47
|
|
|
final public function register( Hook_Loader $loader ): void { |
48
|
|
|
$loader->action( 'wp_loaded', array( $this, 'configure_blade_handler' ), 10, 2 ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Sets renderable from DI when constructing. |
53
|
|
|
* |
54
|
|
|
* @param BladeOne_Provider $renderable |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
|
|
public function set_renderable( BladeOne_Provider $renderable ): void { |
58
|
|
|
$this->renderable = $renderable; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Will call the config class, if using BladeOne. |
63
|
|
|
* |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
|
|
final public function configure_blade_handler(): void { |
67
|
|
|
if ( ! is_null( $this->renderable ) && is_a( $this->renderable, BladeOne_Provider::class ) ) { |
68
|
|
|
$this->config( $this->renderable ); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Method to extend from to configure bladeone |
74
|
|
|
* |
75
|
|
|
* @param BladeOne_Provider $bladeone |
76
|
|
|
* @return void |
77
|
|
|
*/ |
78
|
|
|
abstract public function config( BladeOne_Provider $bladeone): void; |
79
|
|
|
} |
80
|
|
|
|