2016-07-31 20:47:25 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Action\Article;
|
|
|
|
|
|
2016-08-01 17:30:43 +02:00
|
|
|
use App\Service\EntityServiceInterface;
|
2016-07-31 20:47:25 +02:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
|
use Zend\Diactoros\Response\JsonResponse;
|
|
|
|
|
|
|
|
|
|
class DeleteAction
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
2016-08-01 17:30:43 +02:00
|
|
|
* @var EntityServiceInterface
|
2016-07-31 20:47:25 +02:00
|
|
|
*/
|
2016-08-01 17:30:43 +02:00
|
|
|
private $entityService;
|
2016-07-31 20:47:25 +02:00
|
|
|
|
2016-08-01 17:30:43 +02:00
|
|
|
public function __construct(EntityServiceInterface $entityService)
|
2016-07-31 20:47:25 +02:00
|
|
|
{
|
2016-08-01 17:30:43 +02:00
|
|
|
$this->entityService = $entityService;
|
2016-07-31 20:47:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
|
|
|
|
|
{
|
|
|
|
|
$id = $request->getAttribute('id');
|
|
|
|
|
|
2016-08-01 17:30:43 +02:00
|
|
|
$result = $this->entityService->delete($id);
|
|
|
|
|
|
|
|
|
|
$return = new JsonResponse($result);
|
2016-07-31 20:47:25 +02:00
|
|
|
|
2016-08-01 17:30:43 +02:00
|
|
|
if (false === $result) {
|
|
|
|
|
return $return->withStatus(500, 'Failed to delete record.');
|
2016-07-31 20:47:25 +02:00
|
|
|
}
|
|
|
|
|
|
2016-08-01 17:30:43 +02:00
|
|
|
return $return;
|
2016-07-31 20:47:25 +02:00
|
|
|
}
|
2016-08-01 17:30:43 +02:00
|
|
|
}
|