vendor/symfony/webpack-encore-bundle/src/Dto/StimulusTargetsDto.php line 25

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the Symfony WebpackEncoreBundle package.
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  * For the full copyright and license information, please view the LICENSE
  7.  * file that was distributed with this source code.
  8.  */
  9. namespace Symfony\WebpackEncoreBundle\Dto;
  10. /**
  11.  * @deprecated since 1.17.0 - install symfony/stimulus-bundle instead.
  12.  */
  13. final class StimulusTargetsDto extends AbstractStimulusDto
  14. {
  15.     private $targets = [];
  16.     /**
  17.      * @param string      $controllerName the Stimulus controller name
  18.      * @param string|null $targetNames    The space-separated list of target names if a string is passed to the 1st argument. Optional.
  19.      */
  20.     public function addTarget(string $controllerNamestring $targetNames null): void
  21.     {
  22.         $controllerName $this->getFormattedControllerName($controllerName);
  23.         $this->targets['data-'.$controllerName.'-target'] = $targetNames;
  24.     }
  25.     public function __toString(): string
  26.     {
  27.         if (=== \count($this->targets)) {
  28.             return '';
  29.         }
  30.         return implode(' 'array_map(function (string $attributestring $value): string {
  31.             return $attribute.'="'.$this->escapeAsHtmlAttr($value).'"';
  32.         }, array_keys($this->targets), $this->targets));
  33.     }
  34.     public function toArray(): array
  35.     {
  36.         return $this->targets;
  37.     }
  38. }