Official tutorial from which this is adapted:
Clone the project from Florent's repository (updated ZF3 quickstart):]
git clone git@github.com:Orkin/tsi-getting-start.git
As William Durand was recently explaining in his SOS, he "didn't see any other interesting blog post about REST with Symfony recently unfortunately". After spending some long hours to implement an API strongly secured with oAuth, I thought it was time for me to purpose my simple explanation of how to do it.
You might have already seen some good explanation of how to easily create a REST API with Symfony2. There are famous really good bundles a.k.a. :
/** | |
* @return ViewModel | |
*/ | |
public function registerAction() | |
{ | |
$form = new RegisterForm(); | |
if (($result = $this->prg()) instanceof Response) { | |
return $result; | |
} elseif ($result !== false) { |
<?php | |
namespace Common\Registry; | |
class Registry | |
{ | |
/** | |
* @var array | |
*/ | |
protected static $container = array(); |
<?php | |
namespace User\Form; | |
use Common\Registry\Registry; | |
use DoctrineORMModule\Stdlib\Hydrator\DoctrineEntity as DoctrineHydrator; | |
use User\Entity\StudentSkill as StudentSkillEntity; | |
use Zend\Form\Fieldset; | |
use Zend\InputFilter\InputFilterProviderInterface; | |
use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator; |
<?php | |
namespace User\Form; | |
use Common\Registry\Registry; | |
use DoctrineORMModule\Stdlib\Hydrator\DoctrineEntity as DoctrineHydrator; | |
use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator; | |
class Student extends AbstractUser | |
{ |
<?php | |
// Par défaut, Doctrine t'offre ces différents events : | |
// PostLoad, PostPersist, PostRemove, PostUpdate | |
// PrePersist, PreRemove, PreUpdate | |
/** | |
* @ORM\Entity | |
* @ORM\HasLifecycleCallbacks // <=== Active le mécanisme d'évènements | |
*/ |
<?php | |
use Doctrine\ORM\Mapping as ORM; | |
use Doctrine\Common\Collections\ArrayCollection; | |
/** | |
* @ORM\Entity() | |
* @ORM\Table(name="user") | |
*/ | |
class User |