1 | <?php namespace Intraxia\Jaxion\Core; |
||
15 | class Application extends Container implements ApplicationContract { |
||
16 | /** |
||
17 | * Define plugin version on Application. |
||
18 | */ |
||
19 | const VERSION = ''; |
||
20 | |||
21 | /** |
||
22 | * Singleton instance of the Application object |
||
23 | * |
||
24 | * @var Application[] |
||
25 | */ |
||
26 | protected static $instances = array(); |
||
27 | |||
28 | /** |
||
29 | * Instantiates a new Application container. |
||
30 | * |
||
31 | * The Application constructor enforces the presence of of a single instance |
||
32 | * of the Application. If an instance already exists, an Exception will be thrown. |
||
33 | * |
||
34 | * @param Config $config |
||
35 | * @param array $providers |
||
36 | * |
||
37 | * @throws ApplicationAlreadyBootedException |
||
38 | */ |
||
39 | 27 | public function __construct( $config, array $providers = array() ) { |
|
40 | 27 | if ( isset( static::$instances[ get_called_class() ] ) ) { |
|
41 | 3 | throw new ApplicationAlreadyBootedException; |
|
42 | } |
||
43 | |||
44 | 27 | static::$instances[ get_called_class() ] = $this; |
|
45 | |||
46 | 27 | if ( ! ( $config instanceof Config ) ) { |
|
47 | $config = new Config( ConfigType::PLUGIN, $config ); |
||
48 | } |
||
49 | |||
50 | 27 | $this->register_constants( $config ); |
|
51 | 27 | $this->register_core_services( $config ); |
|
52 | |||
53 | 27 | register_activation_hook( $config->file, array( $this, 'activate' ) ); |
|
54 | 27 | register_deactivation_hook( $config->file, array( $this, 'deactivate' ) ); |
|
55 | |||
56 | 27 | parent::__construct( $providers ); |
|
57 | 27 | } |
|
58 | |||
59 | /** |
||
60 | * {@inheritDoc} |
||
61 | * |
||
62 | * @throws UnexpectedValueException |
||
63 | */ |
||
64 | 12 | public function boot() { |
|
65 | 12 | $loader = $this->fetch( 'loader' ); |
|
66 | |||
67 | 12 | if ( ! ( $loader instanceof LoaderContract ) ) { |
|
68 | 3 | throw new UnexpectedValueException; |
|
69 | } |
||
70 | |||
71 | 9 | foreach ( $this as $alias => $value ) { |
|
72 | 9 | if ( $value instanceof HasActions ) { |
|
73 | 9 | $loader->register_actions( $value ); |
|
74 | 9 | } |
|
75 | |||
76 | 9 | if ( $value instanceof HasFilters ) { |
|
77 | 3 | $loader->register_filters( $value ); |
|
78 | 3 | } |
|
79 | |||
80 | 9 | if ( $value instanceof HasShortcode ) { |
|
81 | 3 | $loader->register_shortcode( $value ); |
|
82 | 3 | } |
|
83 | 9 | } |
|
84 | |||
85 | 9 | add_action( 'plugins_loaded', array( $loader, 'run' ) ); |
|
86 | 9 | } |
|
87 | |||
88 | /** |
||
89 | * {@inheritdoc} |
||
90 | * |
||
91 | * @codeCoverageIgnore |
||
92 | */ |
||
93 | public function activate() { |
||
96 | |||
97 | /** |
||
98 | * {@inheritdoc} |
||
99 | * |
||
100 | * @codeCoverageIgnore |
||
101 | */ |
||
102 | public function deactivate() { |
||
105 | |||
106 | /** |
||
107 | * {@inheritDoc} |
||
108 | * |
||
109 | * @return Application |
||
110 | * @throws ApplicationNotBootedException |
||
111 | */ |
||
112 | 9 | public static function instance() { |
|
119 | |||
120 | /** |
||
121 | * {@inheritDoc} |
||
122 | */ |
||
123 | 30 | public static function shutdown() { |
|
128 | |||
129 | /** |
||
130 | * Sets the plugin's url, path, and basename. |
||
131 | * |
||
132 | * @param Config $config |
||
133 | */ |
||
134 | 27 | private function register_constants( Config $config ) { |
|
152 | |||
153 | /** |
||
154 | * Registers the built-in services with the Application container. |
||
155 | * |
||
156 | * @param Config $config |
||
157 | */ |
||
158 | 27 | private function register_core_services( Config $config ) { |
|
167 | } |
||
168 |