Created
April 10, 2014 08:57
-
-
Save desarrolla2/10358743 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is part of the lapera.local package. | |
* | |
* (c) Daniel González <[email protected]> | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
namespace LaPera\RestBundle\Controller; | |
use FOS\RestBundle\Controller\FOSRestController; | |
use Nelmio\ApiDocBundle\Annotation\ApiDoc; | |
use FOS\RestBundle\Controller\Annotations\Prefix; | |
use FOS\RestBundle\Controller\Annotations\NamePrefix; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\Response; | |
use LaPera\RestBundle\Form\Type\UsersType; | |
use LaPera\RestBundle\Form\Model\UsersModel; | |
use LaPera\RestBundle\Form\Handler\UsersHandler; | |
use LaPera\RestBundle\Model\Serializer\User; | |
/** | |
* UsersController | |
* | |
* @NamePrefix("api_user_") | |
*/ | |
class UserController extends FOSRestController{ | |
public function postUsersAction(Request $request) | |
{ | |
$form = $this->createForm( | |
new UsersType(), | |
new UsersModel() | |
); | |
// other stuffs .. | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is part of the lapera.local package. | |
* | |
* (c) Daniel González <[email protected]> | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
namespace LaPera\RestBundle\Form\Model; | |
use Symfony\Component\Validator\Constraints as Assert; | |
use LaPera\CoreBundle\Validator\Constraints as LaPeraAssert; | |
/** | |
* UserModel | |
*/ | |
class UserModel | |
{ | |
/** | |
* @var string $username | |
* | |
* @Assert\NotBlank() | |
* @Assert\Length( min=5 ) | |
* @LaPeraAssert\Username | |
*/ | |
protected $username; | |
/** | |
* @var string $email | |
* | |
* @Assert\NotBlank() | |
* @Assert\Email( ) | |
*/ | |
protected $email; | |
/** | |
* @var string $password | |
* | |
* @Assert\NotBlank() | |
* @Assert\Length( min=5 ) | |
*/ | |
protected $password; | |
/** | |
* @param string $email | |
*/ | |
public function setEmail($email) | |
{ | |
$this->email = $email; | |
} | |
/** | |
* @return string | |
*/ | |
public function getEmail() | |
{ | |
return $this->email; | |
} | |
/** | |
* @param string $password | |
*/ | |
public function setPassword($password) | |
{ | |
$this->password = $password; | |
} | |
/** | |
* @return string | |
*/ | |
public function getPassword() | |
{ | |
return $this->password; | |
} | |
/** | |
* @param string $username | |
*/ | |
public function setUsername($username) | |
{ | |
$this->username = $username; | |
} | |
/** | |
* @return string | |
*/ | |
public function getUsername() | |
{ | |
return $this->username; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is part of the lapera.local package. | |
* | |
* (c) Daniel González <[email protected]> | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
namespace LaPera\RestBundle\Form\Model; | |
/** | |
* UsersModel | |
*/ | |
class UsersModel | |
{ | |
protected $user; | |
/** | |
* @param mixed $user | |
*/ | |
public function setUser($user) | |
{ | |
$this->user = $user; | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getUser() | |
{ | |
return $this->user; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is part of the lapera.local package. | |
* | |
* (c) Daniel González <[email protected]> | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
namespace LaPera\RestBundle\Form\Type; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | |
/** | |
* UserType | |
*/ | |
class UserType extends AbstractType | |
{ | |
/** | |
* @param FormBuilderInterface $builder | |
* @param array $options | |
*/ | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder | |
->add( | |
'username', | |
'text', | |
array( | |
'required' => true, | |
'trim' => true, | |
) | |
) | |
->add( | |
'email', | |
'email', | |
array( | |
'required' => true, | |
'trim' => true, | |
) | |
) | |
->add( | |
'password', | |
'password', | |
array( | |
'required' => true, | |
'trim' => true, | |
) | |
); | |
} | |
/** | |
* @param OptionsResolverInterface $resolver | |
*/ | |
public function setDefaultOptions(OptionsResolverInterface $resolver) | |
{ | |
$resolver->setDefaults( | |
array( | |
'data_class' => 'LaPera\RestBundle\Form\Model\UserModel', | |
) | |
); | |
} | |
public function getName() | |
{ | |
return 'type_user'; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is part of the lapera.local package. | |
* | |
* (c) Daniel González <[email protected]> | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
namespace LaPera\RestBundle\Form\Type; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | |
/** | |
* UsersType | |
*/ | |
class UsersType extends AbstractType | |
{ | |
/** | |
* @param FormBuilderInterface $builder | |
* @param array $options | |
*/ | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder | |
->add( | |
'user', | |
new UserType(), | |
array( | |
'required' => true, | |
) | |
); | |
} | |
public function setDefaultOptions(OptionsResolverInterface $resolver) | |
{ | |
$resolver->setDefaults( | |
array( | |
'data_class' => 'LaPera\RestBundle\Form\Model\UsersModel', | |
'csrf_protection' => false, | |
) | |
); | |
} | |
public function getName() | |
{ | |
return ''; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment