Skip to content

Commit

Permalink
Merge pull request #55 from jolicode/sf-6
Browse files Browse the repository at this point in the history
Add support for Symfony 6
  • Loading branch information
pyrech authored Jun 6, 2023
2 parents 734e099 + b6eaa22 commit 3418195
Show file tree
Hide file tree
Showing 27 changed files with 264 additions and 245 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['7.4', '8.0', '8.1']
php-version: ['8.0', '8.1', '8.2']
minimum-stability: ['']
composer-flags: ['']
name: ['']
include:
- php-version: 7.4
- php-version: 8.0
composer-flags: '--prefer-lowest'
name: '(prefer lowest dependencies)'
steps:
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
/vendor

# Temporary
/Tests/app/cache
/Tests/app/logs
/tests/app/var
/tests/app/public/bundles
2 changes: 1 addition & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('app/cache')
->exclude('app/var')
->append([
__FILE__,
])
Expand Down
15 changes: 10 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# Changes between versions

## 1.8.0 (Not yet released)

* Dropped support for PHP < 8.0 and Symfony < 5.4
* Added support for PHP 8.2 and Symfony 6

## 1.7.0 (2023-06-05)

* Drop support for PHP < 7.4
* Add support for PHP 8.1
* Dropped support for PHP < 7.4
* Added support for PHP 8.1

## 1.6.4 (2021-06-14)

* Fix undefined method call exception
* Fixed undefined method call exception

## 1.6.3 (2021-06-14)

Expand All @@ -19,7 +24,7 @@

## 1.6.1 (2020-03-02)

* Fix Fatal Error support #40
* Fixed Fatal Error support #40

## 1.6.0 (2020-03-02)

Expand All @@ -33,7 +38,7 @@

## 1.4.3 (2018-07-24)

* Hid internal command
* Hide internal command

## 1.4.2 (2017-12-24) :santa:

Expand Down
15 changes: 14 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,22 @@ Run the tests using the following script:
make test
```

## Manual testing

If you want to manually test the error page, you can start the demo application
by running the following command:

```shell
cd tests/app && bin/console assets:install && symfony serve
```

Then open your browser at the displayed url (something like [http://127.0.0.1:8000](http://localhost:8000/).
You can now browse urls like [http://127.0.0.1:8000/error-XXX](http://localhost:8000/error-404)
where XXX is the HTTP status code you want to test.

## Standard code

Use [PHP CS fixer](http://cs.sensiolabs.org/) to make your code compliant with
Use [PHP CS fixer](https://cs.symfony.com/) to make your code compliant with
GifExceptionBundle's coding standards:

```shell
Expand Down
39 changes: 7 additions & 32 deletions Command/GifOptimizerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,24 @@

