Skip to content

Commit

Permalink
apply scrutinizer advices + extend doc example
Browse files Browse the repository at this point in the history
  • Loading branch information
BigZ committed Nov 26, 2016
1 parent 78bf1fc commit df8ae07
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 15 deletions.
64 changes: 53 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@

Hypertext Application Language for (REpresentational State Transfer) Application Programming Interfaces
-------------------------------------------------------------------------------------------------------

[![Build
Status](https://travis-ci.org/BigZ/Halapi.svg?branch=master)](http://travis-ci.org/BigZ/Halapi)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/240ef51f-6625-4c79-9ba2-58d4fcb63fa5/mini.png)](https://insight.sensiolabs.com/projects/240ef51f-6625-4c79-9ba2-58d4fcb63fa5)
[![Scrutinizer Quality
Score](https://scrutinizer-ci.com/g/BigZ/Halapi/badges/quality-score.png?s=45b5a825f99de4d29c98b5103f59e060139cf354)](https://scrutinizer-ci.com/g/willdurand/Hateoas/)
Score](https://scrutinizer-ci.com/g/BigZ/Halapi/badges/quality-score.png?s=45b5a825f99de4d29c98b5103f59e060139cf354)](https://scrutinizer-ci.com/g/BigZ/Halapi/)

This library is a tighly coupled to Doctrine ORM & Symfony's Router implementation of an HAL formatter.

Given some conventions, displaying the HAL representation of any entity becomes vert easy.

If you're using symfony; use Bigz/HalApiBundle to make use of the services definition

Expand All @@ -19,24 +21,64 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RouterInterface;
function SerializeWithHal(Entity $entity)
public function __construct(
RouterInterface $router,
Reader $annotationReader,
EntityManagerInterface $entityManager,
RequestStack $requestStack
) {
$this->router = $router;
$this->annotationReader = $annotationReader;
$this->entityManager = $entityManager;
$this->requestStack = $requestStack;
}
public function SerializeEntityWithHal(Entity $entity)
{
$linksRelation = new LinksRelation(
RouterInterface $router,
Reader $annotationReader,
EntityManagerInterface $entityManager,
RequestStack $requestStack
$this->router,
$this->annotationReader,
$this->entityManager,
$this->requestStack
);
$embeddedRelation = new EmbeddedRelation(
RouterInterface $router,
Reader $annotationReader,
EntityManagerInterface $entityManager,
RequestStack $requestStack
$this->router,
$this->annotationReader,
$this->entityManager,
$this->requestStack
);
$relationFactory = new RelationFactory([$linksRelation, $embeddedRelation]);
$builder = new HALAPIBuilder($relationFactory);
return $builder->gerSerializer()->serialize($entity);
}
public function SerializePaginatedCollectionWithHal($entityName)
{
$linksRelation = new LinksRelation(
$this->router,
$this->annotationReader,
$this->entityManager,
$this->requestStack
);
$embeddedRelation = new EmbeddedRelation(
$this->router,
$this->annotationReader,
$this->entityManager,
$this->requestStack
);
$relationFactory = new RelationFactory([$linksRelation, $embeddedRelation]);
$builder = new HALAPIBuilder($relationFactory);
$paginationFactory = new PaginationFactory(
$this->router,
$this->annotationReader,
$this->entityManager
);
$paginatedRepresentation = $paginationFactory->getRepresentation($entityName);
return $builder->gerSerializer()->serialize($paginatedRepresentation);
}
```
5 changes: 5 additions & 0 deletions src/Halapi/HALAPIBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
*/
class HALAPIBuilder
{
/**
* @var RelationFactory
*/
private $relationFactory;

/**
* @var SerializerBuilder
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Halapi/Relation/LinksRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getRelation($resource)
}

/**
* @param string $property
* @param \ReflectionProperty $property
* @param object $relationContent
* @return string|null
* @throws \Doctrine\ORM\Mapping\MappingException
Expand Down
6 changes: 3 additions & 3 deletions src/Halapi/Representation/PaginatedRepresentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ class PaginatedRepresentation
];

/**
* @var string
* @var int
*/
public $page;

/**
* @var string
* @var int
*/
public $limit;

/**
* @var object
* @var array
*/
public $_links;

Expand Down
4 changes: 4 additions & 0 deletions src/Halapi/Representation/RestEntityRepositoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
*/
trait RestEntityRepositoryTrait
{
abstract public function getClassMetadata();

abstract public function createQueryBuilder($alias, $indexBy = null);

/**
* @param array $sorting
* @param array $filterValues
Expand Down

0 comments on commit df8ae07

Please sign in to comment.