From 1ae6e9fcc25a7a6a7fea795f766840989fa634a0 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 12 Oct 2017 22:29:16 +0200 Subject: [PATCH] Adds Collision --- CHANGELOG.md | 5 ++ composer.json | 5 +- phpunit.xml | 3 ++ src/Application.php | 3 ++ src/Bootstrappers/ServiceProviders.php | 17 ++++--- src/Contracts/Providers/ErrorHandler.php | 25 ++++++++++ src/Providers/ErrorHandler/ErrorHandler.php | 48 +++++++++++++++++++ .../ErrorHandler/ServiceProvider.php | 32 +++++++++++++ tests/Integration/ApplicationTest.php | 2 +- tests/TestCase.php | 4 +- 10 files changed, 132 insertions(+), 12 deletions(-) create mode 100644 src/Contracts/Providers/ErrorHandler.php create mode 100644 src/Providers/ErrorHandler/ErrorHandler.php create mode 100644 src/Providers/ErrorHandler/ServiceProvider.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 90a69b23406f..b3d888023fb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [3.7.0] - 2017-10-12 +### Added +- Added Collision listener to `phpunit.xml`. +- Core: Adds Collision. + ## [3.6.11] - 2017-10-01 ### Added - Core: Adds `config_path` helper. diff --git a/composer.json b/composer.json index 83f39b1897aa..527d4e268991 100755 --- a/composer.json +++ b/composer.json @@ -32,8 +32,9 @@ "mtdowling/cron-expression": "^1.2" }, "require-dev": { - "phpunit/phpunit": "~6.3", - "squizlabs/php_codesniffer": "^2.3" + "phpunit/phpunit": "~6.4", + "squizlabs/php_codesniffer": "^2.3", + "nunomaduro/collision": "^1.1" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index 0b97e900d80f..5491bef5974a 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -20,6 +20,9 @@ ./tests/Integration + + + ./app diff --git a/src/Application.php b/src/Application.php index c2a31538cd1b..3778d6bca3d0 100644 --- a/src/Application.php +++ b/src/Application.php @@ -11,6 +11,7 @@ use Illuminate\Contracts\Events\Dispatcher as DispatcherContract; use Illuminate\Contracts\Container\Container as ContainerContract; use LaravelZero\Framework\Contracts\Application as ApplicationContract; +use LaravelZero\Framework\Contracts\Providers\ErrorHandler as ErrorHandlerContract; /** * This is the Zero Framework application class. @@ -81,6 +82,8 @@ protected function getCommandName(InputInterface $input) */ protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output) { + $this->container->make(ErrorHandlerContract::class)->setOutput($output); + return parent::doRunCommand($this->runningCommand = $command, $input, $output); } diff --git a/src/Bootstrappers/ServiceProviders.php b/src/Bootstrappers/ServiceProviders.php index a0583baa3cbe..a8456f3472e4 100644 --- a/src/Bootstrappers/ServiceProviders.php +++ b/src/Bootstrappers/ServiceProviders.php @@ -21,6 +21,7 @@ class ServiceProviders extends Bootstrapper * @var string[] */ protected $providers = [ + Providers\ErrorHandler\ServiceProvider::class, EventServiceProvider::class, CacheServiceProvider::class, Providers\Composer\ServiceProvider::class, @@ -64,13 +65,17 @@ public function bootstrap(): void ) ->each( function ($serviceProvider) { - $instance = new $serviceProvider($this->container); - if (method_exists($instance, 'register')) { - $instance->register(); + $provider = new $serviceProvider($this->container); + if (method_exists($provider, 'register')) { + $provider->register(); } - - if (method_exists($instance, 'boot')) { - $instance->boot(); + } + ) + ->each( + function ($serviceProvider) { + $provider = new $serviceProvider($this->container); + if (method_exists($provider, 'boot')) { + $this->container->call([$provider, 'boot']); } } ); diff --git a/src/Contracts/Providers/ErrorHandler.php b/src/Contracts/Providers/ErrorHandler.php new file mode 100644 index 000000000000..f9013bbfcb93 --- /dev/null +++ b/src/Contracts/Providers/ErrorHandler.php @@ -0,0 +1,25 @@ + + */ +interface ErrorHandler +{ + /** + * Registers the error handler. + */ + public function register(): void; + + /** + * Sets the output of the error handler. + * + * @param \Symfony\Component\Console\Output\OutputInterface $output + */ + public function setOutput(OutputInterface $output): void; +} diff --git a/src/Providers/ErrorHandler/ErrorHandler.php b/src/Providers/ErrorHandler/ErrorHandler.php new file mode 100644 index 000000000000..f71505808ae7 --- /dev/null +++ b/src/Providers/ErrorHandler/ErrorHandler.php @@ -0,0 +1,48 @@ + + */ +class ErrorHandler implements ErrorHandlerContract +{ + /** + * @var \NunoMaduro\Collision\Contracts\Provider + */ + protected $provider; + + /** + * Creates a new instance of the class. + * + * @param \NunoMaduro\Collision\Contracts\Provider|null $provider + */ + public function __construct(ProviderContract $provider = null) + { + $this->provider = $provider ?: new Provider; + } + + /** + * @inheritdoc + */ + public function register(): void + { + $this->provider->register(); + } + + /** + * @inheritdoc + */ + public function setOutput(OutputInterface $output): void + { + $this->provider->getHandler() + ->setOutput($output); + } +} diff --git a/src/Providers/ErrorHandler/ServiceProvider.php b/src/Providers/ErrorHandler/ServiceProvider.php new file mode 100644 index 000000000000..b5299e6e014f --- /dev/null +++ b/src/Providers/ErrorHandler/ServiceProvider.php @@ -0,0 +1,32 @@ + + */ +class ServiceProvider extends BaseServiceProvider +{ + /** + * @inheritdoc + */ + public function boot(ErrorHandlerContract $errorHandler): void + { + $errorHandler->register(); + } + + /** + * @inheritdoc + */ + public function register(): void + { + $this->app->singleton(ErrorHandlerContract::class, function() { + return new ErrorHandler; + }); + } +} diff --git a/tests/Integration/ApplicationTest.php b/tests/Integration/ApplicationTest.php index c35f11a292a9..c696d959268a 100755 --- a/tests/Integration/ApplicationTest.php +++ b/tests/Integration/ApplicationTest.php @@ -1,6 +1,6 @@