Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Create configured FinalHandler if one is not available in the container #309

Closed
wants to merge 1 commit into from
Closed

Create configured FinalHandler if one is not available in the container #309

wants to merge 1 commit into from

Conversation

michaelmoussa
Copy link
Contributor

@michaelmoussa michaelmoussa commented Feb 3, 2016

@weierophinney this piggybacks on what we discussed earlier with regard to the issue that inspired this PR on the Stratigility repo.

The first part of the other PR fixes the stack traces in production issue, and the second adds the setOriginalResponse($response); to the FinalHandler in order to allow someone to create a properly configured FinalHandler ahead of time. The Application would then inject the original response when it calls ->getFinalHandler().

The purpose of this new PR is to provide support for configuring the FinalHandler that Expressive automatically creates without needing to create a new factory class. Developers would just need to add the desired final handler options to their config.

There's a caveat, though - it depends on the Stratigility PR.

This version of this PR should not be merged until the Stratigility PR is merged, a new version is tagged, and Expressive's composer.json entry for zendframework/zend-stratigility reflects the dependency on that version. This implementation needs FinalHandler to support setOriginalResponse, otherwise, 200 OK responses will return 404s instead (since no original response is being injected into the FinalHandler).

I don't think the full solution would be considered a BC break, though, since people who were providing their own FinalHandler will not be affected, and people who were relying on the default will not notice a thing.

Let me know if you think a proper Zend\Expressive\FinalHandlerFactory that folks need to explicitly add to their dependencies config would be a better solution, otherwise, I'll take care of the composer.json update once the other PR is merged and tagged and update this PR.

@michaelmoussa
Copy link
Contributor Author

Closing & re-opening to trigger a new Travis build, since my pending zendframework/zend-stratigility PR has been merged.

@michaelmoussa
Copy link
Contributor Author

@weierophinney now that this build will pass once Travis finishes running again, what do you think?

Basically, instead of defaulting an unset FinalHandler to null, it'll create a new one based on the final_handler options available in the configuration.

Alternatively, I could create a Zend\Expressive\FinalHandlerFactory to encapsulate the creation-from-config logic, which will allow the default to remain null, but will allow users to just configure their DI container to use the Expressive default and not need to write their own to support options-based creation (that's probably the better option, actually, as these days I hate seeing new in constructors 😄). Let me know and I'll go ahead and change it.

$config = $container->has('config') ? $container->get('config') : [];
$options = isset($config['final_handler']['options']) ? $config['final_handler']['options'] : [];
$finalHandler = new FinalHandler($options, null);
}
Copy link
Member

Choose a reason for hiding this comment

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

I'd extract the above logic to a private method, so that the logic here can be simply something like $finalHandler = $this->marshalFinalHandler($container);.

@weierophinney
Copy link
Member

Alternatively, I could create a Zend\Expressive\FinalHandlerFactory to encapsulate the creation-from-config logic

I like this approach, but it would require existing users to update their configuration to add a dependency map for it. As such, let's stick to an internal, private method for this as suggested above.

@weierophinney weierophinney added this to the 1.1.0 milestone Mar 17, 2016
@weierophinney weierophinney self-assigned this Mar 17, 2016
@weierophinney
Copy link
Member

One more thing: update the composer.json to pin to zend-stratigility ^1.2.0.

@michaelmoussa
Copy link
Contributor Author

@weierophinney done and done

@@ -22,7 +22,7 @@
"zendframework/zend-diactoros": "^1.1",
"zendframework/zend-expressive-router": "^1.1",
"zendframework/zend-expressive-template": "^1.0.1",
"zendframework/zend-stratigility": "^1.1"
"zendframework/zend-stratigility": "^1.2.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

^1.2 instead?

Copy link
Member

Choose a reason for hiding this comment

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

They're semantically equivalent. ^ will allow from that version to next
major. (vs ~, which limits to the same minor version.)
On Mar 21, 2016 6:23 PM, "Michaël Gallego" [email protected] wrote:

In composer.json
#309 (comment)
:

@@ -22,7 +22,7 @@
"zendframework/zend-diactoros": "^1.1",
"zendframework/zend-expressive-router": "^1.1",
"zendframework/zend-expressive-template": "^1.0.1",

  •    "zendframework/zend-stratigility": "^1.1"
    
  •    "zendframework/zend-stratigility": "^1.2.0"
    

^1.2 instead?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/zendframework/zend-expressive/pull/309/files/889ed8b8ddeb9c92de319184aa9377d22d9112f5#r56914722

weierophinney added a commit that referenced this pull request Aug 15, 2016
…-handler

Create configured FinalHandler if one is not available in the container
weierophinney added a commit that referenced this pull request Aug 15, 2016
weierophinney added a commit that referenced this pull request Aug 15, 2016
@weierophinney
Copy link
Member

Thanks for the patch, @michaelmoussa! Merged to develop for release with 1.1.0.

weierophinney pushed a commit to weierophinney/zend-expressive that referenced this pull request Jan 30, 2017
Backport zendframework#309 for release with 1.1.0.

Conflicts:
	composer.json
	src/Container/ApplicationFactory.php
weierophinney pushed a commit to weierophinney/zend-expressive that referenced this pull request Feb 8, 2017
Backport zendframework#309 for release with 1.1.0.

Conflicts:
	composer.json
	src/Container/ApplicationFactory.php
weierophinney added a commit that referenced this pull request Feb 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants