PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.5.5
Fluent Support – Helpdesk & Customer Support Ticket System v1.5.5
2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 68 releases
fluent-support / vendor / wpfluent / framework / src / WPFluent / Foundation / Application.php

Application.php in Fluent Support – Helpdesk & Customer Support Ticket System 1.5.5, at vendor/wpfluent/framework/src/WPFluent/Foundation/Application.php

151 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\Framework\Foundation;
4
5 use InvalidArgumentException;
6 use FluentSupport\Framework\Foundation\Config;
7 use FluentSupport\Framework\Foundation\Container;
8 use FluentSupport\Framework\Foundation\FoundationTrait;
9 use FluentSupport\Framework\Foundation\ComponentBinder;
10 use FluentSupport\App\Api\Api;
11
12 class Application extends Container
13 {
14 use FoundationTrait;
15
16 protected $file = null;
17 protected $baseUrl = null;
18 protected $basePath = null;
19 protected $handlerNamespace = null;
20 protected $controllerNamespace = null;
21 protected $permissionNamespace = null;
22
23 public function __construct($file = null)
24 {
25 $this->init($file);
26 $this->setAppLevelNamespace();
27 $this->bootstrapApplication();
28 }
29
30 protected function init($file)
31 {
32 $this->file = $this->pluginFilePath($file);
33 $this->basePath = plugin_dir_path($this->file);
34 $this->baseUrl = plugin_dir_url($this->file);
35 }
36
37 protected function pluginFilePath($file)
38 {
39 $file = $file ?: realpath(__DIR__ . '/../../../plugin.php');
40
41 return $file;
42 }
43
44 protected function setAppLevelNamespace()
45 {
46 $autoload = $this->getComposer('autoload');
47
48 $psr4 = array_flip($autoload['psr-4']);
49
50 $this->handlerNamespace = $psr4['app/'] . 'Hooks\Handlers';
51
52 $this->policyNamespace = $psr4['app/'] . 'Http\Policies';
53
54 $this->controllerNamespace = $psr4['app/'] . 'Http\Controllers';
55 }
56
57 protected function getComposer($section = null)
58 {
59 $data = json_decode(
60 file_get_contents($this->basePath . 'composer.json'), true
61 );
62
63 return $section ? $data[$section] : $data;
64 }
65
66 protected function bootstrapApplication()
67 {
68 $this->bindAppInstance();
69 $this->bindPathsAndUrls();
70 $this->loadConfigIfExists();
71 // $this->loadTextdomain();
72 $this->bindComponents($this);
73 $this->requireCommonFiles($this);
74 }
75
76 protected function bindAppInstance()
77 {
78 App::setInstance($this);
79 $this->instance('app', $this);
80 $this->instance(__CLASS__, $this);
81 }
82
83 protected function bindPathsAndUrls()
84 {
85 $this->bindUrls();
86 $this->basePaths();
87 }
88
89 protected function bindUrls()
90 {
91 $this['url.assets'] = $this->baseUrl . 'assets/';
92 }
93
94 protected function basePaths()
95 {
96 $this['path'] = $this->basePath;
97 $this['path.app'] = $this->basePath . 'app/';
98 $this['path.hooks'] = $this['path.app'] . 'Hooks/';
99 $this['path.http'] = $this['path.app'] . 'Http/';
100 $this['path.controllers'] = $this['path.http'] . 'Controllers/';
101 $this['path.config'] = $this->basePath . 'config/';
102 $this['path.assets'] = $this->basePath . 'assets/';
103 $this['path.resources'] = $this->basePath . 'resources/';
104 $this['path.views'] = $this['path.app'] . 'views/';
105 }
106
107 protected function loadConfigIfExists()
108 {
109 $data = [];
110
111 if (is_dir($this['path.config'])) {
112 foreach (glob($this['path.config'] . '*.php') as $file) {
113 $data[basename($file, '.php')] = require_once($file);
114 }
115 }
116
117 $this->instance('config', new Config($data));
118 }
119
120 protected function loadTextdomain()
121 {
122 $this->addAction('init', function() {
123 load_plugin_textdomain(
124 $this->config->get('app.text_domain'), false, $this->config->get('app.domain_path')
125 );
126 });
127 }
128
129 protected function bindComponents($app)
130 {
131 (new ComponentBinder($app))->bindComponents();
132 }
133
134 protected function requireCommonFiles($app)
135 {
136 require_once $this->basePath . 'app/Hooks/actions.php';
137 require_once $this->basePath . 'app/Hooks/filters.php';
138 require_once $this->basePath . 'app/Api/FsFunctions.php';
139
140 $this->addAction('rest_api_init', function($wpRestServer) use ($app) {
141 try {
142 $router = $app->router;
143 require_once $this->basePath . 'app/Http/Routes/api.php';
144 $router->registerRoutes();
145 } catch (InvalidArgumentException $e) {
146 $app->doCustomAction('handle_exception', $e);
147 }
148 });
149 }
150 }
151