PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.4.1
Fluent Support – Helpdesk & Customer Support Ticket System v1.4.1
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.4.1, at vendor/wpfluent/framework/src/WPFluent/Foundation/Application.php

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