Пример #1
0
 public function normalizeFormDescription(FormDescription $formDescription)
 {
     $formRepresentation = $this->normalize($formDescription->getForm());
     $formRepresentation->rel = $formDescription->getRel();
     $formRepresentation->method = $formDescription->getMethod();
     $formRepresentation->action = $formDescription->getActionUrl();
     if (null !== $this->atomLinkFactory) {
         $formRepresentation->addLink($this->atomLinkFactory->create('self', $formDescription->getSelfUrl()));
     }
     return $formRepresentation;
 }
Пример #2
0
 protected function createRootRepresentation()
 {
     $rootRepresentation = new Resource();
     // Add link to every resource collection
     foreach ($this->resources as $rel => $resource) {
         /** @var $resource \FSC\RestBundle\REST\AbstractResource */
         $href = $this->router->generate($resource->getRouteNameProvider()->getCollectionRouteName(), array(), true);
         $rootRepresentation->addLink($this->atomLinkFactory->create($rel, $href));
     }
     // Add a link to every custom route
     foreach ($this->routes as $rel => $route) {
         $rootRepresentation->addLink($this->atomLinkFactory->create($rel, $this->router->generate($route, array(), true)));
     }
     return $rootRepresentation;
 }
Пример #3
0
 protected function configureCollectionRepresentation(CollectionRepresentation $collectionRepresentation, Pagerfanta $pager, $entity = null, $collectionRel = null)
 {
     // Properties
     $collectionRepresentation->total = $pager->getNbResults();
     $collectionRepresentation->page = $pager->getCurrentPage();
     $collectionRepresentation->limit = $pager->getMaxPerPage();
     // Links between pages
     $createRoute = function ($page, $limit) use($entity, $collectionRel) {
         $parameters = array('search' => array('page' => $page, 'limit' => $limit));
         return null !== $entity && null !== $collectionRel ? $this->getUrlGenerator()->generateEntityCollectionUrl($entity, $collectionRel, $parameters) : $this->getUrlGenerator()->generateCollectionUrl($parameters);
     };
     $collectionRepresentation->addLink($this->atomLinkFactory->create('self', $createRoute($pager->getCurrentPage(), $pager->getMaxPerPage())));
     if ($pager->hasNextPage()) {
         $collectionRepresentation->addLink($this->atomLinkFactory->create('next', $createRoute($pager->getNextPage(), $pager->getMaxPerPage())));
     }
     if ($pager->hasPreviousPage()) {
         $collectionRepresentation->addLink($this->atomLinkFactory->create('previous', $createRoute($pager->getPreviousPage(), $pager->getMaxPerPage())));
     }
     $collectionRepresentation->addLink($this->atomLinkFactory->create('first', $createRoute(1, $pager->getMaxPerPage())));
     $collectionRepresentation->addLink($this->atomLinkFactory->create('last', $createRoute($pager->getNbPages(), $pager->getMaxPerPage())));
 }