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

individual checks before calling inject* methods #634

Merged
merged 2 commits into from
Aug 28, 2018

Conversation

pine3ree
Copy link
Contributor

This could be considered just as a tiny refactoring / code-style change: no bugs, no new features

  1. don't call an inject* method with missing/empty related config values
  2. check for empty routes in injectRoutesFromConfig before checking is_array and running the loop on an empty array (this make more sense if the method is called outside this delegator, which, now, already checks for emptiness before calling it)

1. don't call a method for missing/empty config values
2. check for empty routes in `injectRoutesFromConfig` before checking is_array and running the loop on an empty array (this can be useful if the method is called outside this delegator, which, now,  already checks for emptiness before calling it)
@@ -172,7 +173,7 @@ public static function injectPipelineFromConfig(Application $application, array
*/
public static function injectRoutesFromConfig(Application $application, array $config) : void
{
if (! isset($config['routes']) || ! is_array($config['routes'])) {
if (empty($config['routes']) || ! is_array($config['routes'])) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about this change. It's a public function and when used directly, you will get an undefined index notice.

Copy link
Contributor Author

@pine3ree pine3ree Aug 25, 2018

Choose a reason for hiding this comment

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

Hello @xtreamwayz , why?
empty acts like ! isset() plus not-empty value. I am just using a stronger checking. I just intercept empty arrays (or whatever) as well...

before: if not set or not array return (does not return early for empty arrays, no need to loop over an empty array)
my-mod: if not set or empty (whatever) or not array return

I am just making the function skip the for loop in case of an empty array

kind regards

Copy link
Member

Choose a reason for hiding this comment

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

Huh... for some reason I thought it would through a notification but it doesn't. Ignore my comment :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xtreamwayz ,no problem :-)
I was also thinking about storing the resulting locale in a request attribute instead of using Locale::setDefault() in order to make it compatible with async-php setups. What do you reckon?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xtreamwayz , oh ...another thing I forgot... the $config var is casted to an array because the inject* methods requires it, so I left it alone...but since I now check for key existence $config should be an array or at least implement ArrayAccess. Usually if a config service exists in a zend-expressive application, it is an array, so we could also remove those argument castings unless we want to support a non array ArrayAccess configuration object.

kind regards

Copy link
Member

@geerteltink geerteltink Aug 25, 2018

Choose a reason for hiding this comment

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

I was also thinking about storing the resulting locale in a request attribute instead of using Locale::setDefault() in order to make it compatible with async-php setups. What do you reckon?

This is what I do usually. So yes, go ahead.

EDIT: This is for the other PR right?

oh ...another thing I forgot... the $config var is casted to an array because the inject* methods requires it, so I left it alone...but since I now check for key existence $config should be an array or at least implement ArrayAccess. Usually if a config service exists in a zend-expressive application, it is an array, so we could also remove those argument castings unless we want to support a non array ArrayAccess configuration object.

Config should always be an array or ArrayAccess object for Aura.Di.

Usually what we do is $config = $container->get('config') ?? [];.

Copy link
Contributor Author

@pine3ree pine3ree Aug 25, 2018

Choose a reason for hiding this comment

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

@xtreamwayz 1. Oh gosh...yes..right....i have a "few" repos open in so many browser tabs and too little sleep... 2. Good, I am glad I didn't remove the array castings since we need to support ArrayAccess for Aura.Di. best regards.

@weierophinney weierophinney merged commit a193795 into zendframework:master Aug 28, 2018
weierophinney added a commit that referenced this pull request Aug 28, 2018
individual checks before calling `inject*` methods
weierophinney added a commit that referenced this pull request Aug 28, 2018
weierophinney added a commit that referenced this pull request Aug 28, 2018
weierophinney added a commit that referenced this pull request Aug 28, 2018
@weierophinney
Copy link
Member

Thanks, @pine3ree.

@pine3ree pine3ree deleted the patch-3 branch August 29, 2018 07:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants