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

Commit ef832d6

Browse files
Revert "added new MetadataInterface added missing param in doc-blocks fixed ExtractInstanceTrait::extractInstance signature (AbstractMetadata -> AbstractResourceMetadata) fixed few return types fixed useless string conversion in Link constructor changed generateSelfLink and generateLinkForPage signature in RouteBasedCollectionStrategy to be more specific changed UrlBasedCollectionStrategy::generateSelfLink signature to be more specific changed few lambda function to static wherever possible removed DepthAwareMetadataInterface"
This reverts commit 35a0ff1
1 parent 3eb948b commit ef832d6

14 files changed

+40
-34
lines changed

src/HalResponseFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct(
4646
Renderer\XmlRenderer $xmlRenderer = null
4747
) {
4848
// Ensures type safety of the composed factory
49-
$this->responseFactory = static function () use ($responseFactory) : ResponseInterface {
49+
$this->responseFactory = function () use ($responseFactory) : ResponseInterface {
5050
return $responseFactory();
5151
};
5252
$this->jsonRenderer = $jsonRenderer ?: new Renderer\JsonRenderer();

src/HalResponseFactoryFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Psr\Container\ContainerInterface;
1111
use Psr\Http\Message\ResponseInterface;
12-
use RuntimeException;
1312

1413
/**
1514
* Create and return a HalResponseFactory instance.

src/Link.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Link implements EvolvableLinkInterface
4848

4949
/**
5050
* @param string|string[] $relation One or more relations represented by this link.
51-
* @param string $uri
51+
* @param string|object $uri
5252
* @param bool $isTemplated
5353
* @param array $attributes
5454
* @throws InvalidArgumentException if $relation is neither a string nor an array.
@@ -58,7 +58,7 @@ class Link implements EvolvableLinkInterface
5858
public function __construct($relation, string $uri = '', bool $isTemplated = false, array $attributes = [])
5959
{
6060
$this->relations = $this->validateRelation($relation);
61-
$this->uri = $uri;
61+
$this->uri = is_string($uri) ? $uri : (string) $uri;
6262
$this->isTemplated = $isTemplated;
6363
$this->attributes = $this->validateAttributes($attributes);
6464
}
@@ -153,7 +153,7 @@ public function withoutRel($rel)
153153
}
154154

155155
$new = clone $this;
156-
$new->relations = array_filter($this->relations, static function ($value) use ($rel) {
156+
$new->relations = array_filter($this->relations, function ($value) use ($rel) {
157157
return $rel !== $value;
158158
});
159159
return $new;
@@ -227,7 +227,7 @@ private function validateAttributeValue($value, string $context)
227227
));
228228
}
229229

230-
if (is_array($value) && array_reduce($value, static function ($isInvalid, $value) {
230+
if (is_array($value) && array_reduce($value, function ($isInvalid, $value) {
231231
return $isInvalid || ! is_string($value);
232232
}, false)) {
233233
throw new InvalidArgumentException(sprintf(
@@ -260,7 +260,7 @@ private function validateRelation($relation)
260260
));
261261
}
262262

263-
if (is_array($relation) && false === array_reduce($relation, static function ($isString, $value) {
263+
if (is_array($relation) && false === array_reduce($relation, function ($isString, $value) {
264264
return $isString === false || is_string($value) || empty($value);
265265
}, true)) {
266266
throw new InvalidArgumentException(

src/LinkCollection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function getLinks()
3737
*/
3838
public function getLinksByRel($rel)
3939
{
40-
return array_filter($this->links, static function (LinkInterface $link) use ($rel) {
40+
return array_filter($this->links, function (LinkInterface $link) use ($rel) {
4141
$rels = $link->getRels();
4242
return in_array($rel, $rels, true);
4343
});
@@ -67,7 +67,7 @@ public function withoutLink(LinkInterface $link)
6767
}
6868

6969
$new = clone $this;
70-
$new->links = array_filter($this->links, static function (LinkInterface $compare) use ($link) {
70+
$new->links = array_filter($this->links, function (LinkInterface $compare) use ($link) {
7171
return $link !== $compare;
7272
});
7373
return $new;

src/Metadata/AbstractMetadata.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77

88
namespace Zend\Expressive\Hal\Metadata;
99

10-
abstract class AbstractMetadata implements MetadataInterface
10+
use Zend\Expressive\Hal\LinkCollection;
11+
12+
abstract class AbstractMetadata
1113
{
14+
use LinkCollection;
15+
1216
/**
1317
* @var string
1418
*/
@@ -18,9 +22,4 @@ public function getClass() : string
1822
{
1923
return $this->class;
2024
}
21-
22-
public function hasReachedMaxDepth(int $currentDepth): bool
23-
{
24-
return false;
25-
}
2625
}

src/Metadata/MetadataInterface.php renamed to src/Metadata/DepthAwareMetadataInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
namespace Zend\Expressive\Hal\Metadata;
55

6-
interface MetadataInterface
6+
interface DepthAwareMetadataInterface
77
{
88
/**
9-
* Returns the configured metadata class name
9+
* Returns configured max depth
1010
*
11-
* @return string
11+
* @return int
1212
*/
13-
public function getClass() : string;
13+
public function getMaxDepth(): int;
1414

1515
/**
1616
* Determines whenever the current depth level exceeds the allowed max depth

src/Metadata/MetadataMapFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private function populateMetadataMapFromConfig(
9191
* @throws Exception\InvalidConfigException if no matching `create*()`
9292
* method is found for the "__class__" entry.
9393
*/
94-
private function injectMetadata(MetadataMap $metadataMap, array $metadata, array $metadataFactories): void
94+
private function injectMetadata(MetadataMap $metadataMap, array $metadata, array $metadataFactories)
9595
{
9696
if (! isset($metadata['__class__'])) {
9797
throw Exception\InvalidConfigException::dueToMissingMetadataClass();

src/Metadata/RouteBasedResourceMetadata.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Zend\Expressive\Hal\Metadata;
99

10-
class RouteBasedResourceMetadata extends AbstractResourceMetadata
10+
class RouteBasedResourceMetadata extends AbstractResourceMetadata implements DepthAwareMetadataInterface
1111
{
1212
/** @var string */
1313
private $resourceIdentifier;
@@ -67,6 +67,11 @@ public function setRouteParams(array $routeParams) : void
6767
$this->routeParams = $routeParams;
6868
}
6969

70+
public function getMaxDepth(): int
71+
{
72+
return $this->maxDepth;
73+
}
74+
7075
public function hasReachedMaxDepth(int $currentDepth): bool
7176
{
7277
return $currentDepth > $this->maxDepth;

src/Renderer/XmlRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private function createResourceNode(DOMDocument $doc, array $resource, string $r
7878
return $this->createNodeTree($doc, $node, $resource);
7979
}
8080

81-
private function createLinkNode(DOMDocument $doc, string $rel, array $data): \DOMElement
81+
private function createLinkNode(DOMDocument $doc, string $rel, array $data)
8282
{
8383
$link = $doc->createElement('link');
8484
$link->setAttribute('rel', $rel);

src/ResourceGenerator.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ public function fromArray(array $data, string $uri = null) : HalResource
122122
* @param object $instance An object of any type; the type will be checked
123123
* against types registered in the metadata map.
124124
* @param ServerRequestInterface $request
125-
* @param int $depth
126125
*/
127126
public function fromObject($instance, ServerRequestInterface $request, int $depth = 0) : HalResource
128127
{

0 commit comments

Comments
 (0)