Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Controller/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ protected function getRelFromCollectionFormRoute(Request $request)
return $matches[1];
}

/**
* @return \FSC\RestBundle\REST\Description\FormDescription|\Pagerfanta\Pagerfanta|integer|string|null|Request
*/
protected function getRelFromEntityCollectionRoute(Request $request)
{
$route = $request->attributes->get('_route');
Expand Down
8 changes: 8 additions & 0 deletions Model/Representation/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,19 @@ public function addRelation(Entity $entity)
$this->relations[$entity->rel] = $entity;
}

/**
* @param string $key
* @param string $value
*/
public function setElement($key, $value)
{
$this->elements[$key] = $value;
}

/**
* @param string $key
* @param string $value
*/
public function setAttribute($key, $value)
{
$this->attributes[$key] = $value;
Expand Down
16 changes: 10 additions & 6 deletions Normalizer/FormNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function __construct(AtomLinkFactory $atomLinkFactory = null)

/**
* {@inheritdoc}
* @param \Symfony\Component\Form\FormInterface $object
*/
public function normalize($object, $format = null)
{
Expand Down Expand Up @@ -102,6 +103,9 @@ protected function mergeFormElementsArrays($formElements)
return $this->mergeFormElementsArrays($formElements);
}

/**
* @param string|null $blockName
*/
protected function renderBlock(FormView $view, $blockName = null, array $variables = array())
{
$variables = $view->getVars();
Expand Down Expand Up @@ -148,8 +152,7 @@ protected function renderBlock(FormView $view, $blockName = null, array $variabl
/*
{% if compound %}
{{ block('form_widget_compound') }}
{% else %}
{{ block('form_widget_simple') }}
{% else { %}{ block('form_widget_simple') }}
{% endif %}
*/
protected function renderFormWidget(FormView $view, $blockName, array $variables = array())
Expand Down Expand Up @@ -358,8 +361,7 @@ protected function renderCollectionWidget(FormView $view, $blockName, array $var
/*
{% if expanded %}
{{ block('choice_widget_expanded') }}
{% else %}
{{ block('choice_widget_collapsed') }}
{% else { %}{ block('choice_widget_collapsed') }}
{% endif %}
*/
protected function renderChoiceWidget(FormView $view, $blockName, array $variables = array())
Expand Down Expand Up @@ -507,11 +509,13 @@ protected function renderFormRows(FormView $view, $blockName, array $variables =
{% for attrname, attrvalue in attr %}
{% if attrname in ['placeholder', 'title'] %}
{{ attrname }}="{{ attrvalue|trans({}, translation_domain) }}"
{% else %}
{{ attrname }}="{{ attrvalue }}"
{% else { %}{ attrname }}="{{ attrvalue }}"
{% endif %}
{% endfor %}
*/
/**
* @param FormRepresentations\Input|FormRepresentations\Textarea|FormRepresentations\Select $widget
*/
protected function addWidgetAttributes($widget, FormView $view, $blockName, array $variables = array())
{
$widget->attributes['name'] = $variables['full_name'];
Expand Down
3 changes: 2 additions & 1 deletion REST/AbstractDoctrineResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ protected function getRepository()

/**
* @param QueryBuilder|Query $query
* @param Collection $collection
* @param null|Collection $collection
* @param boolean $fetchJoinCollection
*
* @return Pagerfanta
*/
Expand Down
28 changes: 28 additions & 0 deletions REST/AbstractResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ public function guessRouteNamePrefix()
return sprintf('%s_rest_%s', $routeName, $this->guessResourceName());
}

/**
* @param boolean $doNotExpandRelationsAndCollections
*/
public function normalizeEntity($entity, $doNotExpandRelationsAndCollections = false)
{
// Make sure that the used is authorized to see this resource
Expand Down Expand Up @@ -410,6 +413,9 @@ public function normalizeCollection(Pagerfanta $pager, FormDescription $formDesc
return $collectionRepresentation;
}

/**
* @param integer|string $rel
*/
public function normalizeEntityCollection($entity, $rel, Pagerfanta $pager, FormDescription $formDescription)
{
$configurationEntityCollection = $this->getConfigurationEntityCollections()[$rel];
Expand Down Expand Up @@ -503,6 +509,9 @@ public function createCollectionSearchFormDescription(Request $request = null)
return new FormDescription($rel, $method, $actionUrl, $form, $formData, $selfUrl);
}

/**
* @return FormDescription
*/
public function createEntityCollectionFormDescription($rel, $entity, $collectionRel, Request $request = null)
{
if ('search' == $rel) {
Expand All @@ -512,6 +521,9 @@ public function createEntityCollectionFormDescription($rel, $entity, $collection
throw new \Exception('Not implemented, sorry!');
}

/**
* @param integer|string $collectionRel
*/
public function createEntityCollectionSearchFormDescription($entity, $collectionRel, Request $request = null)
{
$createForm = $this->getConfigurationCollectionSearch()['create_form'];
Expand Down Expand Up @@ -542,10 +554,26 @@ public function getEntityCollectionRelFromRouteRel($routeRel)
}
}

/**
* @return FormDescription|Pagerfanta|integer|string|null|Request
*/
abstract public function getEntity(Request $request);
/**
* @return FormDescription|Pagerfanta
*/
abstract public function getCollectionPager(Collection $search);
/**
* @param integer|string $rel
*
* @return FormDescription|Pagerfanta|integer|string
*/
abstract public function getEntityCollectionPager($entity, Collection $search, $rel);

/**
* @param integer|string $entityRelationRel
*
* @return object|null
*/
public function getEntityRelation($entity, $entityRelationRel)
{
$getRelation = $this->getConfigurationEntityRelations()[$entityRelationRel]['get_relation'];
Expand Down
11 changes: 11 additions & 0 deletions REST/AtomLinkFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public function __construct($relPrefix = '')
$this->relPrefix = $relPrefix;
}

/**
* @param string|integer $rel
* @param string $href
*
* @return AtomLink
*/
public function create($rel, $href, $type = null)
{
return AtomLink::create($this->getRel($rel), $href, $type);
Expand All @@ -41,6 +47,11 @@ public static function getIanaRelations()
return static::$ianaRelations;
}

/**
* @param integer|string $rel
*
* @return string
*/
public function getRel($rel)
{
if (!in_array($rel, static::$ianaRelations)) {
Expand Down
6 changes: 6 additions & 0 deletions REST/Description/FormDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ public function getForm()
return $this->form;
}

/**
* @return \FSC\RestBundle\Form\Model\Collection
*/
public function getData()
{
return $this->data;
}

/**
* @return string
*/
public function getSelfUrl()
{
return $this->selfUrl;
Expand Down
16 changes: 16 additions & 0 deletions Routing/RouteNameProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public function getCollectionRouteName()
return $this->resourceBaseRoute.'_collection';
}

/**
* @param string $formRel
*/
public function getCollectionFormRouteName($formRel)
{
return $this->resourceBaseRoute.'_collection_form_'.$this->normalizeRel($formRel);
Expand All @@ -26,21 +29,34 @@ public function getEntityRouteName()
return $this->resourceBaseRoute.'_entity';
}

/**
* @param string $formRel
*/
public function getEntityFormRouteName($formRel)
{
return $this->resourceBaseRoute.'_entity_form_'.$this->normalizeRel($formRel);
}

/**
* @param string $collectionRel
*/
public function getEntityCollectionRouteName($collectionRel)
{
return $this->resourceBaseRoute.'_entity_collection_'.$this->normalizeRel($collectionRel);
}

/**
* @param string $collectionRel
* @param string $formRel
*/
public function getEntityCollectionFormRouteName($collectionRel, $formRel)
{
return $this->resourceBaseRoute.'_entity_collection_'.$this->normalizeRel($collectionRel).'_form_'.$this->normalizeRel($formRel);
}

/**
* @param integer|string $rel
*/
public static function normalizeRel($rel)
{
return preg_replace('/[^0-9a-zA-Z_.]+/', '', $rel);
Expand Down
18 changes: 18 additions & 0 deletions Routing/RouteNameProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,28 @@

interface RouteNameProviderInterface
{
/**
* @return string
*/
public function getCollectionRouteName();
/**
* @return string
*/
public function getCollectionFormRouteName($formRel);
/**
* @return string
*/
public function getEntityRouteName();
/**
* @return string
*/
public function getEntityFormRouteName($formRel);
/**
* @return string
*/
public function getEntityCollectionRouteName($collectionRel);
/**
* @return string
*/
public function getEntityCollectionFormRouteName($collectionRel, $formRel);
}
9 changes: 9 additions & 0 deletions Routing/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function __construct(SFUrlGeneratorInterface $urlGenerator, RouteNameProv

/**
* {@inheritdoc}
* @param array $parameters
*/
public function generateCollectionUrl($parameters = array())
{
Expand All @@ -32,6 +33,8 @@ public function generateCollectionUrl($parameters = array())

/**
* {@inheritdoc}
* @param string $formRel
* @param array $parameters
*/
public function generateCollectionFormUrl($formRel, $parameters = array())
{
Expand All @@ -42,6 +45,7 @@ public function generateCollectionFormUrl($formRel, $parameters = array())

/**
* {@inheritdoc}
* @param array $parameters
*/
public function generateEntityUrl($entity, $parameters = array())
{
Expand All @@ -53,6 +57,7 @@ public function generateEntityUrl($entity, $parameters = array())

/**
* {@inheritdoc}
* @param array $parameters
*/
public function generateEntityFormUrl($entity, $formRel, $parameters = array())
{
Expand All @@ -64,6 +69,8 @@ public function generateEntityFormUrl($entity, $formRel, $parameters = array())

/**
* {@inheritdoc}
* @param integer|string $collectionRel
* @param array $parameters
*/
public function generateEntityCollectionUrl($entity, $collectionRel, $parameters = array())
{
Expand All @@ -75,6 +82,8 @@ public function generateEntityCollectionUrl($entity, $collectionRel, $parameters

/**
* {@inheritdoc}
* @param string $formRel
* @param array $parameters
*/
public function generateEntityCollectionFormUrl($entity, $collectionRel, $formRel, $parameters = array())
{
Expand Down
18 changes: 18 additions & 0 deletions Routing/UrlGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,28 @@

interface UrlGeneratorInterface
{
/**
* @return string
*/
public function generateCollectionUrl($parameters = array());
/**
* @return string
*/
public function generateCollectionFormUrl($formRel, $parameters = array());
/**
* @return string
*/
public function generateEntityUrl($entity, $parameters = array());
/**
* @return string
*/
public function generateEntityFormUrl($entity, $formRel, $parameters = array());
/**
* @return string
*/
public function generateEntityCollectionUrl($entity, $collectionRel, $parameters = array());
/**
* @return string
*/
public function generateEntityCollectionFormUrl($entity, $collectionRel, $formRel, $parameters = array());
}
1 change: 0 additions & 1 deletion Tests/Functional/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace FSC\RestBundle\Tests\Functional;

use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;

Expand Down
1 change: 0 additions & 1 deletion Tests/Functional/Normalizer/FormNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace FSC\RestBundle\Tests\Functional\Normalizer;

use FSC\RestBundle\Tests\Functional\TestCase;
use FSC\RestBundle\Form\RestRendererEngine;

class FormNormalizerTest extends TestCase
{
Expand Down
8 changes: 8 additions & 0 deletions Tests/Functional/SerializationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@

abstract class SerializationTestCase extends TestCase
{
/**
* @param string $expectedXml
* @param \FSC\RestBundle\Model\Representation\Form\Form|\FSC\RestBundle\Model\Representation\AtomLink|\FSC\RestBundle\Model\Representation\Common\Measure|\FSC\RestBundle\Model\Representation\Resource $value
*/
protected function assertSerializedXmlEquals($expectedXml, $value)
{
$serializedValue = $this->get('serializer')->serialize($value, 'xml');

$this->assertEquals(sprintf('<?xml version="1.0" encoding="UTF-8"?>%s%s%s', "\n", $expectedXml, "\n"), $serializedValue);
}

/**
* @param string $expectedSerializedValue
* @param \FSC\RestBundle\Model\Representation\Resource $value
*/
protected function assertSerializedJsonEquals($expectedSerializedValue, $value)
{
$serializedValue = $this->get('serializer')->serialize($value, 'json');
Expand Down
Loading