use ImageOptimizer\Optimizer;
use ImageOptimizer\OptimizerFactory;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(name: 'jolicode:gifexception:optimize')]
class GifOptimizerCommand extends Command
{
/**
* @var string The name of the command
*/
private const COMMAND_NAME = 'jolicode:gifexception:optimize';

/**
* @var string
*/
private const DEFAULT_OPTIMIZATION_LEVEL = '-O3';

/**
* @var int
*/
private const DEFAULT_WIDTH = 145;

/**
* @var Optimizer
*/
private $optimizer;
private Optimizer $optimizer;

/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this
->setName(self::COMMAND_NAME)
->addArgument(
'image_dir',
InputArgument::OPTIONAL,
Expand All @@ -72,15 +55,10 @@ protected function configure()
->setDescription('Optimize gifs')
;

if (method_exists($this, 'setHidden')) {
$this->setHidden(true);
}
$this->setHidden(true);
}

/**
* {@inheritdoc}
*/
protected function initialize(InputInterface $input, OutputInterface $output)
protected function initialize(InputInterface $input, OutputInterface $output): void
{
$ignoreErrors = (bool) $input->getOption('ignore_errors');
$optimizationLevel = $input->getOption('optimization_level');
Expand All @@ -95,9 +73,6 @@ protected function initialize(InputInterface $input, OutputInterface $output)
$this->optimizer = $factory->get('gif');
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$imageDir = $input->getArgument('image_dir');
Expand Down Expand Up @@ -136,7 +111,7 @@ private function formatBytes(int $bytes, bool $useStandard = true): string
if ($bytes <= $unit) {
return $bytes . ' B';
}
$exp = (int) ((log($bytes) / log($unit)));
$exp = (int) (log($bytes) / log($unit));
$pre = ($useStandard ? 'kMGTPE' : 'KMGTPE');
$pre = $pre[$exp - 1] . ($useStandard ? '' : 'i');

Expand Down
5 changes: 1 addition & 4 deletions DependencyInjection/GifExceptionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

class GifExceptionExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
if (!$container->getParameter('kernel.debug')) {
return;
Expand Down
43 changes: 12 additions & 31 deletions EventListener/ReplaceImageListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,22 @@

class ReplaceImageListener implements EventSubscriberInterface
{
/** @var string[][] */
private $gifs;

/** @var string */
private $exceptionController;

/** @var Packages */
private $packages;

/**
* @param string[][] $gifs
*/
public function __construct(array $gifs, string $exceptionController, Packages $packages = null)
{
$this->gifs = $gifs;
$this->exceptionController = $exceptionController;
$this->packages = $packages;
public function __construct(
/** @var string[][] */
private array $gifs,
private string $exceptionController,
private ?Packages $packages = null
) {
}

/**
* Handle the response for exception and replace the little Phantom by a random Gif.
*/
public function onKernelResponse(ResponseEvent $event)
public function onKernelResponse(ResponseEvent $event): void
{
// Symfony > 5.3
if (method_exists($event, 'isMainRequest')) {
if ($event->isMainRequest()
|| $event->getRequest()->attributes->get('_controller') !== $this->exceptionController) {
return;
}
} else {
if ($event->isMasterRequest()
|| $event->getRequest()->attributes->get('_controller') !== $this->exceptionController) {
return;
}
if ($event->isMainRequest()
|| $event->getRequest()->attributes->get('_controller') !== $this->exceptionController) {
return;
}

$exception = $event->getRequest()->attributes->get('exception');
Expand Down Expand Up @@ -114,15 +95,15 @@ private function getRandomGif(string $dir): string
}

/**
* Return a the url of given gif in the given directory.
* Return the url of given gif in the given directory.
*/
private function getGifUrl(string $dir, string $gif): string
{
return $this->generateUrl(sprintf('bundles/gifexception/images/%s/%s', $dir, $gif));
}

/**
* Generate an url in both Symfony 2 and Symfony 3+ compatible ways.
* Generate an url with the asset package if available.
*/
private function generateUrl(string $url): string
{
Expand Down
5 changes: 0 additions & 5 deletions GifExceptionBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@

namespace Joli\GifExceptionBundle;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class GifExceptionBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);
}
}
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

[![Latest Stable Version](https://poser.pugx.org/jolicode/gif-exception-bundle/v/stable)](https://packagist.org/packages/jolicode/gif-exception-bundle)
[![Total Downloads](https://poser.pugx.org/jolicode/gif-exception-bundle/downloads)](https://packagist.org/packages/jolicode/gif-exception-bundle)
[![Build Status](https://travis-ci.org/jolicode/GifExceptionBundle.svg?branch=main)](https://travis-ci.org/jolicode/GifExceptionBundle)

The GhostBuster of your exception page!

It displays a GIF instead of Symfony's ghost on exception page and it's compatible with Symfony versions from 4.4 to latest. Here is what it looks like :
It displays a GIF instead of Symfony's ghost on exception page and it's compatible with Symfony versions from 5.4 to latest.
Here is what it looks like :

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

*Be aware that we can not be held responsible for any loss of productivity during development.*

> **Note**
> Support for previous Symfony versions was available in previous versions of this bundle.
> See the [CHANGELOG](CHANGELOG.md) for more details.
## Installation

- Use [Composer](http://getcomposer.org/) with [Symfony Flex](https://github.com/symfony/flex) to install `GifExceptionBundle` in your project:
Expand Down
75 changes: 0 additions & 75 deletions Tests/app/AppKernel.php

This file was deleted.

11 changes: 0 additions & 11 deletions Tests/app/config/config.yml

This file was deleted.

7 changes: 0 additions & 7 deletions Tests/app/config/routing.yml

This file was deleted.

Loading

0 comments on commit 3418195

Please sign in to comment.