PluginProbe
Boxzilla – WordPress Popup Builder / 3.2.14
Boxzilla – WordPress Popup Builder v3.2.14
3.4.11 3.4.10 3.4.9 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 trunk 3.0 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 All 72 releases
boxzilla / src / class-bootstrapper.php

class-bootstrapper.php in Boxzilla – WordPress Popup Builder 3.2.14, at src/class-bootstrapper.php

106 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Boxzilla;
4
5 use InvalidArgumentException;
6
7 /**
8 * Class Bootstrapper
9 * @package Boxzilla
10 *
11 * @method void admin( callable $callback )
12 * @method void cron( callable $callback )
13 * @method void front( callable $callback )
14 * @method void ajax( callable $callback )
15 * @method void cli( callable $callback )
16 */
17 class Bootstrapper
18 {
19
20 /**
21 * @var array
22 */
23 private $bootstrappers = array(
24 'admin' => array(),
25 'ajax' => array(),
26 'cli' => array(),
27 'cron' => array(),
28 'front' => array(),
29 'global' => array(),
30 );
31
32 /**
33 * @param string $section
34 * @param callable $callable
35 */
36 public function register($section, $callable)
37 {
38 if (! isset($this->bootstrappers[ $section ])) {
39 throw new InvalidArgumentException("Section $section is invalid.");
40 }
41
42 if (! is_callable($callable)) {
43 throw new InvalidArgumentException('Callable argument is not callable.');
44 }
45
46 $this->bootstrappers[ $section ][] = $callable;
47 }
48
49 /**
50 * @param string $name
51 * @param array $arguments
52 */
53 public function __call($name, $arguments)
54 {
55 if (isset($this->bootstrappers[ $name ])) {
56 $this->register($name, $arguments[0]);
57 }
58 }
59
60 /**
61 * Run registered bootstrappers
62 *
63 * @param string $section
64 */
65 public function run($section = '')
66 {
67 if (! $section) {
68 $section = $this->section();
69 }
70
71 // call all global callbacks
72 foreach ($this->bootstrappers['global'] as $callback) {
73 $callback();
74 }
75
76 // call section specific callbacks
77 foreach ($this->bootstrappers[ $section ] as $callback) {
78 $callback();
79 }
80 }
81
82 /**
83 * Get currently active section.
84 *
85 * @return string
86 */
87 public function section()
88 {
89 if (is_admin()) {
90 if (defined('DOING_AJAX') && DOING_AJAX) {
91 return 'ajax';
92 } else {
93 return 'admin';
94 }
95 } else {
96 if (defined('DOING_CRON') && DOING_CRON) {
97 return 'cron';
98 } elseif (defined('WP_CLI') && WP_CLI) {
99 return 'cli';
100 } else {
101 return 'front';
102 }
103 }
104 }
105 }
106