Skip to content

Commit

Permalink
Drop compatibility with PHP < 5.5.9 and Symfony < 2.7 and add support…
Browse files Browse the repository at this point in the history
… for Symfony 4.0
  • Loading branch information
pyrech committed Nov 17, 2017
1 parent 6ddf88c commit 01de894
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 36 deletions.
55 changes: 37 additions & 18 deletions .travis.yml
@@ -1,31 +1,50 @@
language: php

sudo: false

dist: trusty

cache:
directories:
- $HOME/.composer/cache
php:
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm

env:
global:
- deps=high
- TARGET=test

matrix:
fast_finish: true
include:
- php: hhvm
- php: 5.4
env: deps=low
- php: 7.0
env: TARGET=cs_dry_run
- php: 5.5
env: COMPOSER_FLAGS="--prefer-lowest"
# test 2.7 LTS
- php: 5.6
env: deps=high
- php: 7.0
env: deps=low
env: SYMFONY_VERSION=2.7.*
# test 2.8 LTS
- php: 5.6
env: SYMFONY_VERSION=2.8.*
# test the latest stable 3.x release
- php: 5.6
env: SYMFONY_VERSION=^3.0
# test the latest release (including beta releases)
- php: 7.1
env: DEPENDENCIES=beta
allow_failures:
- php: hhvm

sudo: false

cache:
directories:
- $HOME/.composer/cache

before_install:
- if [ "$DEPENDENCIES" = "beta" ]; then perl -pi -e 's/^}$/,"minimum-stability":"beta"}/' composer.json; fi;
- if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi;
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then echo "memory_limit=2G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi;

install:
- if [ "$deps" = "low" ]; then composer update --prefer-dist --prefer-lowest; fi;
- if [ "$deps" != "low" ]; then composer update --prefer-dist; fi;
install: composer update --prefer-dist --no-interaction $COMPOSER_FLAGS

script:
- make test
- make $TARGET
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
# Changes between versions

## Not yet released

* Added compatibility with Symfony 4.0
* Dropped compatibility with PHP < 5.5.9 and Symfony < 2.7

## 1.3.0 (2017-04-10)

* Updated PHP-CS-Fixer to version 2
Expand Down
8 changes: 3 additions & 5 deletions EventListener/ReplaceImageListener.php
Expand Up @@ -13,7 +13,6 @@

use Symfony\Component\Asset\Packages;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Templating\Helper\CoreAssetsHelper;

Expand Down Expand Up @@ -54,8 +53,7 @@ public function __construct(array $gifs, $exceptionController, Packages $package
*/
public function onKernelResponse(FilterResponseEvent $event)
{
// $event->isMasterRequest() method was added in Symfony 2.4
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()
if ($event->isMasterRequest()
|| $event->getRequest()->attributes->get('_controller') !== $this->exceptionController) {
return;
}
Expand Down Expand Up @@ -119,7 +117,7 @@ private function getGifDir($statusCode)
*/
private function getRandomGif($dir)
{
$imageIndex = rand(0, count($this->gifs[$dir]) - 1);
$imageIndex = mt_rand(0, count($this->gifs[$dir]) - 1);

return $this->gifs[$dir][$imageIndex];
}
Expand All @@ -138,7 +136,7 @@ private function getGifUrl($dir, $gif)
}

/**
* Generate an url in both Symfony 2 and Symfony 3 compatible ways.
* Generate an url in both Symfony 2 and Symfony 3+ compatible ways.
*
* @param string $url
*
Expand Down
5 changes: 4 additions & 1 deletion Makefile
@@ -1,5 +1,8 @@
cs:
./vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --verbose
./vendor/bin/php-cs-fixer fix --verbose

cs_dry_run:
./vendor/bin/php-cs-fixer fix --verbose --dry-run

test:
./vendor/bin/phpunit
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -10,7 +10,7 @@ It displays a GIF instead of Symfony's ghost on exception page:

![Demo](Resources/doc/images/demo.gif)

It's compatible with Symfony versions from 2.3 to latest. Here is what it looks like with Symfony 3.3+:
It's compatible with Symfony versions from 2.7 to latest. Here is what it looks like with Symfony 3.3+:

![Demo sf 3.3](Resources/doc/images/demo-sf-3-3.gif)

Expand Down
8 changes: 7 additions & 1 deletion Tests/FunctionalTest.php
Expand Up @@ -73,13 +73,19 @@ private function getImage($content)
@$dom->loadHTML($content); // svg throw a warning
$xpath = new \DomXpath($dom);

// SF < 3.2
// SF < 3.2 and image replaced
$image = $xpath->query('//img[@alt="Exception detected!"]')->item(0);

if (!$image) {
// SF < 3.3
$image = $xpath->query('//svg[@width="112"]')->item(0);
}

if (!$image) {
// SF >= 3.3
$image = $xpath->query('//div[contains(@class, "exception-illustration")]/svg')->item(0);
}

$this->assertNotNull($image);

return $image;
Expand Down
20 changes: 10 additions & 10 deletions composer.json
Expand Up @@ -13,24 +13,24 @@
]
},
"require": {
"php": "~5.4|^7.0",
"symfony/framework-bundle": "~2.3|~3.0"
"php": "^5.5.9 || ^7.0",
"symfony/framework-bundle": "^2.7 || ^3.0 || ^4.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2.0",
"phpunit/phpunit": "~4.8|~5.0",
"phpunit/phpunit": "~4.8 || ~5.0",
"ps/image-optimizer": "^1.0.4",
"symfony/config": "~2.3|~3.0",
"symfony/dependency-injection": "~2.3|~3.0",
"symfony/http-kernel": "~2.3|~3.0",
"symfony/twig-bundle": "~2.3|~3.0",
"symfony/asset": "~2.3|~3.0",
"symfony/templating": "~2.3|~3.0",
"symfony/config": "^2.7 || ^3.0 || ^4.0",
"symfony/dependency-injection": "^2.7 || ^3.0 || ^4.0",
"symfony/http-kernel": "^2.7 || ^3.0 || ^4.0",
"symfony/twig-bundle": "^2.7 || ^3.0 || ^4.0",
"symfony/asset": "^2.7 || ^3.0 || ^4.0",
"symfony/templating": "^2.7 || ^3.0 || ^4.0",
"doctrine/annotations": "^1.2"
},
"extra": {
"branch-alias": {
"dev-master": "1.3.x-dev"
"dev-master": "1.4.x-dev"
}
}
}

0 comments on commit 01de894

Please sign in to comment.