├── .github └── workflows │ ├── static.yml │ └── tests.yml ├── LICENSE.md ├── README.md ├── composer.json ├── phpstan.neon.dist ├── phpunit.xml.dist └── src ├── CollisionAdapterSymfonyBundle.php ├── DependencyInjection └── CollisionAdapterSymfonyExtension.php ├── EventListener └── ErrorListener.php └── Resources └── config └── services.php /.github/workflows/static.yml: -------------------------------------------------------------------------------- 1 | name: Static Analysis 2 | 3 | on: ['push', 'pull_request'] 4 | 5 | jobs: 6 | phpstan: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | matrix: 10 | dependency-version: [prefer-lowest, prefer-stable] 11 | 12 | name: PHPStan ${{ matrix.dependency-version }} 13 | 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v2 17 | 18 | - name: Setup PHP 19 | uses: shivammathur/setup-php@v2 20 | with: 21 | php-version: 8.2 22 | tools: composer 23 | coverage: none 24 | 25 | - name: Install Dependencies 26 | run: composer update --prefer-stable --no-interaction --prefer-dist --no-progress --ansi 27 | 28 | - name: Run PHPStan 29 | run: vendor/bin/phpstan analyse --no-progress --ansi 30 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: ['push', 'pull_request'] 4 | 5 | jobs: 6 | tests: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | fail-fast: true 10 | matrix: 11 | php: [7.4, 8.0, 8.1, 8.2] 12 | dependency-version: [prefer-lowest, prefer-stable] 13 | 14 | name: PHP ${{ matrix.php }} ${{ matrix.dependency-version }} 15 | 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v2 19 | 20 | - name: Setup PHP 21 | uses: shivammathur/setup-php@v2 22 | with: 23 | php-version: ${{ matrix.php }} 24 | tools: composer 25 | coverage: none 26 | 27 | - name: Setup Problem Matchers 28 | run: | 29 | echo "::add-matcher::${{ runner.tool_cache }}/php.json" 30 | echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" 31 | 32 | - name: Install PHP dependencies 33 | run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist --no-progress --ansi 34 | 35 | - name: Run Unit Tests 36 | run: vendor/bin/phpunit --colors=always 37 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Nuno Maduro 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | Collision logo 3 |
4 | Collision code example 5 |

6 | 7 |

8 | Build Status 9 | Quality Score 10 | Coverage 11 | Total Downloads 12 | Latest Stable Version 13 | License 14 |

