Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Closed

Conversation

@HeahDude
Copy link
Contributor

QA
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
LicenseMIT
Doc PRTODO ?

@HeahDudeHeahDude changed the title[ValueExporter] extract HttpKernel/DataCollector util to its own component[PoC] [ValueExporter] extract HttpKernel/DataCollector util to its own componentApr 5, 2016
@nicolas-grekas
Copy link
Member

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.

@HeahDudeHeahDudeforce-pushed thecomponent/value-exporter branch from5d237ae to0e4dbe2CompareApril 5, 2016 18:06
@HeahDude
Copy link
ContributorAuthor

@nicolas-grekas Thank you for your feedback, I understand.

But currently, I really need it as it is proposed in that PR, to avoid requiringsymfony/http-kernel for theValueExporter only and to add it some flexibility.

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.

@HeahDudeHeahDudeforce-pushed thecomponent/value-exporter branch 2 times, most recently from608f750 to0028027CompareApril 6, 2016 11:38
*
* @var FormatterInterface[]
*/
protected $formatters = array();
Copy link
Member

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

@HeahDudeHeahDudeforce-pushed thecomponent/value-exporter branch from0028027 to1afcb8bCompareApril 7, 2016 08:41
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) {
Copy link
ContributorAuthor

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.

@HeahDudeHeahDudeforce-pushed thecomponent/value-exporter branch 4 times, most recently fromef747a3 to20a9b46CompareApril 9, 2016 12:25
@HeahDude
Copy link
ContributorAuthor

Little update here:

  • addressed@stof comment aboutformatters property inAbstractValueExporter,
  • added an abstractExpandedFormatter to use expanded exports (exporting nested values).
  • addedTraversableToStringFormatter extending the newExpandedFormatter.
    (this formatter is not added by default)

See the tests for basic usage.

@HeahDude
Copy link
ContributorAuthor

Changelog: addedEntityToStringFormatter.

@HeahDudeHeahDudeforce-pushed thecomponent/value-exporter branch from1bb7e7a to9f2ab95CompareApril 20, 2016 15:55
@HeahDudeHeahDudeforce-pushed thecomponent/value-exporter branch 2 times, most recently from08d6b76 toeb65886CompareApril 21, 2016 17:50
@HeahDudeHeahDudeforce-pushed thecomponent/value-exporter branch fromeb65886 to6e4b7e9CompareApril 23, 2016 06:37
@HeahDudeHeahDudeforce-pushed thecomponent/value-exporter branch from6e4b7e9 toab119f0CompareApril 23, 2016 06:48
@HeahDude
Copy link
ContributorAuthor

HeahDude commentedApr 23, 2016
edited
Loading

Changelog:

  • eb1a34d added a priority handling for formatters.
    Using eitherAbstractValueExporter::__construct($formatter, $_...)
    orValueExporter::addFormatters(array $formatters).
  • 0e066a1 madeExpandedFormatter a trait for formatters needing recursive export.
  • 677c3c2 fixed an issue with the class name resolution in theInvalidFormatterException message.
  • 8f63b07 added support for FQCN formatters registration instead of passing instances.
  • a83684c added support for objects implementing__toString().
  • ab119f0 tweaked theCallableToStringFormatter.

How-to

So 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 inAbstractValueExporter holding three private arrays:

  • $formatters =>array($formatterFqcn => (int) $priority, ...)
  • $sortedFormatters =>array($formatterInstance, ...)
  • $cachedFormatters =>array($formatterFqcn => $formatterInstance, ...)

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

Question

Do 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 :)

@HeahDudeHeahDudeforce-pushed thecomponent/value-exporter branch from856cdb2 to5d73a2fCompareApril 23, 2016 07:18
@HeahDudeHeahDudeforce-pushed thecomponent/value-exporter branch from5d73a2f to826e8fbCompareApril 23, 2016 07:20
$priority = (int)$formatter[1];
$formatter =$formatter[0];
}else {
$priority =0;
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
ContributorAuthor

@iltar thank you for your review :), however I don't really understand your last sentence:

If it doesn't support it on prio 10, it won't support it on anything lower either.

Thanks again, the style can still change, but I'd really like to stabilise the functional part for now.

Cheers

@linaori
Copy link
Contributor

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
Copy link
ContributorAuthor

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 insupports you may want to move it to the latest after using it.

@linaori
Copy link
Contributor

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
Copy link
ContributorAuthor

Isn't that what happens withArgumentValueResolverInterface::supports andEncoder::supportsEncoding from serializer? That's why I was thinking of a parameter to test unique classes.

namespace Symfony\Component\ValueExporter\Formatter;

/**
* Returns a string representation of a DateTimeInterface instance.
Copy link
Contributor

Choose a reason for hiding this comment

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

Phpdocs looks like copypasted

HeahDude reacted with laugh emoji
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@HeahDude@nicolas-grekas@linaori@Koc@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp