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

Fixed parameters resolution of generated factories #17

Closed
wants to merge 2 commits into from

Conversation

enumag
Copy link
Contributor

@enumag enumag commented Sep 6, 2014

The previous commit doesn't seem to work as expected in all cases (http://forum.nette.org/cs/20601-generovane-tovarnicky-s-parametry), most probably because it was rebased several times. Of course I will add more tests for this.

@enumag
Copy link
Contributor Author

enumag commented Sep 6, 2014

I've modified the tests, didn't have to add new ones in the end. I've also prepared another branch where the fix is separated to four commits - failing test, fix, failing test, better fix - to show why the fix needs to be like this. The PR itself contains those four commits squashed.

@@ -306,6 +306,9 @@ private function resolveImplement(ServiceDefinition $def, $name)

if (!$def->parameters) {
$ctorParams = array();
if ((!$def->factory || !$def->factory->entity && !$def->factory->arguments) && $def->class) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ambiguous && and || resolution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean operators priority? Should I add (...)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By the way the && $def->class can be removed and tests will still pass.

@dg
Copy link
Member

dg commented Sep 8, 2014

@enumag Why did you modified existing test and didn't add new one?

@enumag
Copy link
Contributor Author

enumag commented Sep 8, 2014

Because I thought it would be redundant. But ok, I'll add new tests instead.

@enumag
Copy link
Contributor Author

enumag commented Sep 8, 2014

@dg Also what about && and ||? Should I add brackets for readability or not? I didn't find anything about it in Nette coding style so I did it without brackets whis was possible according to PHP operator precedence.

@dg
Copy link
Member

dg commented Sep 8, 2014

Whether it is 100% redundant, it is ok.

@enumag
Copy link
Contributor Author

enumag commented Sep 8, 2014

Well it might not be 100% so I added them.

@dg
Copy link
Member

dg commented Sep 8, 2014

Also what about && and ||?

It is really less understandable, || can be removed this way if (empty($def->factory->entity) && !$def->factory->arguments).

@enumag
Copy link
Contributor Author

enumag commented Sep 8, 2014

@dg Nope, that failed with E_NOTICE Trying to get property of non-object. By the way && has greater priority than ||. The code I used is (intentionaly) equivalent to this:

if (!$def->factory || (!$def->factory->entity && !$def->factory->arguments)) {

@enumag
Copy link
Contributor Author

enumag commented Sep 21, 2014

Now the parameters resolution magic works even if the class gets some arguments from config.

if (!$def->factory || !$def->factory->entity) {
$def->setFactory($def->class, $def->factory ? $def->factory->arguments : array());
}
if ($def->factory && ($class = $this->resolveEntityClass($def->factory, array($name => 1)))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dg What is the array($name => 1) here for? You added it when merging the feature but removing it doesn't break any test.

Copy link
Member

Choose a reason for hiding this comment

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

resolveEntityClass() uses it when throws exception.

@dg dg force-pushed the master branch 6 times, most recently from d349d3f to 7da1abe Compare November 16, 2014 14:36
@enumag
Copy link
Contributor Author

enumag commented Nov 30, 2014

ping @dg, If there is any problem with this PR I'll be happy to fix it.

@dg dg closed this in 5d5ec18 Dec 14, 2014
dg pushed a commit that referenced this pull request Feb 19, 2019
Add method to set individual service factory arguments
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.

None yet

3 participants