Skip to content

[Yaml] Inconsistent tag parsing #22198

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

Closed
ro0NL opened this issue Mar 28, 2017 · 3 comments
Closed

[Yaml] Inconsistent tag parsing #22198

ro0NL opened this issue Mar 28, 2017 · 3 comments
Labels

Comments

@ro0NL
Copy link
Contributor

ro0NL commented Mar 28, 2017

Q A
Bug report? yes
Feature request? no
BC Break report? no
Symfony version 3.x

Seems like the YAML parser doesnt recognize tagged scalar nodes really well;

a: !foo bar
b: !foo 'bar'
c: !foo
    bar
d: !foo [1, 2, 3]
array:4 [▼
  "a" => "!foo bar"
  "b" => "!foo 'bar'"
  "c" => TaggedValue {#254 ▶}
  "d" => TaggedValue {#221 ▶}
]

Considering DI; both !iterator foo and !iterator [foo] produce a valid container, but a different value.

@GuilhemN
Copy link
Contributor

That's for bc, tagged scalars will be supported only in 4.0.
Though we can allow a tag for scalars on a per basis.

@ro0NL
Copy link
Contributor Author

ro0NL commented Mar 28, 2017

Your're right... actually missed the deprecation. Point is https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php#L662 is not thrown for the deprecated notation.

Guess little we can do here.

@ro0NL ro0NL closed this as completed Mar 28, 2017
@GuilhemN
Copy link
Contributor

Point is https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php#L662 is not thrown for the deprecated notation.

Yes it's currently useless, it's here to be sure we won't forget it in 4.0.

@xabbuh xabbuh added the Yaml label Mar 29, 2017
nicolas-grekas added a commit that referenced this issue Sep 28, 2017
This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Reference tagged services in config

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #12269
| License       | MIT
| Doc PR        | symfony/symfony-docs#8404

This is a proof of concept to reference a sequence of tagged services.

The problem bugs me for some time, and at first i thought the solution was to have some super generic compiler pass. If it could replace a lot of compilers in core.. perhaps worth it, but eventually each tag comes with it's own logic, including how to deal with tag attributes.

However, writing the passes over and over again becomes tedious for the most basic usecase. So given the recent developments, this idea came to mind.

```yml
services:
    a:
        class: stdClass
        properties: { a: true }
        tags: [foo]

    b:
        class: stdClass
        properties: { b: true }
        tags: [foo]

    c:
        class: stdClass
        properties:
            #stds: !tagged_services foo (see #22198)
            stds: !tagged_services
                foo
```

```
dump(iterator_to_array($this->get('c')->stds));
```

```
array:2 [▼
  0 => {#5052 ▼
    +"a": true
  }
  1 => {#4667 ▼
    +"b": true
  }
]
```

Given the _basic_ example at https://symfony.com/doc/current/service_container/tags.html, this could replace that.

Any thoughts?

Commits
-------

979e58f [DI] Reference tagged services in config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants