Skip to content

Commit

Permalink
Merge pull request #92 from fcastilloes/schema-tags
Browse files Browse the repository at this point in the history
Add tags to ActionSchema
  • Loading branch information
fcastilloes committed Nov 30, 2017
2 parents 5a4ec67 + d1069f0 commit e99e9d3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Mapper/SchemaMapper.php
Expand Up @@ -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
);
}
Expand Down
25 changes: 25 additions & 0 deletions src/Schema/ActionSchema.php
Expand Up @@ -70,6 +70,11 @@ class ActionSchema
*/
private $remoteCalls = [];

/**
* @var string[]
*/
private $tags = [];

/**
* @var ActionReturn
*/
Expand All @@ -86,6 +91,7 @@ class ActionSchema
* @param array $calls
* @param array $deferCalls
* @param array $remoteCalls
* @param array $tags
* @param ActionReturn $return
*/
public function __construct(
Expand All @@ -99,6 +105,7 @@ public function __construct(
array $calls,
array $deferCalls,
array $remoteCalls,
array $tags = [],
ActionReturn $return = null
) {
$paramNames = array_map(function (ParamSchema $param) {
Expand All @@ -120,6 +127,7 @@ public function __construct(
$this->calls = $calls;
$this->deferCalls = $deferCalls;
$this->remoteCalls = $remoteCalls;
$this->tags = $tags;
$this->return = $return;
}

Expand Down Expand Up @@ -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
*/
Expand Down
6 changes: 6 additions & 0 deletions tests/Mapper/SchemaMapperTest.php
Expand Up @@ -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());
Expand Down
6 changes: 5 additions & 1 deletion tests/Mapper/service_mapping.json
Expand Up @@ -51,7 +51,11 @@
"g": false
}
}
}
},
"t": [
"one",
"two"
]
}
}
},
Expand Down

0 comments on commit e99e9d3

Please sign in to comment.