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 / ComponentBinder.php

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

151 lines 3.7 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 FluentSupport\App\Api\Api;
6 use FluentSupport\Framework\View\View;
7 use FluentSupport\Framework\Http\Router;
8 use FluentSupport\Framework\Request\Request;
9 use FluentSupport\Framework\Response\Response;
10 use FluentSupport\Framework\Database\Orm\Model;
11 use FluentSupport\Framework\Validator\Validator;
12 use FluentSupport\Framework\Foundation\Dispatcher;
13 use FluentSupport\Framework\Foundation\RequestGuard;
14 use FluentSupport\Framework\Pagination\AbstractPaginator;
15 use FluentSupport\Framework\Database\ConnectionResolver;
16 use FluentSupport\Framework\Database\Query\WPDBConnection;
17 use FluentSupport\Framework\Foundation\UnAuthorizedException;
18
19 class ComponentBinder
20 {
21 protected $app = null;
22
23 protected $bindables = [
24 'Request',
25 'Response',
26 'Validator',
27 'View',
28 'Events',
29 'DataBase',
30 'Router',
31 'Paginator',
32 'Api'
33 ];
34
35 public function __construct($app)
36 {
37 $this->app = $app;
38 }
39
40 public function bindComponents()
41 {
42 foreach ($this->bindables as $value) {
43 $method = "bind{$value}";
44 $this->{$method}();
45 }
46
47 $this->extendBindings($this);
48 }
49
50 protected function bindRequest()
51 {
52 $this->app->singleton(Request::class, function ($app) {
53 return new Request($app, $_GET, $_POST, $_FILES);
54 });
55
56 $this->app->alias(Request::class, 'request');
57 }
58
59 protected function bindResponse()
60 {
61 $this->app->singleton(Response::class, function($app) {
62 return new Response($app);
63 });
64
65 $this->app->alias(Response::class, 'response');
66 }
67
68 protected function bindValidator()
69 {
70 $this->app->bind(Validator::class, function($app) {
71 return new Validator;
72 });
73
74 $this->app->alias(Validator::class, 'validator');
75 }
76
77 protected function bindView()
78 {
79 $this->app->bind(View::class, function($app) {
80 return new View($app);
81 });
82
83 $this->app->alias(View::class, 'view');
84 }
85
86 protected function bindEvents()
87 {
88 $this->app->singleton(Dispatcher::class, function($app) {
89 return new Dispatcher($app);
90 });
91
92 $this->app->alias(Dispatcher::class, 'events');
93 }
94
95 protected function bindDataBase()
96 {
97 $this->app->bindShared('db', function($app) {
98 return new WPDBConnection(
99 $GLOBALS['wpdb'], $app->config->get('database')
100 );
101 });
102
103 Model::setEventDispatcher($this->app['events']);
104
105 Model::setConnectionResolver(new ConnectionResolver);
106 }
107
108 protected function bindApi()
109 {
110 $this->app->singleton('FluentSupport\App\Api\Api', function ($app) {
111 return new Api($app);
112 });
113
114 $this->app->alias('FluentSupport\App\Api\Api', 'api');
115
116 }
117
118 protected function bindRouter()
119 {
120 $this->app->singleton('router', function($app) {
121 return new Router($app);
122 });
123 }
124
125 protected function bindPaginator()
126 {
127 AbstractPaginator::currentPathResolver(function () {
128 return $this->app['request']->url();
129 });
130
131 AbstractPaginator::currentPageResolver(function ($pageName = 'page') {
132 $page = $this->app['request']->get($pageName);
133
134 if (filter_var($page, FILTER_VALIDATE_INT) !== false && (int) $page >= 1) {
135 return $page;
136 }
137
138 return 1;
139 });
140 }
141
142 protected function extendBindings($app)
143 {
144 $bindings = $this->app['path'] . 'boot/bindings.php';
145
146 if (is_readable($bindings)) {
147 require_once $bindings;
148 }
149 }
150 }
151