15 | 16 | ## About Collision Adapter Symfony 17 | 18 | Collision was created by, and is maintained by [Nuno Maduro](https://github.com/nunomaduro), and is an error handler framework for console/command-line PHP applications. 19 | 20 | - Build on top of [Whoops](https://github.com/filp/whoops). 21 | - Supports [Laravel](https://github.com/laravel/laravel) & [Symfony](https://github.com/symfony/symfony) & [PHPUnit](https://github.com/sebastianbergmann/phpunit). 22 | - Built with [PHP 7](https://php.net) using modern coding standards. 23 | 24 | > **Note:** This repository contains the core code of the Collision Symfony Adapter. If you want use Collision for Laravel, for PHPUnit or for a standalone console application: visit the main [Collision repository](https://github.com/nunomaduro/collision). 25 | 26 | ## Installation & Usage 27 | 28 | > **Requires [PHP 7.1.3+](https://php.net/releases/)** 29 | 30 | Require Collision Adapter Symfony using [Composer](https://getcomposer.org): 31 | 32 | ```bash 33 | composer require nunomaduro/collision-adapter-symfony 34 | ``` 35 | 36 | ## Contributing 37 | 38 | Thank you for considering to contribute to Collision Adapter Symfony. All the contribution guidelines are mentioned [here](CONTRIBUTING.md). 39 | 40 | You can have a look at the [CHANGELOG](CHANGELOG.md) for constant updates & detailed information about the changes. You can also follow the twitter account for latest announcements or just come say hi!: [@enunomaduro](https://twitter.com/enunomaduro) 41 | 42 | ## Support the development 43 | **Do you like this project? Support it by donating** 44 | 45 | - PayPal: [Donate](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L) 46 | - Patreon: [Donate](https://www.patreon.com/nunomaduro) 47 | 48 | ## License 49 | 50 | Collision Adapter Symfony is an open-sourced software licensed under the [MIT license](LICENSE.md). 51 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nunomaduro/collision-adapter-symfony", 3 | "description": "Collision's adapter for Symfony applications. Error Reporting for console/command-line PHP applications.", 4 | "keywords": ["symfony", "bundle", "console", "command-line", "php", "cli", "error", "handling", "collision", "laravel-zero"], 5 | "license": "MIT", 6 | "type": "symfony-bundle", 7 | "authors": [ 8 | { 9 | "name": "Nuno Maduro", 10 | "email": "enunomaduro@gmail.com" 11 | } 12 | ], 13 | "require": { 14 | "php": ">=7.4", 15 | "nunomaduro/collision": ">=3.0", 16 | "symfony/framework-bundle": ">=5.3" 17 | }, 18 | "require-dev": { 19 | "phpstan/phpstan": ">=0.12", 20 | "phpunit/phpunit": ">=9.6", 21 | "symfony/filesystem": "*", 22 | "symfony/yaml": "*" 23 | }, 24 | "autoload-dev": { 25 | "psr-4": { 26 | "Tests\\": "tests/" 27 | } 28 | }, 29 | "minimum-stability": "dev", 30 | "prefer-stable": true, 31 | "autoload": { 32 | "psr-4": { 33 | "NunoMaduro\\CollisionAdapterSymfony\\": "src/" 34 | } 35 | }, 36 | "config": { 37 | "preferred-install": "dist", 38 | "sort-packages": true 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /phpstan.neon.dist: -------------------------------------------------------------------------------- 1 | parameters: 2 | level: max 3 | paths: 4 | - src 5 | reportUnmatchedIgnoredErrors: false 6 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | tests 16 | 17 | 18 | src 19 | src/Resources/config 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/CollisionAdapterSymfonyBundle.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace NunoMaduro\CollisionAdapterSymfony; 15 | 16 | use Symfony\Component\HttpKernel\Bundle\Bundle; 17 | 18 | /** 19 | * This is an Collision Adapter Symfony Bundle implementation. 20 | * 21 | * @author Nuno Maduro 22 | */ 23 | final class CollisionAdapterSymfonyBundle extends Bundle 24 | { 25 | } 26 | -------------------------------------------------------------------------------- /src/DependencyInjection/CollisionAdapterSymfonyExtension.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace NunoMaduro\CollisionAdapterSymfony\DependencyInjection; 15 | 16 | use Symfony\Component\Config\FileLocator; 17 | use Symfony\Component\DependencyInjection\ContainerBuilder; 18 | use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; 19 | use Symfony\Component\HttpKernel\DependencyInjection\Extension; 20 | 21 | /** 22 | * This is an Collision Adapter Symfony Extension implementation. 23 | * 24 | * @author Nuno Maduro 25 | */ 26 | final class CollisionAdapterSymfonyExtension extends Extension 27 | { 28 | /** 29 | * {@inheritdoc} 30 | * 31 | * @param mixed[] $configs 32 | */ 33 | public function load(array $configs, ContainerBuilder $container): void 34 | { 35 | $loader = new PhpFileLoader($container, new FileLocator(__DIR__)); 36 | 37 | $loader->load(__DIR__.'/../Resources/config/services.php'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/EventListener/ErrorListener.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace NunoMaduro\CollisionAdapterSymfony\EventListener; 15 | 16 | use NunoMaduro\Collision\Writer; 17 | use Symfony\Component\Console\Event\ConsoleErrorEvent; 18 | use Symfony\Component\Console\Exception\ExceptionInterface; 19 | use Whoops\Exception\Inspector; 20 | 21 | /** 22 | * @author Nuno Maduro 23 | */ 24 | final class ErrorListener 25 | { 26 | private Writer $writer; 27 | 28 | public function __construct(?Writer $writer = null) 29 | { 30 | $this->writer = $writer ? clone $writer : new Writer(); 31 | } 32 | 33 | /** 34 | * This event should be attached to an {@Event("Symfony\Component\Console\Event\ConsoleErrorEvent")}. 35 | * 36 | * Retrieves error from the provided event, and writes a collision exception to the 37 | * current event output. It also sets the event ExitCode to `O` avoiding the 38 | * exception to be rendered by the default Symfony console application. 39 | */ 40 | public function onConsoleError(ConsoleErrorEvent $event): void 41 | { 42 | $error = $event->getError(); 43 | 44 | if ($error instanceof ExceptionInterface) { 45 | return; 46 | } 47 | 48 | $this->writer->setOutput($event->getOutput()); 49 | $this->writer->write(new Inspector($error)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Resources/config/services.php: -------------------------------------------------------------------------------- 1 | services() 11 | ->set('collision.error_listener', ErrorListener::class) 12 | ->autowire() 13 | ->public() 14 | ->tag('kernel.event_listener', ['event' => ConsoleEvents::ERROR]); 15 | }; 16 | --------------------------------------------------------------------------------