vendor/api-platform/core/src/Operation/DashPathSegmentNameGenerator.php line 27

  1. <?php
  2. /*
  3.  * This file is part of the API Platform project.
  4.  *
  5.  * (c) Kévin Dunglas <dunglas@gmail.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace ApiPlatform\Operation;
  12. use ApiPlatform\Util\Inflector;
  13. /**
  14.  * Generate a path name with a dash separator according to a string and whether it's a collection or not.
  15.  *
  16.  * @deprecated replaced by ApiPlatform\Metadata\Operation\DashPathSegmentNameGenerator
  17.  *
  18.  * @author Antoine Bluchet <soyuka@gmail.com>
  19.  */
  20. final class DashPathSegmentNameGenerator implements PathSegmentNameGeneratorInterface
  21. {
  22.     public function __construct()
  23.     {
  24.         trigger_deprecation('api-platform''3.1'sprintf('%s is deprecated in favor of %s. This class will be removed in 4.0.'self::class, \ApiPlatform\Metadata\Operation\DashPathSegmentNameGenerator::class));
  25.     }
  26.     /**
  27.      * {@inheritdoc}
  28.      */
  29.     public function getSegmentName(string $namebool $collection true): string
  30.     {
  31.         return $collection $this->dashize(Inflector::pluralize($name)) : $this->dashize($name);
  32.     }
  33.     private function dashize(string $string): string
  34.     {
  35.         return strtolower(preg_replace('~(?<=\\w)([A-Z])~''-$1'$string));
  36.     }
  37. }