This repository was archived by the owner on Dec 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathAPIProvider.php
More file actions
214 lines (193 loc) · 6.38 KB
/
APIProvider.php
File metadata and controls
214 lines (193 loc) · 6.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
namespace Bolt\Extension\Bolt\JsonApi\Provider;
use Bolt\Composer\Package;
use Bolt\Composer\PackageCollection;
use Bolt\Extension\Bolt\JsonApi\Action\ContentListAction;
use Bolt\Extension\Bolt\JsonApi\Action\MenuAction;
use Bolt\Extension\Bolt\JsonApi\Action\SearchAction;
use Bolt\Extension\Bolt\JsonApi\Action\SingleAction;
use Bolt\Extension\Bolt\JsonApi\Action\TaxonomyAction;
use Bolt\Extension\Bolt\JsonApi\Config\Config;
use Bolt\Extension\Bolt\JsonApi\Converter\JSONAPIConverter;
use Bolt\Extension\Bolt\JsonApi\Helpers\DataLinks;
use Bolt\Extension\Bolt\JsonApi\Parser\Parser;
use Bolt\Extension\Bolt\JsonApi\Storage\Query\Handler\Directive\PagerHandler;
use Bolt\Extension\Bolt\JsonApi\Storage\Query\Handler\PagingHandler;
use Silex\Application;
use Silex\ServiceProviderInterface;
use Bolt\Storage\Query\ContentQueryParser;
use Bolt\Extension\Bolt\JsonApi\Action\RootAction;
/**
* Class APIProvider
*
* @package JSONAPI\Provider
*/
class APIProvider implements ServiceProviderInterface
{
/** @var array */
private $config;
/**
* Constructor.
*
* @param array $config
*/
public function __construct(array $config)
{
$this->config = $config;
}
/**
* Registers services on the given app.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param Application $app
*/
public function register(Application $app)
{
/**
* The main configuration class
*/
$app['jsonapi.config'] = $app->share(
function ($app) {
return new Config($this->config, $app);
}
);
/**
* Param converter to handle JSONAPI spec.
* For example:
* filters, contains, sort, includes, page[number], and page[size]
*/
$app['jsonapi.converter'] = $app->share(
function ($app) {
return new JSONAPIConverter(
$app['jsonapi.config'],
$app['storage.metadata']
);
}
);
/**
* Class to handle parsing of individual items
*
* @todo Refactor to include individual parsers based upon the field type
*/
$app['jsonapi.parser'] = $app->share(
function ($app) {
return new Parser(
$app['jsonapi.config'],
$app['resources'],
$app['storage.metadata'],
$app['users']
);
}
);
/**
* Simple class to handle linking to related items and the current content type
*
* @todo Refactor...
*/
$app['jsonapi.datalinks'] = $app->share(
function ($app) {
return new DataLinks($app['jsonapi.config']);
}
);
/**
* Add controller actions to DI container
*/
$app['jsonapi.action.contentlist'] = $app->share(
function ($app) {
return new ContentListAction(
$app['query'],
$app['jsonapi.parser'],
$app['jsonapi.datalinks'],
$app['jsonapi.config']
);
}
);
$app['jsonapi.action.search'] = $app->share(
function ($app) {
return new SearchAction(
$app['query'],
$app['jsonapi.parser'],
$app['jsonapi.datalinks'],
$app['jsonapi.config']
);
}
);
$app['jsonapi.action.single'] = $app->share(
function ($app) {
return new SingleAction(
$app['query'],
$app['jsonapi.parser'],
$app['jsonapi.datalinks'],
$app['jsonapi.config']
);
}
);
$app['jsonapi.action.menu'] = $app->share(
function ($app) {
return new MenuAction(
$app['config'],
$app['jsonapi.config'],
$app['jsonapi.datalinks']
);
}
);
$app['jsonapi.action.root'] = $app->share(
function ($app) {
$boltVersion = $app['bolt_version'];
/** @var PackageCollection $jsonapiVersion */
$jsonAPIVersion = $app['extend.manager']->getAllPackages();
/** @var Package $jsonapiVersion */
$jsonAPIVersion = $jsonAPIVersion->get('bolt/jsonapi');
//Get exact version
$jsonAPIVersion = $jsonAPIVersion->jsonSerialize()['version'];
return new RootAction(
$app['config'],
$app['jsonapi.config'],
$boltVersion,
$jsonAPIVersion
);
}
);
$app['jsonapi.action.taxonomy'] = $app->share(
function ($app) {
return new TaxonomyAction(
$app['config'],
$app['jsonapi.config']
);
}
);
/**
* Add repository and query parsers to handle pagination to DI
*/
$app['storage.content_repository'] = $app->protect(
function ($classMetadata) use ($app) {
$repoClass = 'Bolt\Extension\Bolt\JsonApi\Storage\Repository';
$repo = new $repoClass($app['storage'], $classMetadata);
$repo->setLegacyService($app['storage.legacy_service']);
return $repo;
}
);
$app['query.parser'] = $app->share(
$app->extend('query.parser', function (ContentQueryParser $parser) {
$parser->addDirectiveHandler('paginate', new PagerHandler());
$parser->addHandler('pager', new PagingHandler());
$parser->addOperation('pager');
return $parser;
})
);
}
/**
* Bootstraps the application.
*
* This method is called after all services are registered
* and should be used for "dynamic" configuration (whenever
* a service must be requested).
*
* @param Application $app
*/
public function boot(Application $app)
{
}
}