Skip to content

Commit

Permalink
Remove support for EOL versions
Browse files Browse the repository at this point in the history
* Requires PHP >= 7.2
* Requires Symfony >= 4.4
* Requires PHPUnit >= 8.5
  • Loading branch information
jsor committed Apr 15, 2020
1 parent 5cb995f commit 7a37504
Show file tree
Hide file tree
Showing 31 changed files with 213 additions and 170 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.php_cs.cache
.phpunit.result.cache
build/
composer.lock
composer.phar
phpunit.xml
var/
vendor/
12 changes: 4 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@ language: php
sudo: false

php:
- 5.6
- 7.0
- 7.1
- 7.2
- nightly
- 7.3
- 7.4

matrix:
include:
- php: 5.6
- php: 7.2
env: dependencies=lowest
- php: 7.1
- php: 7.4
env: dependencies=highest
allow_failures:
- php: nightly
fast_finish: true

cache:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Stack/Hal
[![Build Status](https://travis-ci.org/jsor/stack-hal.svg?branch=master)](https://travis-ci.org/jsor/stack-hal)
[![Coverage Status](https://coveralls.io/repos/github/jsor/stack-hal/badge.svg?branch=master)](https://coveralls.io/github/jsor/stack-hal?branch=master)

[Stack](https://stackphp.com) middlewares and utilities for working with the
[Stack](https://stackphp.com) and [Symfony](https://symfony.com) middlewares
and utilities for working with the
[Hypertext Application Language](https://tools.ietf.org/html/draft-kelly-json-hal-06)
(HAL) using [Nocarrier\HAL](https://github.com/blongden/hal).

Expand Down
28 changes: 14 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jsor/stack-hal",
"description": "Stack middlewares and utilities for working with the Hypertext Application Language (HAL).",
"keywords": ["stack", "stackphp", "hal", "vnd.error", "rest"],
"description": "Stack and Symfony middlewares and utilities for working with the Hypertext Application Language (HAL).",
"keywords": ["stack", "stackphp", "symfony", "hal", "vnd.error", "rest"],
"homepage": "https://github.com/jsor/stack-hal",
"license": "MIT",
"authors": [
Expand All @@ -11,9 +11,9 @@
}
],
"require": {
"php": "^5.6||^7.0",
"symfony/http-foundation": "^2.1||^3.0||^4.0",
"symfony/http-kernel": "^2.4||^3.0||^4.0",
"php": "^7.2",
"symfony/http-foundation": "^4.4||^5.0",
"symfony/http-kernel": "^4.4||^5.0",
"nocarrier/hal": "^0.9.4"
},
"suggest": {
Expand All @@ -27,19 +27,19 @@
"require-dev": {
"psr/log": "^1.0",

"symfony/event-dispatcher": "^2.5||^3.0||^4.0",
"symfony/event-dispatcher": "^4.4||^5.0",

"symfony/config": "^2.5||^3.0||^4.0",
"symfony/dependency-injection": "^2.5||^3.0||^4.0",
"symfony/config": "^4.4||^5.0",
"symfony/dependency-injection": "^4.4||^5.0",

"symfony/form": "^2.8||^3.0||^4.0",
"symfony/translation": "^2.5||^3.0||^4.0",
"symfony/validator": "^2.6||^3.0||^4.0",
"symfony/security-core": "^2.5||^3.0||^4.0",
"symfony/serializer": "^2.1||^3.0||^4.0",
"symfony/form": "^4.4||^5.0",
"symfony/translation": "^4.4||^5.0",
"symfony/validator": "^4.4||^5.0",
"symfony/security-core": "^4.4||^5.0",
"symfony/serializer": "^4.4||^5.0",

"willdurand/negotiation": "^2.0",
"phpunit/phpunit": "^5.7"
"phpunit/phpunit": "^8.5"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Jsor\Stack\Hal">
Expand Down
8 changes: 4 additions & 4 deletions src/EventListener/ExceptionConversionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class ExceptionConversionListener implements EventSubscriberInterface
Expand All @@ -28,10 +28,10 @@ public function __construct(
$this->formats = $formats;
}

public function onKernelException(GetResponseForExceptionEvent $event)
public function onKernelException(ExceptionEvent $event)
{
$response = ExceptionConverter::handleException(
$event->getException(),
$response = ExceptionConverter::handleThrowable(
$event->getThrowable(),
$event->getRequest(),
$this->logger,
$this->prettyPrint,
Expand Down
4 changes: 2 additions & 2 deletions src/EventListener/RequestFormatNegotiationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Jsor\Stack\Hal\RequestFormatNegotiator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class RequestFormatNegotiationListener implements EventSubscriberInterface
Expand All @@ -20,7 +20,7 @@ public function __construct(
$this->priorities = $priorities;
}

public function onKernelRequest(GetResponseEvent $event)
public function onKernelRequest(RequestEvent $event)
{
RequestFormatNegotiator::negotiate(
$event->getRequest(),
Expand Down
4 changes: 2 additions & 2 deletions src/EventListener/RequestFormatValidationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Jsor\Stack\Hal\RequestFormatValidator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class RequestFormatValidationListener implements EventSubscriberInterface
Expand All @@ -21,7 +21,7 @@ public function __construct(
$this->exclude = $exclude;
}

public function onKernelRequest(GetResponseEvent $event)
public function onKernelRequest(RequestEvent $event)
{
$response = RequestFormatValidator::intercept(
$event->getRequest(),
Expand Down
4 changes: 2 additions & 2 deletions src/EventListener/ResponseConversionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Jsor\Stack\Hal\Response\HalResponse;
use Nocarrier\Hal;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\Event\ViewEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class ResponseConversionListener implements EventSubscriberInterface
Expand All @@ -17,7 +17,7 @@ public function __construct($prettyPrint = true)
$this->prettyPrint = (bool) $prettyPrint;
}

public function onKernelView(GetResponseForControllerResultEvent $event)
public function onKernelView(ViewEvent $event)
{
$hal = $event->getControllerResult();

Expand Down
2 changes: 1 addition & 1 deletion src/Exception/ErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(
array $errors,
$message = null,
$logref = null,
\Exception $previous = null,
\Throwable $previous = null,
$code = 0
) {
parent::__construct($message, $previous, $code);
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/FormErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct(
FormInterface $form,
$message = null,
$logref = null,
\Exception $previous = null,
\Throwable $previous = null,
$code = 0
) {
parent::__construct($message, $previous, $code);
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/ValidationErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct(
ConstraintViolationListInterface $violationList,
$message = null,
$logref = null,
\Exception $previous = null,
\Throwable $previous = null,
$code = 0
) {
parent::__construct($message, $previous, $code);
Expand Down
30 changes: 15 additions & 15 deletions src/ExceptionConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function handle(
throw $exception;
}

$response = self::handleException(
$response = self::handleThrowable(
$exception,
$request,
$this->logger,
Expand All @@ -71,16 +71,16 @@ public function handle(
}
}

public static function handleException(
\Exception $exception,
public static function handleThrowable(
\Throwable $throwable,
Request $request,
LoggerInterface $logger = null,
$prettyPrint = true,
$debug = false,
array $formats = null
) {
if (null !== $logger) {
self::logException($logger, $exception);
self::logThrowable($logger, $throwable);
}

$formats = $formats ?: ['json', 'xml'];
Expand All @@ -91,28 +91,28 @@ public static function handleException(
return;
}

return VndErrorResponse::fromException(
$exception,
return VndErrorResponse::fromThrowable(
$throwable,
$prettyPrint,
$debug
);
}

public static function logException(
public static function logThrowable(
LoggerInterface $logger,
\Exception $exception
\Throwable $throwable
) {
$message = \sprintf(
'Uncaught PHP Exception %s: "%s" at %s line %s',
\get_class($exception),
$exception->getMessage(),
$exception->getFile(),
$exception->getLine()
\get_class($throwable),
$throwable->getMessage(),
$throwable->getFile(),
$throwable->getLine()
);

$isCritical = !$exception instanceof HttpExceptionInterface ||
$exception->getStatusCode() >= 500;
$context = ['exception' => $exception];
$isCritical = !$throwable instanceof HttpExceptionInterface ||
$throwable->getStatusCode() >= 500;
$context = ['exception' => $throwable];

if ($isCritical) {
$logger->critical($message, $context);
Expand Down
39 changes: 20 additions & 19 deletions src/Response/VndErrorResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

class VndErrorResponse extends HalResponse
{
Expand All @@ -30,17 +31,17 @@ public static function create(
return new static($hal, $status, $headers, $prettyPrint);
}

public static function fromException(
\Exception $exception,
public static function fromThrowable(
\Throwable $throwable,
$prettyPrint = true,
$debug = false
) {
$statusCode = self::extractStatus($exception);
$headers = self::extractHeaders($exception);
$message = self::extractMessage($exception, $debug);
$statusCode = self::extractStatus($throwable);
$headers = self::extractHeaders($throwable);
$message = self::extractMessage($throwable, $debug);

if ($exception instanceof HalException) {
$hal = $exception->getHal();
if ($throwable instanceof HalException) {
$hal = $throwable->getHal();
} else {
$hal = new Hal(null, ['message' => $message]);
}
Expand Down Expand Up @@ -71,40 +72,40 @@ public function prepare(Request $request)
return $this;
}

private static function extractStatus(\Exception $exception)
private static function extractStatus(\Throwable $throwable)
{
if ($exception instanceof HttpExceptionInterface) {
return $exception->getStatusCode();
if ($throwable instanceof HttpExceptionInterface) {
return $throwable->getStatusCode();
}

if ($exception instanceof \Symfony\Component\Security\Core\Exception\AccessDeniedException) {
if ($throwable instanceof AccessDeniedException) {
return 403;
}

return 500;
}

private static function extractHeaders(\Exception $exception)
private static function extractHeaders(\Throwable $throwable)
{
if ($exception instanceof HttpExceptionInterface) {
return $exception->getHeaders();
if ($throwable instanceof HttpExceptionInterface) {
return $throwable->getHeaders();
}

return [];
}

private static function extractMessage(\Exception $exception, $debug)
private static function extractMessage(\Throwable $throwable, $debug)
{
if ($exception instanceof HttpExceptionInterface) {
return $exception->getMessage();
if ($throwable instanceof HttpExceptionInterface) {
return $throwable->getMessage();
}

if ($debug) {
// Expose exception message only in debug mode
return $exception->getMessage();
return $throwable->getMessage();
}

if ($exception instanceof \Symfony\Component\Security\Core\Exception\AccessDeniedException) {
if ($throwable instanceof AccessDeniedException) {
return 'Access Denied';
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Exception/ErrorExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Jsor\Stack\Hal\Exception;

class ErrorExceptionTest extends \PHPUnit_Framework_TestCase
class ErrorExceptionTest extends \PHPUnit\Framework\TestCase
{
/** @test */
public function it_serializes_exception_to_json()
Expand Down
2 changes: 1 addition & 1 deletion tests/Exception/FormErrorExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Symfony\Component\Form\Forms;
use Symfony\Component\Validator\Validation;

class FormErrorExceptionTest extends \PHPUnit_Framework_TestCase
class FormErrorExceptionTest extends \PHPUnit\Framework\TestCase
{
/** @test */
public function it_serializes_exception_to_json()
Expand Down
2 changes: 1 addition & 1 deletion tests/Exception/ValidationErrorExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\ValidatorBuilder;

class ValidationErrorExceptionTest extends \PHPUnit_Framework_TestCase
class ValidationErrorExceptionTest extends \PHPUnit\Framework\TestCase
{
/** @test */
public function it_serializes_exception_to_json()
Expand Down
Loading

0 comments on commit 7a37504

Please sign in to comment.