Skip to content

Commit

Permalink
Merge pull request #12 from esbenp/fix-8
Browse files Browse the repository at this point in the history
Move reporter binding to service provider
  • Loading branch information
esbenp authored Apr 17, 2017
2 parents 7e4f09e + 4b91ab2 commit eda2d19
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public function report(Exception $e)

$config = isset($reporter['config']) && is_array($reporter['config']) ? $reporter['config'] : [];

$reporterInstance = $this->container->make($class, [$config]);
// $this->container->make($class)($config) fails php <= 5.4
$reporterFactory = $this->container->make($class);
$reporterInstance = $reporterFactory($config);

$this->reportResponses[$key] = $reporterInstance->report($e);
}
Expand Down
18 changes: 18 additions & 0 deletions src/Provider/LaravelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
namespace Optimus\Heimdal\Provider;

use Illuminate\Support\ServiceProvider as BaseProvider;
use Optimus\Heimdal\Reporters\BugsnagReporter;
use Optimus\Heimdal\Reporters\SentryReporter;

class LaravelServiceProvider extends BaseProvider {

public function register()
{
$this->loadConfig();
$this->registerAssets();
$this->bindReporters();
}

private function registerAssets()
Expand All @@ -25,4 +28,19 @@ private function loadConfig()
$this->app['config']->set('optimus.heimdal', require __DIR__.'/../config/optimus.heimdal.php');
}
}

private function bindReporters()
{
$this->app->bind(BugsnagReporter::class, function ($app) {
return function (array $config) {
return new BugsnagReporter($config);
};
});

$this->app->bind(SentryReporter::class, function ($app) {
return function (array $config) {
return new SentryReporter($config);
};
});
}
}
6 changes: 6 additions & 0 deletions tests/ExceptionHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public function setUp()
*/
private function createHandler()
{
app()->bind(TestReporter::class, function($app){
return function (array $config) {
return new TestReporter($config);
};
});

return app()->make(ExceptionHandler::class);
}

Expand Down

0 comments on commit eda2d19

Please sign in to comment.