Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[PoC] [ValueExporter] extract HttpKernel/DataCollector util to its own component#18450
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
HeahDude commentedApr 5, 2016
| Q | A |
|---|---|
| Branch? | master |
| Bug fix? | no |
| New feature? | yes |
| BC breaks? | not yet (old implementation has not been removed) |
| Deprecations? | no |
| Tests pass? | yes |
| Fixed tickets | #18149 |
| License | MIT |
| Doc PR | TODO ? |
nicolas-grekas commentedApr 5, 2016
Since master is in features freeze, and also since I really think VarDumper has almost all the required bits, I suggest not working on this right now. |
5d237ae to0e4dbe2CompareHeahDude commentedApr 5, 2016
@nicolas-grekas Thank you for your feedback, I understand. But currently, I really need it as it is proposed in that PR, to avoid requiring Anyone can feel free to use, reuse that code for other implementation/work or when it will be the time to bring it in core. I think I will maintain this branch for the time being. Thanks. |
608f750 to0028027Compare| * | ||
| * @var FormatterInterface[] | ||
| */ | ||
| protected $formatters = array(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
any new property should be private
0028027 to1afcb8bCompare| return sprintf("array(\n%s%s\n)", $indent, implode(sprintf(",\n%s", $indent), $a)); | ||
| } | ||
| // Not an array, test each formatter | ||
| foreach ($this->formatters as $formatter) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@stof So here I should use a getter ?
I've pushed some minor changes just now on that class, differences can be seen in the tests.
In fact, I've first tried to use theVarDumper component, but theValueExporter looks more likevar_export to me, notvar_dump. So I took example on the architecture of the var dumper wrapper and kept the light weight of the originalValueExporter class, since it does not need cloners, we just want the type here not a deep profile.
I guess if it should replace the logic in many place in the core among the DataCollector profile, this method will be called many time each request.dump has a more specific usage imo.
So I get I'm gonna use that component as is to handle assertion messages (logs and exceptions) in the bundle I'm working on but I can close that PR if you think it's off topic.
Does this make sense to you ?
In any case I really appreciate your review. Thanks.
ef747a3 to20a9b46CompareHeahDude commentedApr 9, 2016
Little update here:
See the tests for basic usage. |
20a9b46 to77c9637Compare77c9637 tof237ebeComparef237ebe to1bb7e7aCompareHeahDude commentedApr 19, 2016
Changelog: added |
1bb7e7a to9f2ab95Compare08d6b76 toeb65886Compareeb65886 to6e4b7e9Compare6e4b7e9 toab119f0CompareHeahDude commentedApr 23, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Changelog:
How-toSo now to register formatters, you can pass either an FQCN or an array with an FQCN and a priority as you would do for listener method: <?phpuseApp\ValueExporter\Formatter\CustomValueToStringFormatter;useApp\ValueExporter\Formatter\OverrideValueToStringFormatter;useSymfony\Component\ValueExporter\Exporter\ValueToStringExporter;useSymfony\Component\ValueExporter\ValueExporter;ValueExporter::addFormatters(array( CustomValueToStringFormatter::class,array(OverrideValueToStringFormatter::class,10),));// or using variadic argument of the constructorValueExporter::setExporter(newValueToStringExporter(array(CustomValueToStringFormatter::class,100), OverrideValueToStringFormatter::class,)); Also note that priorities are handled in
It means that you can change the priority of a formatter in runtime: <?phpuseApp\ValueExporter\Formatter\ValueToStringFormatter;useSymfony\Component\ValueExporter\ValueExporter;$value =// ...echoto_string($value);// defaultValueExporter::addFormatters(array(array(ValueToStringFormatter::class,10),));echoto_string($value);// use new formatterValueExporter::addFormatters(array(array(ValueToStringFormatter::class, -1),));echoto_string($value);// use formatter with a new priority QuestionDo you think I should allow to use the same formatter class multiple times as discussed in#18482? (ping@iltar :) I don't feel it is coherent here. I would really appreciate any one giving it a quick review or thought, I think I just need to add some other tests for better covering the priority handling. Besides that, I believe this pseudo-component is now flexible and stable enough, so I can start using it in my work on#18411 (ref#18403). Thanks to anyone giving a look at this experimental PR :) |
856cdb2 to5d73a2fCompare5d73a2f to826e8fbCompare| $priority = (int)$formatter[1]; | ||
| $formatter =$formatter[0]; | ||
| }else { | ||
| $priority =0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
You could actually do some unpacking herelist($formatter, $priority) = $formatter;. I don't really think the int cast is necessary
linaori commentedApr 23, 2016
I don't think it makes sense to use the same formatter class multiple times I think. If it doesn't support it on prio 10, it won't support it on anything lower either. |
HeahDude commentedApr 23, 2016
@iltar thank you for your review :), however I don't really understand your last sentence:
Thanks again, the style can still change, but I'd really like to stabilise the functional part for now. Cheers |
linaori commentedApr 23, 2016
If you have something hooking in on 2 priorities, let's say 10 and 20 and on 20 it doesn't trigger anything, why would it trigger something on 10? There won't be a difference in triggering both or only 1 |
HeahDude commentedApr 23, 2016
Ok I got you, you just argue in my way: one class -> one call to support => one way to support. Having the same class with two instances and different configurations, returning a different result when calling support makes no sens to me. That's why I was suggesting unique class in your PR (at least for argument value resolvers). Also I used this implementation, because I think they may be use cases for changing a priority at runtime to help debugging a particular value. Because when you need a specific overhead in |
linaori commentedApr 23, 2016
Yeah so in this PR it makes no sense because once support is declined, it won't ever return anything else. However, in my PR the difference is that there is no supports and everything is supported. In your case I think it's best to make them unique or add a warning/exception if added twice. |
HeahDude commentedApr 23, 2016
Isn't that what happens with |
| namespace Symfony\Component\ValueExporter\Formatter; | ||
| /** | ||
| * Returns a string representation of a DateTimeInterface instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Phpdocs looks like copypasted