Skip to content
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

Move default into class so simpler ::class syntax can be used. #9806

Merged
merged 3 commits into from
Dec 9, 2016

Conversation

dereuromark
Copy link
Member

The default should be moved inside the class to allow simpler Application setup:

		$middleware
			->add(MaintenanceMiddleware::class)
			->add(ErrorHandlerMiddleware::class)
			->add(AssetMiddleware::class)
			->add(RoutingMiddleware::class);

etc

No need to force instantiation here.

* @param array $config Configuration options to use. If empty, `Configure::read('Error')`
* will be used.
*/
public function __construct($renderer = null, array $config = [])
{
if ($renderer === null) {
$renderer = Configure::read('Error.exceptionRenderer');
Copy link
Member

Choose a reason for hiding this comment

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

Couple of lines below there's Configure::read('Error') which would return array containing exceptionRenderer so a separate call seems unnecessary.

Personally I would avoid setting $this->renderer unless explicitly passed and then get the renderer directly from $this->_config in getRenderer() method if $this->renderer is unset.

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes indeed more sense alltogether. Wanna help me adjust the PR here?

@codecov-io
Copy link

codecov-io commented Nov 27, 2016

Current coverage is 94.86% (diff: 100%)

Merging #9806 into 3.next will decrease coverage by 0.01%

@@             3.next      #9806   diff @@
==========================================
  Files           417        417          
  Lines         29367      29535   +168   
  Methods        3616       3647    +31   
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          27863      28017   +154   
- Misses         1504       1518    +14   
  Partials          0          0          

Powered by Codecov. Last update 0f77dc0...803f00e

@dereuromark
Copy link
Member Author

Looks good to me.

@@ -121,6 +133,10 @@ public function handleException($exception, $request, $response)
*/
protected function getRenderer($exception)
{
if (!$this->renderer) {
$this->renderer = $this->config('exceptionRender') ?: ExceptionRenderer::class;
}
Copy link
Member

Choose a reason for hiding this comment

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

Any reason this couldn't be done in the constructor? Are you trying to avoid the class load?

Copy link
Member

Choose a reason for hiding this comment

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

I don't see the need to check for default / fallback class so early until it needs to be actually instantiated.

Copy link
Member

Choose a reason for hiding this comment

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

Ok.

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this a case for using $_defaultConfig?

Copy link
Member

@markstory markstory Nov 28, 2016

Choose a reason for hiding this comment

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

Good point, but that would introduce strings again, which is what I think @dereuromark is trying to remove.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, I only wanted to not have it outside to be a requirement to be passed in :) See the linked app PR

@@ -121,6 +133,10 @@ public function handleException($exception, $request, $response)
*/
protected function getRenderer($exception)
{
if (!$this->renderer) {
$this->renderer = $this->config('exceptionRender') ?: ExceptionRenderer::class;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be exceptionRenderer?

Copy link
Member

Choose a reason for hiding this comment

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

Yup, typo, I'll fix it.

@dereuromark
Copy link
Member Author

I rebased and fixed the name.

if (is_string($this->renderer)) {
$class = App::className($this->renderer, 'Error');
if (!$this->exceptionRenderer) {
$this->exceptionRenderer = $this->config('exceptionRender') ?: ExceptionRenderer::class;
Copy link
Member

Choose a reason for hiding this comment

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

Still needs to be exceptionRenderer.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh that name.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah the config value doesn't!atch the one in the app skeleton

@markstory markstory merged commit 089c85c into 3.next Dec 9, 2016
@markstory markstory deleted the 3.next-error-handler-middleware branch December 9, 2016 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants