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 pathContentController.php
More file actions
165 lines (145 loc) · 4.75 KB
/
ContentController.php
File metadata and controls
165 lines (145 loc) · 4.75 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
<?php
namespace Bolt\Extension\Bolt\JsonApi\Controllers;
use Bolt\Extension\Bolt\JsonApi\Config\Config;
use Bolt\Extension\Bolt\JsonApi\Converter\Parameter\ParameterCollection;
use Silex\Application;
use Silex\ControllerCollection;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Class ContentController
*
* @package JSONAPI\Controllers
*/
class ContentController implements ControllerProviderInterface
{
/**
* @var Config
*/
private $config;
/**
* ContentController constructor.
*
* @param Config $config
*/
public function __construct(Config $config)
{
$this->config = $config;
}
/**
* Returns routes to connect to the given application.
*
* @param Application $app An Application instance
*
* @return ControllerCollection A ControllerCollection instance
*/
public function connect(Application $app)
{
/**
* @var $ctr \Silex\ControllerCollection
*/
$ctr = $app['controllers_factory'];
$ctr->get('/', [$this, 'root'])
->bind('jsonapi');
$ctr->get('/menu', [$this, 'menu'])
->bind('jsonapi.menu');
$ctr->get('/menu/{q}', [$this, 'menu'])
->bind('jsonapi.singleMenu');
$ctr->get('/taxonomy', [$this, 'taxonomy'])
->bind('jsonapi.taxonomy');
$ctr->get('/search', [$this, 'searchAll'])
->bind('jsonapi.searchAll')
->convert('parameters', 'jsonapi.converter:grabParameters');
$ctr->get('/{contentType}/search', [$this, 'searchContent'])
->bind('jsonapi.searchContent')
->convert('parameters', 'jsonapi.converter:grabParameters');
$ctr->get('/{contentType}/{slug}/{relatedContentType}', [$this, 'singleContent'])
->value('relatedContentType', null)
->assert('slug', '[a-zA-Z0-9_\-]+')
->bind('jsonapi.singleContent')
->convert('parameters', 'jsonapi.converter:grabParameters');
$ctr->get('/{contentType}', [$this, 'listContent'])
->bind('jsonapi.listContent')
->convert('parameters', 'jsonapi.converter:grabParameters');
return $ctr;
}
/**
* @param Application $app
* @param Request $request
*
* @return mixed
*/
public function root(Application $app, Request $request)
{
return $app['jsonapi.action.root']->handle($request);
}
/**
* @param Application $app
* @param Request $request
*
* @return mixed
*/
public function menu(Application $app, Request $request)
{
return $app['jsonapi.action.menu']->handle($request);
}
/**
* @param Application $app
* @param Request $request
*
* @return mixed
*/
public function taxonomy(Application $app, Request $request)
{
return $app['jsonapi.action.taxonomy']->handle($request);
}
/**
* @param Application $app
* @param Request $request
* @param ParameterCollection $parameters
*
* @return mixed
*/
public function searchAll(Application $app, Request $request, ParameterCollection $parameters)
{
return $app['jsonapi.action.search']->handle(null, $request, $parameters);
}
/**
* @param Application $app
* @param Request $request
* @param string $contentType
* @param ParameterCollection $parameters
*
* @return mixed
*/
public function searchContent(Application $app, Request $request, $contentType, ParameterCollection $parameters)
{
return $app['jsonapi.action.search']->handle($contentType, $request, $parameters);
}
/**
* @param Application $app
* @param Request $request
* @param string $contentType
* @param string $slug
* @param string $relatedContentType
* @param ParameterCollection $parameters
*
* @return mixed
*/
public function singleContent(Application $app, Request $request, $contentType, $slug, $relatedContentType, ParameterCollection $parameters)
{
return $app['jsonapi.action.single']->handle($contentType, $slug, $relatedContentType, $request, $parameters);
}
/**
* @param Application $app
* @param Request $request
* @param string $contentType
* @param ParameterCollection $parameters
*
* @return mixed
*/
public function listContent(Application $app, Request $request, $contentType, ParameterCollection $parameters)
{
return $app['jsonapi.action.contentlist']->handle($contentType, $request, $parameters);
}
}