* 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,49 @@
<?php
namespace App\Action\Article;
use App\Entity\Article;
use Doctrine\ORM\EntityManager;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response\JsonResponse;
class DeleteAction
{
/**
* @var EntityManager
*/
private $em;
public function __construct(EntityManager $em)
{
$this->em = $em;
}
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
{
$id = $request->getAttribute('id');
if (null === ($entity = $this->em->find(Article::class, $id))) {
$ret = new JsonResponse([
'success' => false
]);
return $ret->withStatus(404);
}
try {
$this->em->remove($entity);
$this->em->flush();
} catch (\Exception $ex) {
$ret = new JsonResponse([
'success' => false
]);
return $ret->withStatus(500);
}
return new JsonResponse([
'success' => true,
]);
}
}