Skip to content

Commit f96f2ae

Browse files
author
Martynas Sudintas
committed
Merge pull request #82 from martiis/proxy_type_fix
rest request proxy now also carries repository type
2 parents 940fb8e + 65a9589 commit f96f2ae

File tree

5 files changed

+47
-11
lines changed

5 files changed

+47
-11
lines changed

DependencyInjection/ONGRApiExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ public function generate()
123123
'url' => $this->formatUrl($name, $type),
124124
'defaults' => [
125125
'id' => null,
126-
'type' => strtolower($type),
127126
'manager' => $config['manager'],
128127
'repository' => $docConfig['name'],
128+
'_type' => strtolower($type),
129129
'_version' => $this->getVersion(),
130130
'_allow_extra_fields' => $docConfig['allow_extra_fields'],
131131
],

Request/BatchProcessor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ private function prepareProxy(RestRequestProxy $proxy, $body, $options)
165165
->get($options['manager'])
166166
->getRepository($options['repository'])
167167
)
168+
->setType($options['_type'])
168169
->setAllowedExtraFields($options['_allow_extra_fields']);
169170
}
170171

Request/RestRequest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,14 @@ public function isAllowedExtraFields()
208208
{
209209
return $this->getRequest()->attributes->get('_allow_extra_fields', false);
210210
}
211+
212+
/**
213+
* Returns using repository type.
214+
*
215+
* @return string|null
216+
*/
217+
public function getType()
218+
{
219+
return $this->getRequest()->attributes->get('_type');
220+
}
211221
}

Request/RestRequestProxy.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class RestRequestProxy extends RestRequest
3333
*/
3434
private $allowedExtraFields = false;
3535

36+
/**
37+
* @var string
38+
*/
39+
private $type;
40+
3641
/**
3742
* {@inheritdoc}
3843
*/
@@ -93,6 +98,26 @@ public function setAllowedExtraFields($allowedExtraFields)
9398
return $this;
9499
}
95100

101+
/**
102+
* {@inheritdoc}
103+
*/
104+
public function getType()
105+
{
106+
return $this->type;
107+
}
108+
109+
/**
110+
* @param string $type
111+
*
112+
* @return $this
113+
*/
114+
public function setType($type)
115+
{
116+
$this->type = $type;
117+
118+
return $this;
119+
}
120+
96121
/**
97122
* Initializes proxy rest request.
98123
*

Tests/Functional/Routing/ElasticsearchLoaderTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public function getTestLoadData()
3131
'GET',
3232
[
3333
'id' => null,
34-
'type' => 'person',
3534
'manager' => 'es.manager.default',
3635
'repository' => 'AcmeTestBundle:Person',
36+
'_type' => 'person',
3737
'_version' => 'v1',
3838
'_controller' => 'ongr_api.rest_controller:getAction',
3939
'_allow_extra_fields' => true,
@@ -45,9 +45,9 @@ public function getTestLoadData()
4545
'POST',
4646
[
4747
'id' => null,
48-
'type' => 'person',
4948
'manager' => 'es.manager.default',
5049
'repository' => 'AcmeTestBundle:Person',
50+
'_type' => 'person',
5151
'_version' => 'v1',
5252
'_controller' => 'ongr_api.rest_controller:postAction',
5353
'_allow_extra_fields' => true,
@@ -59,9 +59,9 @@ public function getTestLoadData()
5959
'POST',
6060
[
6161
'id' => null,
62-
'type' => 'person',
6362
'manager' => 'es.manager.not_default',
6463
'repository' => 'AcmeTestBundle:Person',
64+
'_type' => 'person',
6565
'_version' => 'v1',
6666
'_controller' => 'ongr_api.rest_controller:postAction',
6767
'_allow_extra_fields' => false,
@@ -73,9 +73,9 @@ public function getTestLoadData()
7373
'GET',
7474
[
7575
'id' => null,
76-
'type' => 'person',
7776
'manager' => 'es.manager.not_default',
7877
'repository' => 'AcmeTestBundle:Person',
78+
'_type' => 'person',
7979
'_version' => 'v1',
8080
'_controller' => 'ongr_api.rest_controller:getAction',
8181
'_allow_extra_fields' => false,
@@ -87,9 +87,9 @@ public function getTestLoadData()
8787
'PUT',
8888
[
8989
'id' => null,
90-
'type' => 'person',
9190
'manager' => 'es.manager.not_default',
9291
'repository' => 'AcmeTestBundle:Person',
92+
'_type' => 'person',
9393
'_version' => 'v1',
9494
'_controller' => 'ongr_api.rest_controller:putAction',
9595
'_allow_extra_fields' => false,
@@ -101,9 +101,9 @@ public function getTestLoadData()
101101
'DELETE',
102102
[
103103
'id' => null,
104-
'type' => 'person',
105104
'manager' => 'es.manager.not_default',
106105
'repository' => 'AcmeTestBundle:Person',
106+
'_type' => 'person',
107107
'_version' => 'v1',
108108
'_controller' => 'ongr_api.rest_controller:deleteAction',
109109
'_allow_extra_fields' => false,
@@ -115,9 +115,9 @@ public function getTestLoadData()
115115
'POST',
116116
[
117117
'id' => null,
118-
'type' => 'person',
119118
'manager' => 'es.manager.default',
120119
'repository' => 'AcmeTestBundle:Person',
120+
'_type' => 'person',
121121
'_version' => 'v2',
122122
'_controller' => 'ongr_api.rest_controller:postAction',
123123
'_allow_extra_fields' => true,
@@ -129,9 +129,9 @@ public function getTestLoadData()
129129
'GET',
130130
[
131131
'id' => null,
132-
'type' => 'person',
133132
'manager' => 'es.manager.default',
134133
'repository' => 'AcmeTestBundle:Person',
134+
'_type' => 'person',
135135
'_version' => 'v2',
136136
'_controller' => 'ongr_api.rest_controller:getAction',
137137
'_allow_extra_fields' => true,
@@ -143,9 +143,9 @@ public function getTestLoadData()
143143
'PUT',
144144
[
145145
'id' => null,
146-
'type' => 'person',
147146
'manager' => 'es.manager.default',
148147
'repository' => 'AcmeTestBundle:Person',
148+
'_type' => 'person',
149149
'_version' => 'v2',
150150
'_controller' => 'ongr_api.rest_controller:putAction',
151151
'_allow_extra_fields' => true,
@@ -157,9 +157,9 @@ public function getTestLoadData()
157157
'DELETE',
158158
[
159159
'id' => null,
160-
'type' => 'person',
161160
'manager' => 'es.manager.default',
162161
'repository' => 'AcmeTestBundle:Person',
162+
'_type' => 'person',
163163
'_version' => 'v2',
164164
'_controller' => 'ongr_api.rest_controller:deleteAction',
165165
'_allow_extra_fields' => true,

0 commit comments

Comments
 (0)