Skip to content

Commit

Permalink
Merge pull request #82 from martiis/proxy_type_fix
Browse files Browse the repository at this point in the history
rest request proxy now also carries repository type
  • Loading branch information
Martynas Sudintas committed Sep 23, 2015
2 parents 940fb8e + 65a9589 commit f96f2ae
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DependencyInjection/ONGRApiExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ public function generate()
'url' => $this->formatUrl($name, $type),
'defaults' => [
'id' => null,
'type' => strtolower($type),
'manager' => $config['manager'],
'repository' => $docConfig['name'],
'_type' => strtolower($type),
'_version' => $this->getVersion(),
'_allow_extra_fields' => $docConfig['allow_extra_fields'],
],
Expand Down
1 change: 1 addition & 0 deletions Request/BatchProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ private function prepareProxy(RestRequestProxy $proxy, $body, $options)
->get($options['manager'])
->getRepository($options['repository'])
)
->setType($options['_type'])
->setAllowedExtraFields($options['_allow_extra_fields']);
}

Expand Down
10 changes: 10 additions & 0 deletions Request/RestRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,14 @@ public function isAllowedExtraFields()
{
return $this->getRequest()->attributes->get('_allow_extra_fields', false);
}

/**
* Returns using repository type.
*
* @return string|null
*/
public function getType()
{
return $this->getRequest()->attributes->get('_type');
}
}
25 changes: 25 additions & 0 deletions Request/RestRequestProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class RestRequestProxy extends RestRequest
*/
private $allowedExtraFields = false;

/**
* @var string
*/
private $type;

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -93,6 +98,26 @@ public function setAllowedExtraFields($allowedExtraFields)
return $this;
}

/**
* {@inheritdoc}
*/
public function getType()
{
return $this->type;
}

/**
* @param string $type
*
* @return $this
*/
public function setType($type)
{
$this->type = $type;

return $this;
}

/**
* Initializes proxy rest request.
*
Expand Down
20 changes: 10 additions & 10 deletions Tests/Functional/Routing/ElasticsearchLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public function getTestLoadData()
'GET',
[
'id' => null,
'type' => 'person',
'manager' => 'es.manager.default',
'repository' => 'AcmeTestBundle:Person',
'_type' => 'person',
'_version' => 'v1',
'_controller' => 'ongr_api.rest_controller:getAction',
'_allow_extra_fields' => true,
Expand All @@ -45,9 +45,9 @@ public function getTestLoadData()
'POST',
[
'id' => null,
'type' => 'person',
'manager' => 'es.manager.default',
'repository' => 'AcmeTestBundle:Person',
'_type' => 'person',
'_version' => 'v1',
'_controller' => 'ongr_api.rest_controller:postAction',
'_allow_extra_fields' => true,
Expand All @@ -59,9 +59,9 @@ public function getTestLoadData()
'POST',
[
'id' => null,
'type' => 'person',
'manager' => 'es.manager.not_default',
'repository' => 'AcmeTestBundle:Person',
'_type' => 'person',
'_version' => 'v1',
'_controller' => 'ongr_api.rest_controller:postAction',
'_allow_extra_fields' => false,
Expand All @@ -73,9 +73,9 @@ public function getTestLoadData()
'GET',
[
'id' => null,
'type' => 'person',
'manager' => 'es.manager.not_default',
'repository' => 'AcmeTestBundle:Person',
'_type' => 'person',
'_version' => 'v1',
'_controller' => 'ongr_api.rest_controller:getAction',
'_allow_extra_fields' => false,
Expand All @@ -87,9 +87,9 @@ public function getTestLoadData()
'PUT',
[
'id' => null,
'type' => 'person',
'manager' => 'es.manager.not_default',
'repository' => 'AcmeTestBundle:Person',
'_type' => 'person',
'_version' => 'v1',
'_controller' => 'ongr_api.rest_controller:putAction',
'_allow_extra_fields' => false,
Expand All @@ -101,9 +101,9 @@ public function getTestLoadData()
'DELETE',
[
'id' => null,
'type' => 'person',
'manager' => 'es.manager.not_default',
'repository' => 'AcmeTestBundle:Person',
'_type' => 'person',
'_version' => 'v1',
'_controller' => 'ongr_api.rest_controller:deleteAction',
'_allow_extra_fields' => false,
Expand All @@ -115,9 +115,9 @@ public function getTestLoadData()
'POST',
[
'id' => null,
'type' => 'person',
'manager' => 'es.manager.default',
'repository' => 'AcmeTestBundle:Person',
'_type' => 'person',
'_version' => 'v2',
'_controller' => 'ongr_api.rest_controller:postAction',
'_allow_extra_fields' => true,
Expand All @@ -129,9 +129,9 @@ public function getTestLoadData()
'GET',
[
'id' => null,
'type' => 'person',
'manager' => 'es.manager.default',
'repository' => 'AcmeTestBundle:Person',
'_type' => 'person',
'_version' => 'v2',
'_controller' => 'ongr_api.rest_controller:getAction',
'_allow_extra_fields' => true,
Expand All @@ -143,9 +143,9 @@ public function getTestLoadData()
'PUT',
[
'id' => null,
'type' => 'person',
'manager' => 'es.manager.default',
'repository' => 'AcmeTestBundle:Person',
'_type' => 'person',
'_version' => 'v2',
'_controller' => 'ongr_api.rest_controller:putAction',
'_allow_extra_fields' => true,
Expand All @@ -157,9 +157,9 @@ public function getTestLoadData()
'DELETE',
[
'id' => null,
'type' => 'person',
'manager' => 'es.manager.default',
'repository' => 'AcmeTestBundle:Person',
'_type' => 'person',
'_version' => 'v2',
'_controller' => 'ongr_api.rest_controller:deleteAction',
'_allow_extra_fields' => true,
Expand Down

0 comments on commit f96f2ae

Please sign in to comment.