8000 [Serializer] Allow to specify a single value in @Groups by dunglas · Pull Request #20509 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@dunglas
8000
Copy link
Member
@dunglas dunglas commented Nov 13, 2016
Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #19374 (comment)
License MIT
Doc PR symfony/symfony-docs#10314

Tiny DX improvement:

Before:

use Symfony\Component\Serializer\Annotation\Groups;

class Product
{
    /**
     * @Groups({"admins"})
     */
    public $itemsSold;
}

Now allowed:

use Symfony\Component\Serializer\Annotation\Groups;

class Product
{
    /**
     * @Groups("admins")
     */
    public $itemsSold;
}

@dunglas dunglas added DX DX = Developer eXperience (anything that improves the experience of using Symfony) Serializer labels Nov 13, 2016
@dunglas
Copy link
Member Author
dunglas commented Nov 13, 2016

Travis error not related.

$value = (array) $data['value'];
foreach ($value as $group) {
if (!is_string($group)) {
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be an array of strings.', get_class($this)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this message be adapted accordingly?

@ogizanagi
Copy link
Contributor

👍

Status: Reviewed

@xabbuh
Copy link
Member
xabbuh commented Nov 17, 2016

👍

@xabbuh xabbuh added this to the 3.3 milestone Nov 17, 2016
@fabpot
Copy link
Member
fabpot commented Dec 2, 2016

Thank you @dunglas.

@fabpot fabpot closed this Dec 2, 2016
fabpot added a commit that referenced this pull request Dec 2, 2016
…(dunglas)

This PR was squashed before being merged into the 3.3-dev branch (closes #20509).

Discussion
----------

[Serializer] Allow to specify a single value in @groups

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #19374 (comment)
| License       | MIT
| Doc PR        | todo

Tiny DX improvement:

Before:

```php
use Symfony\Component\Serializer\Annotation\Groups;

class Product
{
    /**
     * @groups({"admins"})
     */
    public $itemsSold;
}
```

Now allowed:

```php
use Symfony\Component\Serializer\Annotation\Groups;

class Product
{
    /**
     * @groups("admins")
     */
    public $itemsSold;
}
```

Commits
-------

926aa48 [Serializer] Allow to specify a single value in @groups
@nicolas-grekas nicolas-grekas modified the milestones: 3.x, 3.3 Mar 24, 2017
@fabpot fabpot mentioned this pull request May 1, 2017
@dunglas dunglas deleted the single_group branch June 5, 2018 09:45
nicolas-grekas added a commit that referenced this pull request Jul 1, 2018
…ps opt (dunglas)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[Serializer] Allow to pass a single value for the groups opt

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets |  n/a
| License       | MIT
| Doc PR        | todo

Shortcut syntax similar to #20509 but for the context: allows to pass a string instead of an array of string in the serialization context when only one group if used.

Before:

```php
$serializer->serialize($foo, 'json', ['groups' => ['myGroup']];

/** @ApiResource(normalizationContext={"groups"={"myGroup"}}) */
```

After:

```php
$serializer->serialize($foo, 'json', ['groups' => 'myGroup'];

/** @ApiResource(normalizationContext={"groups"="myGroup") */
```

Commits
-------

5b39203 [Serializer] Allow to pass a single value for the groups opt
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Sep 10, 2018
…(dunglas)

This PR was merged into the 3.4 branch.

Discussion
----------

[Serializer] Allow to specify a single value in @groups

symfony/symfony#20509

Commits
-------

99df65f [Serializer] Allow to specify a single value in @groups
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature Serializer Status: Reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

0