Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
fix entity fields
Browse files Browse the repository at this point in the history
  • Loading branch information
rodsouto committed Jan 11, 2016
1 parent b924464 commit f5c1648
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 20 deletions.
22 changes: 3 additions & 19 deletions src/ApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,10 @@ public function createService(Api $api, $serviceName)
}

$fields = [];
if (isset($this->config['zf-content-validation'][$serviceClassName]['input_filter'])) {
$validatorName = $this->config['zf-content-validation'][$serviceClassName]['input_filter'];
if (isset($this->config['input_filter_specs'][$validatorName])) {
if (isset($this->config['zf-content-validation'][$serviceClassName])) {
foreach($this->config['zf-content-validation'][$serviceClassName] as $validatorKey => $validatorName) {
foreach ($this->mapFields($this->config['input_filter_specs'][$validatorName]) as $fieldData) {
$fields['input_filter'][] = $this->getField($fieldData);
$fields[$validatorKey][] = $this->getField($fieldData);
}
$hasFields = true;
}
Expand All @@ -217,21 +216,6 @@ public function createService(Api $api, $serviceName)
$op = new Operation();
$op->setHttpMethod($httpMethod);

if (isset($this->config['zf-content-validation'][$serviceClassName][$httpMethod])) {
$validatorName = $this->config['zf-content-validation'][$serviceClassName][$httpMethod];
if (isset($this->config['input_filter_specs'][$validatorName])) {
foreach ($this->config['input_filter_specs'][$validatorName] as $fieldData) {
$fields[$httpMethod][] = $field = new Field();
$field->setName($fieldData['name']);
if (isset($fieldData['description'])) {
$field->setDescription($fieldData['description']);
}
$field->setRequired($fieldData['required']);
}
$hasFields = true;
}
}

if ($isRest) {
$description = isset($docsArray[$serviceClassName]['collection'][$httpMethod]['description'])
? $docsArray[$serviceClassName]['collection'][$httpMethod]['description']
Expand Down
13 changes: 12 additions & 1 deletion test/ApiFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function testCreateApi()

$this->assertEquals('Test', $api->getName());
$this->assertEquals(1, $api->getVersion());
$this->assertCount(4, $api->getServices());
$this->assertCount(5, $api->getServices());
}

public function testCreateRestService()
Expand Down Expand Up @@ -262,4 +262,15 @@ public function testCreateRpcService()
}
}
}

public function testGetFieldsForEntityMethods()
{
$api = $this->apiFactory->createApi('Test', 1);

$service = $this->apiFactory->createService($api, 'EntityFields');

$this->assertEquals('EntityFields', $service->getName());

$this->assertCount(1, $service->getFields('PUT'));
}
}
64 changes: 64 additions & 0 deletions test/TestAsset/module-config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@
),
),
),
'test.rest.entity-fields' => array(
'type' => 'Segment',
'options' => array(
'route' => '/entity-fields',
'defaults' => array(
'controller' => 'Test\\V1\\Rest\\EntityFields\\Controller',
'action' => 'test',
),
),
),
),
),
'zf-versioning' => array(
Expand Down Expand Up @@ -106,6 +116,23 @@
'collection_class' => 'Test\\V1\\Rest\\BooBaz\\BooBazCollection',
'service_name' => 'BooBaz',
),
'Test\\V1\\Rest\\EntityFields\\Controller' => array(
'listener' => 'Test\\V1\\Rest\\EntityFields\\EntityFieldsResource',
'route_name' => 'test.rest.entity-fields',
'route_identifier_name' => 'id',
'collection_name' => 'entity_fields',
'entity_http_methods' => array(
0 => 'PUT',
),
'collection_http_methods' => array(
),
'collection_query_whitelist' => array(),
'page_size' => 25,
'page_size_param' => null,
'entity_class' => 'Test\\V1\\Rest\\EntityFields\\EntityFieldsEntity',
'collection_class' => 'Test\\V1\\Rest\\EntityFields\\EntityFieldsCollection',
'service_name' => 'EntityFields',
),
),
'zf-content-negotiation' => array(
'controllers' => array(
Expand Down Expand Up @@ -135,6 +162,11 @@
1 => 'application/json',
2 => 'application/*+json',
),
'Test\\V1\\Rest\\EntityFields\\Controller' => array(
0 => 'application/vnd.test.v1+json',
1 => 'application/json',
2 => 'application/*+json',
),
),
'content_type_whitelist' => array(
'Test\\V1\\Rest\\FooBar\\Controller' => array(
Expand All @@ -153,6 +185,10 @@
0 => 'application/vnd.test.v1+json',
1 => 'application/json',
),
'Test\\V1\\Rpc\\EntityFields\\Controller' => array(
0 => 'application/vnd.test.v1+json',
1 => 'application/json',
),
),
),
'zf-hal' => array(
Expand Down Expand Up @@ -181,6 +217,12 @@
'route_identifier_name' => 'boo_baz_id',
'is_collection' => true,
),
'Test\\V1\\Rest\\EntityFields\\EntityFieldsCollection' => array(
'entity_identifier_name' => 'id',
'route_name' => 'test.rest.entity-fields',
'route_identifier_name' => 'id',
'is_collection' => true,
),
),
),
'controllers' => array(
Expand Down Expand Up @@ -209,6 +251,10 @@
'Test\\V1\\Rest\\FooBar\\Controller' => array(
'input_filter' => 'Test\\V1\\Rest\\FooBar\\Validator',
),
'Test\\V1\\Rest\\EntityFields\\Controller' => array(
'input_filter' => 'Test\\V1\\Rest\\EntityFields\\Validator',
'PUT' => 'Test\\V1\\Rest\\EntityFields\\Validator\\Put',
),
),
'input_filter_specs' => array(
'Test\\V1\\Rest\\FooBar\\Validator' => array(
Expand Down Expand Up @@ -271,6 +317,24 @@
),
),
),
'Test\\V1\\Rest\\EntityFields\\Validator' => array(
0 => array(
'required' => true,
'validators' => array(),
'filters' => array(),
'name' => 'test',
'description' => 'test',
),
),
'Test\\V1\\Rest\\EntityFields\\Validator\\Put' => array(
0 => array(
'required' => true,
'validators' => array(),
'filters' => array(),
'name' => 'test_put',
'description' => 'test_put',
),
),
),
'zf-mvc-auth' => array(
'authentication' => array(
Expand Down

0 comments on commit f5c1648

Please sign in to comment.