Skip to content

[DependencyInjection][Yaml] Add support for flags parsing with binary_flags type and tag #57522

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

Conversation

alexandre-daubois
Copy link
Member

Q A
Branch? 7.2
Bug fix? no
New feature? yes
Deprecations? no
Issues -
License MIT

After symfony/symfony-docs#19965. This PR would allow to write such code (removed NS for readability of the example):

App\Entity\Report:
    properties:
        customConfiguration:
            - Yaml:
                  message: Your configuration doesn't have valid YAML syntax.
                  flags: !!binary_flags YamlParser::PARSE_CONSTANT | YamlParser::PARSE_CUSTOM_TAGS | Yaml::PARSE_DATETIME

Same goes for XML, where a new binary_flags type is added.

When parsing, binary_flags assumes you give only constants as parameters, the goal is not to rewrite a complete bitwise ops parser.

@alexandre-daubois alexandre-daubois force-pushed the binary-flags branch 2 times, most recently from bddbede to 60354a2 Compare June 25, 2024 18:57
@nicolas-grekas
Copy link
Member

nicolas-grekas commented Aug 21, 2024

Binary expressions can also also have brackets or ~ and &...
Did you try using an expression instead? @= the-expr

@alexandre-daubois
Copy link
Member Author

Indeed, this is the way instead of reinventing a whole bitfield parser. Worth the extra dependency to me.

nicolas-grekas added a commit that referenced this pull request Aug 22, 2024
…~` bitwise operators (alexandre-daubois)

This PR was merged into the 7.2 branch.

Discussion
----------

[ExpressionLanguage] Add support for `<<`, `>>`, and `~` bitwise operators

| Q             | A
| ------------- | ---
| Branch?       | 7.2
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Issues        | -
| License       | MIT

In order to fully support [this idea](#57522 (comment)), I suggest adding to ExpressionLanguage the 3 currently missing bitwise operators, namely left shift, right shift and binary not.

```php
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;

require 'vendor/autoload.php';

$el = new ExpressionLanguage();

$el->evaluate('1 << 4'); // 16
$el->evaluate('32 >> 4'); // 2
$el->evaluate('~5'); // -6
```

Commits
-------

b470422 [ExpressionLanguage] Add support for `<<`, `>>`, and `~` bitwise operators
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.

4 participants