-
Notifications
You must be signed in to change notification settings - Fork 80
feature(pipeline): add support for registering middleware #478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
8ccb3c0
7980a89
2fdf722
f4a834b
0d65e99
cdd7b39
ba285a6
f72d82a
bd78139
91af088
9c89a77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,9 +117,9 @@ public function __construct(Configuration $config, ResolverInterface $resolver = | |
| $this->http = new HttpClient($config, $guzzle ?: static::makeGuzzle()); | ||
| $this->sessionTracker = new SessionTracker($config); | ||
|
|
||
| $this->pipeline->pipe(new NotificationSkipper($config)); | ||
| $this->pipeline->pipe(new BreadcrumbData($this->recorder)); | ||
| $this->pipeline->pipe(new SessionData($this)); | ||
| $this->registerMiddleware(new NotificationSkipper($config)); | ||
| $this->registerMiddleware(new BreadcrumbData($this->recorder)); | ||
| $this->registerMiddleware(new SessionData($this)); | ||
|
|
||
| register_shutdown_function([$this, 'flush']); | ||
| } | ||
|
|
@@ -178,7 +178,7 @@ public function getConfig() | |
| */ | ||
| public function registerCallback(callable $callback) | ||
| { | ||
| $this->pipeline->pipe(new CallbackBridge($callback)); | ||
| $this->registerMiddleware(new CallbackBridge($callback)); | ||
|
|
||
| return $this; | ||
| } | ||
|
|
@@ -200,6 +200,24 @@ public function registerDefaultCallbacks() | |
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * Register a middleware object to the pipeline. | ||
| * | ||
| * @param callable $middleware | ||
| * | ||
| * @return $this | ||
| */ | ||
| public function registerMiddleware(callable $middleware) | ||
| { | ||
| if (is_callable($middleware)) { | ||
| $this->pipeline->pipe($middleware); | ||
| } else { | ||
| syslog(LOG_WARNING, 'Middleware '.get_class($middleware).' could not be added to the pipeline'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is not reachable, and should be deleted.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're correct, I was just verifying the earlier versions of PHP had the same behaviour
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They should do. Callable was introduced in php 5.4 as a typehint, and the behavior has remained the same since.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what kind of error is thrown in earlier versions of PHP, in PHP 7 it's quite explicitly a TypeError, any idea for PHP 5.6?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * Record the given breadcrumb. | ||
| * | ||
|
|
@@ -277,27 +295,21 @@ public function notifyError($name, $message, callable $callback = null) | |
| */ | ||
| public function notify(Report $report, callable $callback = null) | ||
| { | ||
| $initialUnhandled = $report->getUnhandled(); | ||
| $initialSeverity = $report->getSeverity(); | ||
| $initialReason = $report->getSeverityReason(); | ||
| $this->pipeline->execute($report, function ($report) use ($callback, $initialUnhandled, $initialSeverity, $initialReason) { | ||
| $this->pipeline->execute($report, function ($report) use ($callback) { | ||
| if ($callback) { | ||
| if ($callback($report) === false) { | ||
| $resolvedReport = null; | ||
|
|
||
| $bridge = new CallbackBridge($callback); | ||
| $bridge($report, function ($report) use ($resolvedReport) { | ||
| $resolvedReport = $report; | ||
| }); | ||
| if ($resolvedReport) { | ||
| $report = $resolvedReport; | ||
| } else { | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| $report->setUnhandled($initialUnhandled); | ||
| if ($report->getSeverity() != $initialSeverity) { | ||
| // Severity has been changed via callbacks -> severity reason should be userCallbackSetSeverity | ||
| $report->setSeverityReason([ | ||
| 'type' => 'userCallbackSetSeverity', | ||
| ]); | ||
| } else { | ||
| // Otherwise we ensure the original severity reason is preserved | ||
| $report->setSeverityReason($initialReason); | ||
| } | ||
|
|
||
| $this->http->queue($report); | ||
| }); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need to check this. The type annotation already raises an error.