PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 1.2.4
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v1.2.4
6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 3.6.66 All 195 releases
fluentform / framework / Foundation / Application.php

Application.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 1.2.4, at framework/Foundation/Application.php

252 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * This file is part of the Glue WordPress plugin framework.
5 *
6 * @package Glue
7 * @link https://github.com/wpglue
8 * @author Sheikh Heera <heera.sheikh77@gmail.com>
9 * @license https://github.com/wpglue/framework/blob/master/LICENSE
10 */
11
12 namespace FluentForm\Framework\Foundation;
13
14 use FluentForm\Framework\Exception\ExceptionHandler;
15
16 class Application extends Container
17 {
18 use PathsAndUrlsTrait, SetGetAttributesTrait, FacadeLoaderTrait, HelpersTrait;
19
20 /**
21 * Framework Version
22 */
23 const VERSION = '1.0.0';
24
25 /**
26 * $baseFile root plugin file path
27 * @var string
28 */
29 protected $baseFile = null;
30
31 /**
32 * The app config (/config/app.php)
33 * @var array
34 */
35 protected $appConfig = null;
36
37 /**
38 * Callbacks for framework's booted event
39 * @var array
40 */
41 protected $engineBootedCallbacks = array();
42
43 /**
44 * Callbacks for framework's ready event
45 * @var array
46 */
47 protected $pluginReadyCallbacks = array();
48
49 /**
50 * A flag to register the dynamic facade loader once
51 * @var boolean
52 */
53 protected $isFacadeLoaderRegistered = false;
54
55 /**
56 * Get application version
57 * @return string
58 */
59 public function version()
60 {
61 return self::VERSION;
62 }
63
64 /**
65 * Init the application
66 * @param string $baseFile (root plugin file path)
67 * @param array $appConfig (/config/app.php)
68 */
69 public function __construct($baseFile, $appConfig)
70 {
71 $this->baseFile = $baseFile;
72 $this->appConfig = $appConfig;
73 $this->bootstrapApplication();
74 }
75
76 /**
77 * Bootup the application
78 * @param string $baseFile (root plugin file path)
79 * @param array $appConfig (/config/app.php)
80 * @return void
81 */
82 protected function bootstrapApplication()
83 {
84 $this->setAppBaseBindings();
85 $this->setExceptionHandler();
86 $this->loadApplicationTextDomain();
87 $this->bootstrapWith($this->getEngineProviders());
88 $this->fireCallbacks($this->engineBootedCallbacks);
89 $this->bootstrapWith($this->getPluginProviders());
90 $this->fireCallbacks($this->pluginReadyCallbacks);
91 }
92
93 /**
94 * Register application base bindings
95 * @return void
96 */
97 protected function setAppBaseBindings()
98 {
99 $this->bindAppInstance();
100 $this->registerAppPaths();
101 $this->registerAppUrls();
102 }
103
104 /**
105 * Bind application instance
106 * @return void
107 */
108 protected function bindAppInstance()
109 {
110 AppFacade::setApplication($this);
111 }
112
113 /**
114 * Set Application paths
115 * @return void
116 */
117 protected function registerAppPaths()
118 {
119 $path = plugin_dir_path($this->baseFile);
120 $this->bindInstance('path', $path);
121 $this->bindInstance('path.app', $path.'app/');
122 $this->bindInstance('path.config', $path.'config/');
123 $this->bindInstance('path.public', $path.'public/');
124 $this->bindInstance('path.framework', $path.'framework/');
125 $this->bindInstance('path.resource', $path.'resources/');
126 $this->bindInstance('path.storage', $path.'storage/');
127 $this->bindInstance('path.asset', $path.'resources/assets/');
128 $this->bindInstance('path.language', $path.'resources/languages/');
129 $this->bindInstance('path.view', $path.'resources/views/');
130 }
131
132 /**
133 * Set Application urls
134 * @return void
135 */
136 protected function registerAppUrls()
137 {
138 $url = plugin_dir_url($this->baseFile);
139 $this->bindInstance('url', $url);
140 $this->bindInstance('url.public', $url.'public/');
141 $this->bindInstance('url.resource', $url.'resources/');
142 $this->bindInstance('url.asset', $url.'resources/assets/');
143 }
144
145 /**
146 * Set Application Exception Handler
147 * @return void
148 */
149 protected function setExceptionHandler()
150 {
151 if (defined('WP_DEBUG') && WP_DEBUG && $this->getEnv() == 'dev') {
152 return new ExceptionHandler($this);
153 }
154 }
155
156 /**
157 * load languages path for i18n pot files
158 * @return bool
159 */
160 protected function loadApplicationTextDomain()
161 {
162 return load_plugin_textdomain(
163 $this->getTextDomain(), false, $this->languagePath()
164 );
165 }
166
167 /**
168 * Boot application with providers
169 * @param array $providers
170 * @return void
171 */
172 public function bootstrapWith(array $providers)
173 {
174 $instances = [];
175
176 foreach ($providers as $provider) {
177 $instances[] = $instance = new $provider($this);
178 $instance->booting();
179 }
180
181 if (!$this->isFacadeLoaderRegistered) {
182 $this->registerAppFacadeLoader();
183 }
184
185 foreach ($instances as $object) {
186 $object->booted();
187 }
188 }
189
190 /**
191 * Get engine/core providers
192 * @return array
193 */
194 public function getEngineProviders()
195 {
196 return $this->getProviders('core');
197 }
198
199 /**
200 * Get plugin providers (Common)
201 * @return array
202 */
203 public function getCommonProviders()
204 {
205 return $this->getProviders('plugin')['common'];
206 }
207
208 /**
209 * Get plugin providers (Backend|Frontend)
210 * @return array
211 */
212 public function getPluginProviders()
213 {
214 if ($this->isUserOnAdminArea()) {
215 return $this->getProviders('plugin')['backend'];
216 } else {
217 return $this->getProviders('plugin')['frontend'];
218 }
219 }
220
221 /**
222 * Register booted events
223 * @param mixed $callback
224 * @return void
225 */
226 public function booted($callback)
227 {
228 $this->engineBootedCallbacks[] = $this->parseHandler($callback);
229 }
230 /**
231 * Register ready events
232 * @param mixed $callback
233 * @return void
234 */
235 public function ready($callback)
236 {
237 $this->pluginReadyCallbacks[] = $this->parseHandler($callback);
238 }
239
240 /**
241 * Fire application event's handlers
242 * @param array $callbacks
243 * @return void
244 */
245 public function fireCallbacks(array $callbacks)
246 {
247 foreach ($callbacks as $callback) {
248 call_user_func_array($callback, [$this]);
249 }
250 }
251 }
252