Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x

Groups.php

Same filename in this branch
  1. 11.1.x vendor/phpunit/phpunit/src/TextUI/Configuration/Xml/Groups.php
  2. 11.1.x vendor/phpunit/phpunit/src/Metadata/Api/Groups.php
  3. 11.1.x vendor/symfony/serializer/Annotation/Groups.php

Namespace

Symfony\Component\Serializer\Attribute

File

vendor/symfony/serializer/Attribute/Groups.php

View source
<?php


/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Symfony\Component\Serializer\Attribute;

use Symfony\Component\Serializer\Exception\InvalidArgumentException;

/**
 * @author Kévin Dunglas <dunglas@gmail.com>
 */
class Groups {
    
    /**
     * @var string[]
     */
    private readonly array $groups;
    
    /**
     * @param string|string[] $groups The groups to define on the attribute target
     */
    public function __construct(string|array $groups) {
        $this->groups = (array) $groups;
        if (!$this->groups) {
            throw new InvalidArgumentException(\sprintf('Parameter given to "%s" cannot be empty.', static::class));
        }
        foreach ($this->groups as $group) {
            if (!\is_string($group) || '' === $group) {
                throw new InvalidArgumentException(\sprintf('Parameter given to "%s" must be a string or an array of non-empty strings.', static::class));
            }
        }
    }
    
    /**
     * @return string[]
     */
    public function getGroups() : array {
        return $this->groups;
    }

}
if (!class_exists(\Symfony\Component\Serializer\Annotation\Groups::class, false)) {
    class_alias(Groups::class, \Symfony\Component\Serializer\Annotation\Groups::class);
}

Classes

Title Deprecated Summary
Groups @author Kévin Dunglas <dunglas@gmail.com>
RSS feed
Powered by Drupal