File: /var/www/vhosts/creativefellows.nl/horizon.creativefellows.nl/src/Action/Action.php
<?php
namespace App\Action;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use App\Domain\Language\LanguageData;
use Psr\Container\ContainerInterface;
use Slim\Exception\HttpBadRequestException;
use Slim\Exception\HttpNotFoundException;
abstract class Action
{
/**
* @var Request
*/
protected $request;
/**
* @var Response
*/
protected $response;
/**
* @var Container
*/
protected $container;
/**
* @var array
*/
protected $args;
public function __construct(ContainerInterface $container, LanguageData $language)
{
//$this->responder = $responder;
$this->container = $container;
$this->language = $language;
}
/**
* @param Request $request
* @param Response $response
* @param array $args
* @return Response
* @throws HttpNotFoundException
* @throws HttpBadRequestException
*/
public function __invoke(Request $request, Response $response, $args): Response
{
$this->request = $request;
$this->response = $response;
$this->args = $args;
return $this->action();
}
/**
* @return Response
* @throws DomainRecordNotFoundException
* @throws HttpBadRequestException
*/
abstract protected function action(): Response;
public function respond(array $array = []){
$json = json_encode($array, JSON_PRETTY_PRINT);
$this->response->getBody()->write($json);
return $this->response
->withHeader('Content-Type', 'application/json')
->withStatus(200);
}
}