for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Philae;
use League\Container\ContainerAwareInterface;
use League\Container\ContainerAwareTrait;
use Psr\Http\Message\ResponseInterface;
/**
* @method Application getContainer()
*/
abstract class AbstractController implements ContainerAwareInterface
{
use ContainerAwareTrait;
* Create a new URL
*
* @param string|null $to
* @param array|null $query
* @return string
protected function url(string $to = null, array $query = null): string
return $this->getContainer()->getUriResolver()->uri($to, $query)->__toString();
}
* Create a new redirect response
* @param string $to
* @param bool $permanent
* @return ResponseInterface
protected function redirect(string $to, array $query = null, bool $permanent = false): ResponseInterface
return $this->response(null, $permanent ? 301 : 302, ['Location' => $this->url($to, $query)]);
* Create a new response
* @param string|mixed $content
* @param int $code
* @param array $headers
protected function response($content, int $code = 200, array $headers = []): ResponseInterface
$response = $this->getContainer()->getResponse()->withStatus($code);
if ($content) {
$headers['Content-Length'] = strlen($content);
$response->getBody()->write($content);
foreach ($headers as $k => $v) {
$response = $response->withHeader(strtolower($k), $v);
return $response;