PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 1.7.3
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v1.7.3
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.7.3, at framework/Foundation/Application.php

263 lines 5.7 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 * Static interface to initiate the application
66 * @param string $baseFile (root plugin file path)
67 * @param array $appConfig (/config/app.php)
68 * @return $this
69 */
70 public static function run($baseFile, $appConfig)
71 {
72 return new static($baseFile, $appConfig);
73 }
74
75 /**
76 * Init the application
77 * @param string $baseFile (root plugin file path)
78 * @param array $appConfig (/config/app.php)
79 */
80 public function __construct($baseFile, $appConfig)
81 {
82 $this->baseFile = $baseFile;
83 $this->appConfig = $appConfig;
84 $this->bootstrapApplication();
85 }
86
87 /**
88 * Bootup the application
89 * @param string $baseFile (root plugin file path)
90 * @param array $appConfig (/config/app.php)
91 * @return void
92 */
93 protected function bootstrapApplication()
94 {
95 $this->setAppBaseBindings();
96 $this->setExceptionHandler();
97 $this->loadApplicationTextDomain();
98 $this->bootstrapWith($this->getEngineProviders());
99 $this->fireCallbacks($this->engineBootedCallbacks);
100 $this->bootstrapWith($this->getPluginProviders());
101 $this->fireCallbacks($this->pluginReadyCallbacks);
102 }
103
104 /**
105 * Register application base bindings
106 * @return void
107 */
108 protected function setAppBaseBindings()
109 {
110 $this->bindAppInstance();
111 $this->registerAppPaths();
112 $this->registerAppUrls();
113 }
114
115 /**
116 * Bind application instance
117 * @return void
118 */
119 protected function bindAppInstance()
120 {
121 AppFacade::setApplication($this);
122 }
123
124 /**
125 * Set Application paths
126 * @return void
127 */
128 protected function registerAppPaths()
129 {
130 $path = plugin_dir_path($this->baseFile);
131 $this->bindInstance('path', $path);
132 $this->bindInstance('path.app', $path.'app/');
133 $this->bindInstance('path.config', $path.'config/');
134 $this->bindInstance('path.public', $path.'public/');
135 $this->bindInstance('path.framework', $path.'framework/');
136 $this->bindInstance('path.resource', $path.'resources/');
137 $this->bindInstance('path.storage', $path.'storage/');
138 $this->bindInstance('path.asset', $path.'resources/assets/');
139 $this->bindInstance('path.language', $path.'resources/languages/');
140 $this->bindInstance('path.view', $path.'resources/views/');
141 }
142
143 /**
144 * Set Application urls
145 * @return void
146 */
147 protected function registerAppUrls()
148 {
149 $url = plugin_dir_url($this->baseFile);
150 $this->bindInstance('url', $url);
151 $this->bindInstance('url.public', $url.'public/');
152 $this->bindInstance('url.resource', $url.'resources/');
153 $this->bindInstance('url.asset', $url.'resources/assets/');
154 }
155
156 /**
157 * Set Application Exception Handler
158 * @return void
159 */
160 protected function setExceptionHandler()
161 {
162 if (defined('WP_DEBUG') && WP_DEBUG) {
163 return new ExceptionHandler($this);
164 }
165 }
166
167 /**
168 * load languages path for i18n pot files
169 * @return bool
170 */
171 protected function loadApplicationTextDomain()
172 {
173 return load_plugin_textdomain(
174 $this->getTextDomain(), false, $this->languagePath()
175 );
176 }
177
178 /**
179 * Boot application with providers
180 * @param array $providers
181 * @return void
182 */
183 public function bootstrapWith(array $providers)
184 {
185 $instances = [];
186
187 foreach ($providers as $provider) {
188 $instances[] = $instance = new $provider($this);
189 $instance->booting();
190 }
191
192 if (!$this->isFacadeLoaderRegistered) {
193 $this->registerAppFacadeLoader();
194 }
195
196 foreach ($instances as $object) {
197 $object->booted();
198 }
199 }
200
201 /**
202 * Get engine/core providers
203 * @return array
204 */
205 public function getEngineProviders()
206 {
207 return $this->getProviders('core');
208 }
209
210 /**
211 * Get plugin providers (Common)
212 * @return array
213 */
214 public function getCommonProviders()
215 {
216 return $this->getProviders('plugin')['common'];
217 }
218
219 /**
220 * Get plugin providers (Backend|Frontend)
221 * @return array
222 */
223 public function getPluginProviders()
224 {
225 if ($this->isUserOnAdminArea()) {
226 return $this->getProviders('plugin')['backend'];
227 } else {
228 return $this->getProviders('plugin')['frontend'];
229 }
230 }
231
232 /**
233 * Register booted events
234 * @param mixed $callback
235 * @return void
236 */
237 public function booted($callback)
238 {
239 $this->engineBootedCallbacks[] = $this->parseHandler($callback);
240 }
241 /**
242 * Register ready events
243 * @param mixed $callback
244 * @return void
245 */
246 public function ready($callback)
247 {
248 $this->pluginReadyCallbacks[] = $this->parseHandler($callback);
249 }
250
251 /**
252 * Fire application event's handlers
253 * @param array $callbacks
254 * @return void
255 */
256 public function fireCallbacks(array $callbacks)
257 {
258 foreach ($callbacks as $callback) {
259 call_user_func_array($callback, [$this]);
260 }
261 }
262 }
263