Skip to content

feature(pipeline): add support for registering middleware - #478

Merged
Cawllec merged 11 commits into
nextfrom
cawllec/add-register-middleware
Jul 3, 2018
Merged

Cawllec merged 11 commits into
nextfrom
cawllec/add-register-middleware

Conversation

@Cawllec

@Cawllec Cawllec commented May 21, 2018

Copy link
Copy Markdown
Contributor

Goal

This change adds a registerMiddleware method to the Client class that allows middleware to be directly added to the pipeline. It also shifts the consistency checks on unhandled and severity to the CallbackBridge middleware, allowing registered middleware to modify these elements.

Design

Interface changes:
public function registerMiddleware(callable $middleware)

Logic changes:
Wrapped given callback in notify in a CallbackBridge, complicating logic around calling it. Any feedback on that would be appreciated.

Changeset

Added

registerMiddleware method

Changed

Moved severity consistency checks to the CallbackBridge middleware

Tests

Added unit tests

Discussion

I'm not especially happy with the callback logic changed in notify, so any suggestions on how to neaten/improve on that would be appreciated.

Cawllec and others added 4 commits May 21, 2018 13:06
- Added register middleware method
- Added test to ensure middleware is correctly inserted into the pipeline
- Moved severity integrity logic into CallbackBridge
- Added tests for severity integrity
- Add test to ensure middleware can override severity/unhandled
@Cawllec
Cawllec requested a review from a team May 21, 2018 13:08
@kattrali kattrali changed the title feature(add registerMiddleware) feature(pipeline): add support for registering middleware May 21, 2018

@kattrali kattrali left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far. Could use a bit more tests around the interactions between CallbackBridge and custom middleware.

Tests

Added unit tests

Existing tests

  • Custom middleware can modify metadata
  • Custom middleware can modify severity

Additions

  • Custom middleware can modify unhandled state and severity reason
  • When a custom middleware sets the unhandled state, a callback cannot override it
  • When a custom middleware sets the severity and severity is later changed by a callback then the severity reason is userCallbackSetSeverity

Comment thread src/Client.php Outdated
*/
public function registerMiddleware(callable $middleware)
{
if (is_callable($middleware)) {

Copy link
Copy Markdown
Contributor

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.

@kattrali
kattrali changed the base branch from master to next June 2, 2018 01:23
Cawllec and others added 2 commits June 7, 2018 15:04
- Add tests to ensure callbacks cannot override middleware-set severity reason and unhandled
Comment thread src/Client.php Outdated
if (is_callable($middleware)) {
$this->pipeline->pipe($middleware);
} else {
syslog(LOG_WARNING, 'Middleware '.get_class($middleware).' could not be added to the pipeline');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is not reachable, and should be deleted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cawllec
Cawllec dismissed kattrali’s stale review June 11, 2018 15:35

Out of date

@Cawllec
Cawllec merged commit 4cb2c2c into next Jul 3, 2018
@Cawllec
Cawllec deleted the cawllec/add-register-middleware branch July 3, 2018 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants