From 65a95890b3c5909b75068ed7cc00737e5be4ebb4 Mon Sep 17 00:00:00 2001 From: Martynas Sudintas Date: Wed, 23 Sep 2015 12:58:06 +0000 Subject: [PATCH] rest request proxy now also carries repository type --- DependencyInjection/ONGRApiExtension.php | 2 +- Request/BatchProcessor.php | 1 + Request/RestRequest.php | 10 ++++++++ Request/RestRequestProxy.php | 25 +++++++++++++++++++ .../Routing/ElasticsearchLoaderTest.php | 20 +++++++-------- 5 files changed, 47 insertions(+), 11 deletions(-) diff --git a/DependencyInjection/ONGRApiExtension.php b/DependencyInjection/ONGRApiExtension.php index 2c22056..3d5596a 100644 --- a/DependencyInjection/ONGRApiExtension.php +++ b/DependencyInjection/ONGRApiExtension.php @@ -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'], ], diff --git a/Request/BatchProcessor.php b/Request/BatchProcessor.php index 2bfde18..53a3bf2 100644 --- a/Request/BatchProcessor.php +++ b/Request/BatchProcessor.php @@ -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']); } diff --git a/Request/RestRequest.php b/Request/RestRequest.php index c4f52e8..e46fc10 100644 --- a/Request/RestRequest.php +++ b/Request/RestRequest.php @@ -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'); + } } diff --git a/Request/RestRequestProxy.php b/Request/RestRequestProxy.php index a3e60ae..e2d338f 100644 --- a/Request/RestRequestProxy.php +++ b/Request/RestRequestProxy.php @@ -33,6 +33,11 @@ class RestRequestProxy extends RestRequest */ private $allowedExtraFields = false; + /** + * @var string + */ + private $type; + /** * {@inheritdoc} */ @@ -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. * diff --git a/Tests/Functional/Routing/ElasticsearchLoaderTest.php b/Tests/Functional/Routing/ElasticsearchLoaderTest.php index c64e14e..b276b0b 100644 --- a/Tests/Functional/Routing/ElasticsearchLoaderTest.php +++ b/Tests/Functional/Routing/ElasticsearchLoaderTest.php @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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,