Skip to content

Commit

Permalink
Update build-manifest (#1000)
Browse files Browse the repository at this point in the history
* Update build-manifest
  • Loading branch information
cjyclaire committed May 20, 2016
1 parent 7e11ba8 commit c0fbe83
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
8 changes: 5 additions & 3 deletions build/build-manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@
$manifest = [];
foreach (glob(__DIR__ . '/../src/data/**/**/api-2.json') as $file) {
$model = json_decode(file_get_contents($file), true);
preg_match('@src/data/([^/]+)/[0-9]{4}-[0-9]{2}-[0-9]{2}/api-2.json$@', $file, $matches);
$identifier = $matches[1];
$metadata = $model['metadata'] + ['compatibleApiVersions' => []];
if (empty($manifest[$metadata['endpointPrefix']])) {
if (empty($manifest[$identifier])) {
// Calculate a namespace for the service.
$ns = isset($metadata['serviceAbbreviation'])
? $metadata['serviceAbbreviation']
Expand All @@ -65,13 +67,13 @@

$ns = $possibleNamespaces[strtolower($ns)];

$manifest[$metadata['endpointPrefix']] = [
$manifest[$identifier] = [
'namespace' => $ns,
'versions' => [],
];
}

$manifest[$metadata['endpointPrefix']]['versions'][$metadata['apiVersion']]
$manifest[$identifier]['versions'][$metadata['apiVersion']]
= $metadata['apiVersion'];
}

Expand Down
2 changes: 1 addition & 1 deletion build/docs/classes/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Service

public function __construct(Api $api, DocModel $docs)
{
$this->name = $api->getEndpointPrefix();
$this->name = $api->getServiceName();
$this->api = $api;
$this->namespace = $this->getServiceNamespace($this->name);
$this->version = $api->getApiVersion();
Expand Down
3 changes: 3 additions & 0 deletions src/Api/ApiProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public static function resolve(callable $provider, $type, $service, $version)
// Execute the provider and return the result, if there is one.
$result = $provider($type, $service, $version);
if (is_array($result)) {
if (!isset($result['metadata']['serviceIdentifier'])) {
$result['metadata']['serviceIdentifier'] = $service;
}
return $result;
}

Expand Down
18 changes: 17 additions & 1 deletion src/Api/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ public function __construct(array $definition, callable $provider)
$this->definition = $definition;
$this->apiProvider = $provider;
parent::__construct($definition, new ShapeMap($definition['shapes']));
$this->serviceName = $this->getEndpointPrefix();

if (isset($definition['metadata']['serviceIdentifier'])) {
$this->serviceName = $this->getServiceName();
} else {
$this->serviceName = $this->getEndpointPrefix();
}

$this->apiVersion = $this->getApiVersion();
}

Expand Down Expand Up @@ -183,6 +189,16 @@ public function getSigningName()
?: $this->definition['metadata']['endpointPrefix'];
}

/**
* Get the service name.
*
* @return string
*/
public function getServiceName()
{
return $this->definition['metadata']['serviceIdentifier'];
}

/**
* Get the default signature version of the service.
*
Expand Down
3 changes: 2 additions & 1 deletion tests/Api/ApiProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ private function getTestApiProvider($useManifest = true)
public function testCanResolveProvider()
{
$p = function ($a, $b, $c) {return [];};
$this->assertEquals([], ApiProvider::resolve($p, 't', 's', 'v'));
$result = ['metadata'=> ['serviceIdentifier' => 's']];
$this->assertEquals($result, ApiProvider::resolve($p, 't', 's', 'v'));

$p = function ($a, $b, $c) {return null;};
$this->setExpectedException(UnresolvedApiException::class);
Expand Down
6 changes: 4 additions & 2 deletions tests/Api/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function testReturnsApiData()
$s = new Service(
[
'metadata' => [
'serviceFullName' => 'foo',
'serviceFullName' => 'Foo',
'serviceIdentifier' => 'foo',
'endpointPrefix' => 'bar',
'apiVersion' => 'baz',
'signingName' => 'qux',
Expand All @@ -42,7 +43,8 @@ public function testReturnsApiData()
],
function () { return []; }
);
$this->assertEquals('foo', $s->getServiceFullName());
$this->assertEquals('Foo', $s->getServiceFullName());
$this->assertEquals('foo', $s->getServiceName());
$this->assertEquals('bar', $s->getEndpointPrefix());
$this->assertEquals('baz', $s->getApiVersion());
$this->assertEquals('qux', $s->getSigningName());
Expand Down

0 comments on commit c0fbe83

Please sign in to comment.