* initial commit

This commit is contained in:
Danyi Dávid
2016-07-31 20:47:25 +02:00
commit f3939bbd13
62 changed files with 6827 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Action\Article;
use App\Action\AbstractFormAction;
use App\Entity\Article;
use App\Hydrator\DoctrineObject;
use Doctrine\ORM\EntityManager;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response\JsonResponse;
class PostAction extends AbstractFormAction
{
/**
* @var EntityManager
*/
private $em;
/**
* @var DoctrineObject
*/
private $hydrator;
public function __construct(EntityManager $em, DoctrineObject $hydrator)
{
$this->em = $em;
$this->hydrator = $hydrator;
}
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
{
$data = $this->getRequestData($request);
$entity = $this->hydrator->hydrate($data, new Article());
$this->em->persist($entity);
$this->em->flush();
return new JsonResponse([
'success' => true,
'result' => $entity,
]);
}
}