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

[Serializer][FrameworkBundle] Add a YAML encoder#19326

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
dunglas wants to merge5 commits intosymfony:masterfromdunglas:yaml_encoder

Conversation

@dunglas
Copy link
Member

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed ticketsn/a
LicenseMIT
Doc PRtodo

Add YAML support to the Serializer.

sstok, Simperfit, hason, theofidry, yceruto, and GuilhemN reacted with thumbs up emoji
@dunglasdunglas changed the titleYaml encoder[Serializer][FrameworkBundle] Add a YAML encoderJul 10, 2016
private $parser;
private $defaultContext;

public function __construct(Dumper $dumper = null, Parser $parser = null, $defaultContext = array('yaml_inline' => 0, 'yaml_indent' => 0, 'yaml_flags' => 0))
Copy link
Contributor

Choose a reason for hiding this comment

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

Add typehintarray $defaultContext

Copy link
Member

Choose a reason for hiding this comment

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

rather than putting a default value here, you should merge the default with the argument being received.
Otherwise, you have no guarantee about the available keys (and so your access to context options will be unsafe)

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Thanks! Fixed.

@dunglas
Copy link
MemberAuthor

ping @symfony/deciders

$definition->addTag('serializer.normalizer',array('priority' => -900));
}

if (class_exists(YamlEncoder::class)) {
Copy link
Contributor

@GuilhemNGuilhemNJul 18, 2016
edited
Loading

Choose a reason for hiding this comment

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

You must also ensure thatsymfony/yaml is loaded as it isa dev dependency of theframework-bundle.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

It is not necessary because of this particular check. If the class doesn't exist (composant not installed), the encoder will not be registered.

Copy link
Member

Choose a reason for hiding this comment

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

@dunglas yes, but here, YamlEncoder refer to the serializer component.

Copy link
MemberAuthor

@dunglasdunglasJul 19, 2016
edited
Loading

Choose a reason for hiding this comment

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

In fact no. The class constant has a special behavior.

useSomething\That\Not\Exist;echo Exist::class;

This snippet will display the FQCN even if the class not exists.

Copy link
Member

Choose a reason for hiding this comment

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

Dueuse Symfony\Component\Serializer\Encoder\YamlEncoder; this line will not check whether or not a class exists in the Yaml namespace

Copy link
Contributor

@GuilhemNGuilhemNJul 19, 2016
edited
Loading

Choose a reason for hiding this comment

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

Your check ensures that theSerializer component is loaded but you don't know if theYaml component is loaded too.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Ok got it.

Copy link
Member

Choose a reason for hiding this comment

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

The existing check is useful though, to keep compatibility with serializer 3.1 (other checks above also ensure compat with different versions of the component)

Copy link
Member

Choose a reason for hiding this comment

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

You also need to ensure that the Yaml component is present in version 3.1 or higher (e.g. by checking for existence of one of theYaml::* constants).

@dunglas
Copy link
MemberAuthor

Comments fixed. OK to merge?

@fabpot
Copy link
Member

Thank you@dunglas.

@fabpotfabpot closed thisSep 14, 2016
fabpot added a commit that referenced this pull requestSep 14, 2016
…las)This PR was squashed before being merged into the 3.2-dev branch (closes#19326).Discussion----------[Serializer][FrameworkBundle] Add a YAML encoder| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | n/a| License       | MIT| Doc PR        | todoAdd YAML support to the Serializer.Commits-------9366a7d [Serializer][FrameworkBundle] Add a YAML encoder
{
$context = array_merge($this->defaultContext, $context);

return Yaml::parse($data, $context['yaml_flags']);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't you use the injected parser instead of performing a static call?

Copy link
Member

Choose a reason for hiding this comment

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

I agree (see#20006).

fabpot added a commit that referenced this pull requestSep 21, 2016
This PR was merged into the 3.2-dev branch.Discussion----------[Serializer] use the injected YAML parser| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#19326 (comment)| License       | MIT| Doc PR        |Commits-------a40c0e4 [Serializer] use the injected YAML parser
@fabpotfabpot mentioned this pull requestOct 27, 2016
xabbuh added a commit to symfony/symfony-docs that referenced this pull requestDec 12, 2016
This PR was submitted for the master branch but it was merged into the 3.2 branch instead (closes#7040).Discussion----------[Serializer] Docs for CSV and YAML encodersDocs forsymfony/symfony#19197 andsymfony/symfony#19326.Commits-------5687972 [Serializer] Docs for CSV and YAML encoders.
wouterj added a commit to symfony/symfony-docs that referenced this pull requestOct 13, 2017
…r (GuilhemN)This PR was submitted for the 3.2 branch but it was merged into the 3.3 branch instead (closes#7654).Discussion----------[Serializer] Document the CsvEncoder and the YamlEncoderDocument the CsvEncoder and the YamlEncoder introduced insymfony/symfony#19197 andsymfony/symfony#19326.Commits-------6944ea1 [Serializer] Document the CsvEncoder and the YamlEncoder
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@derrabusderrabusderrabus left review comments

@xabbuhxabbuhxabbuh left review comments

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

9 participants

@dunglas@fabpot@stof@jderusse@derrabus@xabbuh@GuilhemN@bhavin-nakrani@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp