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

Feature/no special treatment for injected arrays #67

Merged
merged 2 commits into from
Nov 30, 2017

Conversation

romaninsh
Copy link
Member

When DIContainerTrait was originally implemented, it had a special treatment for arrays, e.g:

$app->add('Button', 'class'=>['blue']);

Instead of replacing value of the $class property, the contents would be merged. Unfortunately this has a major impact on the way how "seeds" work, for example here:

$app->add('MyWidget', 'title'=>['MyTitle', 'hello world']);

If MyWidget already defines title property it won't be replaced with new seed instead it will be merged causing 'MyTitle' to be sent as constructor argument.

There are many cases where array merging is bad and only a single case where it's beneficial, so I'm making array injection consistent with other values and will provide a special treatment for the $class property merging inside views.

I have supplied a test-script which can be used to refactor View's setDefaults method in a test-script within this PR

  • Check if any documentation should be removed / amended.

@codecov
Copy link

codecov bot commented Nov 29, 2017

Codecov Report

Merging #67 into develop will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #67      +/-   ##
===========================================
- Coverage    99.62%   99.62%   -0.01%     
===========================================
  Files           12       12              
  Lines          537      535       -2     
===========================================
- Hits           535      533       -2     
  Misses           2        2
Impacted Files Coverage Δ
src/DIContainerTrait.php 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8315bf1...d50b6ee. Read the comment docs.

$oo = $this->mergeSeeds(['4'=>'four'], ['5'=>'five']);
$this->assertEquals($oo, ['4'=>'four', '5'=>'five']);

$oo = $this->mergeSeeds(['4'=>['four']], ['5'=>['five']]);
Copy link
Member

Choose a reason for hiding this comment

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

this test is duplicated above

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, the value is array, above value is string.

$oo = $this->mergeSeeds(['x'=>['four']], ['x'=>['five']]);
$this->assertEquals($oo, ['x'=>['four']]);

$oo = $this->mergeSeeds(['4'=>['four']], ['4'=>['five']]);
Copy link
Member

Choose a reason for hiding this comment

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

I wonder why these don't fail, because we still have that is_numeric / is_int issue: #65 not fixed, so when merging these keys '4' it should merge these values.

Copy link
Member Author

Choose a reason for hiding this comment

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

hehe me neitherr. in fact i added 'invalid' to that ticket, so when you have time create a proper case for it.

@romaninsh romaninsh merged commit e900b66 into develop Nov 30, 2017
@romaninsh romaninsh deleted the feature/no-special-treatment-for-injected-arrays branch November 30, 2017 21:54
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

2 participants