Last active
December 11, 2015 15:28
-
-
Save Magomogo/4620669 to your computer and use it in GitHub Desktop.
Put command
This file contains 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 | |
namespace STSShop\Admin\Command\Affiliate; | |
use STSShop\Admin\Affiliate\JsonContainer; | |
use STSShop\Admin\Affiliate\Model; | |
use STSShop\Admin\Affiliate\Properties; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\JsonResponse; | |
use Symfony\Component\Validator\Validator; | |
use Magomogo\Model\PropertyContainer\ContainerInterface; | |
use STSShop\Admin\Exception\Validation as ValidationException; | |
class Put | |
{ | |
/** | |
* | |
* @var \Symfony\Component\HttpFoundation\Request | |
*/ | |
private $request = null; | |
/** | |
* @var \Magomogo\Model\PropertyContainer\ContainerInterface | |
*/ | |
private $container; | |
/** | |
* | |
* @var \Symfony\Component\Validator\Validator | |
*/ | |
private $validator = null; | |
/** | |
* @param \Symfony\Component\HttpFoundation\Request $request | |
* @param \Magomogo\Model\PropertyContainer\ContainerInterface $container | |
* @param \Symfony\Component\Validator\Validator $validator | |
*/ | |
public function __construct($request, $container, $validator) | |
{ | |
$this->request = $request; | |
$this->container = $container; | |
$this->validator = $validator; | |
} | |
/** | |
* | |
* @return \Symfony\Component\HttpFoundation\JsonResponse | |
*/ | |
public function execute() | |
{ | |
try { | |
$id = (int) $this->request->query->get('id'); | |
$jsonContainer = new JsonContainer(); | |
$jsonContainer->incomingJson($this->request->getContent(), $this->validator); | |
$property = $jsonContainer->loadProperties(new Properties($id)); | |
$m = new Model($property); | |
$m->putIn($this->container); | |
return JsonResponse::create(array(), 201); | |
} catch (ValidationException $e) { | |
return JsonResponse::create($e->errors, 400); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment