Skip to content

Commit c042ec7

Browse files
committed
Move routePrefix to attributes
1 parent 481ccd8 commit c042ec7

File tree

10 files changed

+9
-46
lines changed

10 files changed

+9
-46
lines changed

src/Annotation/ApiResource.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ final class ApiResource
3838
*/
3939
public $iri;
4040

41-
/**
42-
* @var string
43-
*/
44-
public $routePrefix;
45-
4641
/**
4742
* @var array
4843
*/

src/Bridge/Symfony/Routing/ApiLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ private function addRoute(RouteCollection $routeCollection, string $resourceClas
198198
}
199199
}
200200

201-
$path = $resourceMetadata->getRoutePrefix() ?: '';
201+
$path = $resourceMetadata->getAttribute('routePrefix', '');
202202
$path .= $this->operationPathResolver->resolveOperationPath($resourceShortName, $operation, $operationType, $operationName);
203203

204204
$route = new Route(

src/Metadata/Extractor/XmlExtractor.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ protected function extractPath(string $path)
5151
'graphql' => $this->getOperations($resource, 'operation'),
5252
'attributes' => $this->getAttributes($resource, 'attribute') ?: null,
5353
'properties' => $this->getProperties($resource) ?: null,
54-
'routePrefix' => $this->phpize($resource, 'routePrefix', 'string'),
5554
];
5655
}
5756
}

src/Metadata/Extractor/YamlExtractor.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ private function extractResources(array $resourcesYaml, string $path)
7070
'subresourceOperations' => $resourceYaml['subresourceOperations'] ?? null,
7171
'graphql' => $resourceYaml['graphql'] ?? null,
7272
'attributes' => $resourceYaml['attributes'] ?? null,
73-
'routePrefix' => $this->phpize($resourceYaml, 'routePrefix', 'string'),
7473
];
7574

7675
if (!isset($resourceYaml['properties'])) {

src/Metadata/Resource/Factory/AnnotationResourceMetadataFactory.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,12 @@ private function createMetadata(ApiResource $annotation, ResourceMetadata $paren
8787
$annotation->collectionOperations,
8888
$annotation->attributes,
8989
$annotation->subresourceOperations,
90-
$annotation->graphql,
91-
$annotation->routePrefix
90+
$annotation->graphql
9291
);
9392
}
9493

9594
$resourceMetadata = $parentResourceMetadata;
96-
foreach (['shortName', 'description', 'iri', 'itemOperations', 'collectionOperations', 'subresourceOperations', 'graphql', 'attributes', 'routePrefix'] as $property) {
95+
foreach (['shortName', 'description', 'iri', 'itemOperations', 'collectionOperations', 'subresourceOperations', 'graphql', 'attributes'] as $property) {
9796
$resourceMetadata = $this->createWith($resourceMetadata, $property, $annotation->$property);
9897
}
9998

src/Metadata/Resource/ResourceMetadata.php

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ final class ResourceMetadata
2323
private $shortName;
2424
private $description;
2525
private $iri;
26-
private $routePrefix;
2726
private $itemOperations;
2827
private $collectionOperations;
2928
private $subresourceOperations;
3029
private $graphql;
3130
private $attributes;
3231

33-
public function __construct(string $shortName = null, string $description = null, string $iri = null, array $itemOperations = null, array $collectionOperations = null, array $attributes = null, array $subresourceOperations = null, array $graphql = null, string $routePrefix = null)
32+
public function __construct(string $shortName = null, string $description = null, string $iri = null, array $itemOperations = null, array $collectionOperations = null, array $attributes = null, array $subresourceOperations = null, array $graphql = null)
3433
{
3534
$this->shortName = $shortName;
3635
$this->description = $description;
@@ -40,7 +39,6 @@ public function __construct(string $shortName = null, string $description = null
4039
$this->subresourceOperations = $subresourceOperations;
4140
$this->graphql = $graphql;
4241
$this->attributes = $attributes;
43-
$this->routePrefix = $routePrefix;
4442
}
4543

4644
/**
@@ -322,25 +320,4 @@ public function withGraphql(array $graphql): self
322320

323321
return $metadata;
324322
}
325-
326-
/**
327-
* Gets the route prefix.
328-
*
329-
* @return string|null
330-
*/
331-
public function getRoutePrefix()
332-
{
333-
return $this->routePrefix;
334-
}
335-
336-
/**
337-
* Returns a new instance with the given route prefix.
338-
*/
339-
public function withRoutePrefix(string $routePrefix): self
340-
{
341-
$metadata = clone $this;
342-
$metadata->routePrefix = $routePrefix;
343-
344-
return $metadata;
345-
}
346323
}

tests/Annotation/AnnotatedClass.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
* itemOperations={"foo":{"bar"}},
2424
* collectionOperations={"bar":{"foo"}},
2525
* graphql={"query"={"normalization_context"={"groups"={"foo", "bar"}}}},
26-
* attributes={"foo":"bar"},
27-
* routePrefix="/whatever"
26+
* attributes={"foo":"bar", "routePrefix"="/whatever"},
2827
* )
2928
*
3029
* @author Marcus Speight <marcus@pmconnect.co.uk>

tests/Annotation/ApiResourceTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,13 @@ public function testAssignation()
3232
$resource->collectionOperations = ['bar' => ['foo']];
3333
$resource->graphql = ['query' => ['normalization_context' => ['groups' => ['foo', 'bar']]]];
3434
$resource->attributes = ['foo' => 'bar'];
35-
$resource->routePrefix = '/prefix';
3635

3736
$this->assertSame('shortName', $resource->shortName);
3837
$this->assertSame('description', $resource->description);
3938
$this->assertSame('http://example.com/res', $resource->iri);
4039
$this->assertSame(['bar' => ['foo']], $resource->collectionOperations);
4140
$this->assertSame(['query' => ['normalization_context' => ['groups' => ['foo', 'bar']]]], $resource->graphql);
4241
$this->assertSame(['foo' => 'bar'], $resource->attributes);
43-
$this->assertSame('/prefix', $resource->routePrefix);
4442
}
4543

4644
public function testApiResourceAnnotation()
@@ -53,7 +51,6 @@ public function testApiResourceAnnotation()
5351
$this->assertSame('http://example.com/res', $resource->iri);
5452
$this->assertSame(['bar' => ['foo']], $resource->collectionOperations);
5553
$this->assertSame(['query' => ['normalization_context' => ['groups' => ['foo', 'bar']]]], $resource->graphql);
56-
$this->assertSame(['foo' => 'bar'], $resource->attributes);
57-
$this->assertSame('/whatever', $resource->routePrefix);
54+
$this->assertSame(['foo' => 'bar', 'routePrefix' => '/whatever'], $resource->attributes);
5855
}
5956
}

tests/Bridge/Symfony/Routing/ApiLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function testApiLoaderWithPrefix()
106106
'put' => ['method' => 'PUT'],
107107
'delete' => ['method' => 'DELETE'],
108108
]);
109-
$resourceMetadata = $resourceMetadata->withRoutePrefix('/foobar-prefix');
109+
$resourceMetadata = $resourceMetadata->withAttributes(['routePrefix' => '/foobar-prefix']);
110110

111111
$routeCollection = $this->getApiLoaderWithResourceMetadata($resourceMetadata)->load(null);
112112

tests/Metadata/Resource/Factory/AnnotationResourceMetadataFactoryTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ public function testCreate(ProphecyInterface $reader, ProphecyInterface $decorat
4343
$this->assertEquals(['foo' => ['bar' => true]], $metadata->getItemOperations());
4444
$this->assertEquals(['baz' => ['tab' => false]], $metadata->getCollectionOperations());
4545
$this->assertEquals(['sub' => ['bus' => false]], $metadata->getSubresourceOperations());
46-
$this->assertEquals(['a' => 1], $metadata->getAttributes());
46+
$this->assertEquals(['a' => 1, 'routePrefix' => '/foobar'], $metadata->getAttributes());
4747
$this->assertEquals(['foo' => 'bar'], $metadata->getGraphql());
48-
$this->assertEquals('/foobar', $metadata->getRoutePrefix());
4948
}
5049

5150
public function getCreateDependencies()
@@ -57,9 +56,8 @@ public function getCreateDependencies()
5756
$annotation->itemOperations = ['foo' => ['bar' => true]];
5857
$annotation->collectionOperations = ['baz' => ['tab' => false]];
5958
$annotation->subresourceOperations = ['sub' => ['bus' => false]];
60-
$annotation->attributes = ['a' => 1];
59+
$annotation->attributes = ['a' => 1, 'routePrefix' => '/foobar'];
6160
$annotation->graphql = ['foo' => 'bar'];
62-
$annotation->routePrefix = '/foobar';
6361

6462
$reader = $this->prophesize(Reader::class);
6563
$reader->getClassAnnotation(Argument::type(\ReflectionClass::class), ApiResource::class)->willReturn($annotation)->shouldBeCalled();

0 commit comments

Comments
 (0)