diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e7830b..0d519a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +## Added +- Tags in ActionSchema ## [1.2.8] - 2017-11-07 ## Changed diff --git a/src/Mapper/SchemaMapper.php b/src/Mapper/SchemaMapper.php index 07c49df..ca530ba 100644 --- a/src/Mapper/SchemaMapper.php +++ b/src/Mapper/SchemaMapper.php @@ -172,6 +172,7 @@ public function getServiceSchema($name, $version, array $raw) $this->read($action, 'C', []), $this->read($action, 'dc', []), $this->read($action, 'rc', []), + $this->read($action, 't', []), $return ); } diff --git a/src/Schema/ActionSchema.php b/src/Schema/ActionSchema.php index 79de4a7..4a4ef53 100644 --- a/src/Schema/ActionSchema.php +++ b/src/Schema/ActionSchema.php @@ -70,6 +70,11 @@ class ActionSchema */ private $remoteCalls = []; + /** + * @var string[] + */ + private $tags = []; + /** * @var ActionReturn */ @@ -86,6 +91,7 @@ class ActionSchema * @param array $calls * @param array $deferCalls * @param array $remoteCalls + * @param array $tags * @param ActionReturn $return */ public function __construct( @@ -99,6 +105,7 @@ public function __construct( array $calls, array $deferCalls, array $remoteCalls, + array $tags = [], ActionReturn $return = null ) { $paramNames = array_map(function (ParamSchema $param) { @@ -120,6 +127,7 @@ public function __construct( $this->calls = $calls; $this->deferCalls = $deferCalls; $this->remoteCalls = $remoteCalls; + $this->tags = $tags; $this->return = $return; } @@ -401,6 +409,23 @@ public function hasReturn() return !is_null($this->return); } + /** + * @param string $name + * @return bool + */ + public function hasTag(string $name): bool + { + return in_array($name, $this->tags); + } + + /** + * @return string[] + */ + public function getTags(): array + { + return $this->tags; + } + /** * @return string */ diff --git a/tests/Mapper/SchemaMapperTest.php b/tests/Mapper/SchemaMapperTest.php index dc5ca72..5a93698 100644 --- a/tests/Mapper/SchemaMapperTest.php +++ b/tests/Mapper/SchemaMapperTest.php @@ -113,6 +113,12 @@ public function testActionMapping(ServiceSchema $service) $this->assertEquals('uid', $action->getPrimaryKey()); $this->assertEquals(true, $action->isCollection()); + // Assert tags + $this->assertTrue($action->hasTag('one')); + $this->assertTrue($action->hasTag('two')); + $this->assertFalse($action->hasTag('three')); + $this->assertEquals(['one', 'two'], $action->getTags()); + // Assert http $http = $action->getHttpSchema(); $this->assertEquals(true, $http->isAccessible()); diff --git a/tests/Mapper/service_mapping.json b/tests/Mapper/service_mapping.json index 36647ef..70b5c48 100644 --- a/tests/Mapper/service_mapping.json +++ b/tests/Mapper/service_mapping.json @@ -51,7 +51,11 @@ "g": false } } - } + }, + "t": [ + "one", + "two" + ] } } },