Skip to content

Commit

Permalink
fix annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
BigZ committed Jul 15, 2018
1 parent ef71be9 commit 4910ab5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/Halapi/AnnotationReader/AnnotationReaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ interface AnnotationReaderInterface
* Return the configured route name for an embeddable relation.
*
* @param \ReflectionProperty $property
* @param string $targetClass
*
* @return string
*/
public function getAssociationRouteName(\ReflectionProperty $property);
public function getAssociationRouteName(\ReflectionProperty $property, $targetClass);

/**
* Return the configured route name for a resource, or get_*entityShortName* by default.
Expand Down
14 changes: 8 additions & 6 deletions src/Halapi/AnnotationReader/DoctrineAnnotationReader.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

namespace Halapi\Relation;
namespace Halapi\AnnotationReader;

use Halapi\Annotation\Embeddable;
use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;

/**
* Reads annotations.
Expand All @@ -27,13 +28,16 @@ public function __construct(Reader $annotationReader)
}

/**
* Get the route name of a relationship.
*
* @param \ReflectionProperty $property
* @param string $targetClass
*
* @return mixed
* @return string
*
* @throws \ReflectionException
*/
public function getAssociationRouteName(\ReflectionProperty $property)
public function getAssociationRouteName(\ReflectionProperty $property, $targetClass)
{
/**
* @var Embeddable
Expand All @@ -44,9 +48,7 @@ public function getAssociationRouteName(\ReflectionProperty $property)
return $annotation->getRouteName();
}

return $this->getResourceRouteName(new \ReflectionClass(
$this->classMetadata->getAssociationTargetClass($property->getName())
));
return $this->getResourceRouteName(new \ReflectionClass($targetClass));
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/Halapi/Relation/LinksRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ public function getRelation($resource)
}

/**
* @param \ReflectionProperty $property
* @param $relationContent
* @return mixed
* @throws \ReflectionException
* @inheritdoc
*/
private function getRelationLink(\ReflectionProperty $property, $relationContent)
{
$relationReflection = new \ReflectionClass($relationContent);
if ($this->classMetadata->hasAssociation($property->getName())) {
return $this->urlGenerator->generate(
$this->annotationReader->getAssociationRouteName($property),
$this->annotationReader->getAssociationRouteName(
$property,
$this->classMetadata->getAssociationTargetClass($property->getName())
),
[
strtolower($relationReflection->getShortName()) => $this->objectManager->getIdentifier($relationContent),
]
Expand Down Expand Up @@ -134,8 +134,8 @@ private function getSelfLink($resource)
/**
* @param \ReflectionProperty $property
* @param $relationContent
* @return array|mixed
* @throws \ReflectionException
*
* @return array
*/
private function getRelationLinks(\ReflectionProperty $property, $relationContent)
{
Expand Down

0 comments on commit 4910ab5

Please sign in to comment.