
| Current Path : /var/www/html/rocksensor/vendor/chi-teck/drupal-code-generator/src/Command/PhpStormMeta/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/rocksensor/vendor/chi-teck/drupal-code-generator/src/Command/PhpStormMeta/Routes.php |
<?php
declare(strict_types=1);
namespace DrupalCodeGenerator\Command\PhpStormMeta;
use DrupalCodeGenerator\Asset\File;
use DrupalCodeGenerator\Helper\Drupal\RouteInfo;
/**
* Generates PhpStorm meta-data for routes.
*/
final class Routes {
/**
* Constructs the object.
*/
public function __construct(
private readonly RouteInfo $routeInfo,
) {}
/**
* Generator callback.
*/
public function __invoke(): File {
$routes = $this->routeInfo->getRouteNames();
$route_attributes = $this->getRouteAttributes();
return File::create('.phpstorm.meta.php/routes.php')
->template('routes.php.twig')
->vars(['routes' => $routes, 'route_attributes' => $route_attributes]);
}
/**
* Builds attributes suitable for Route autocompletion.
*/
private function getRouteAttributes(): array {
/** @psalm-var array{options: array, requirements: array, defaults: array} $route_attributes */
$route_attributes = [
'options' => [],
'requirements' => [],
'defaults' => [],
];
foreach ($this->routeInfo->getRoutes() as $route) {
$route_attributes['options'] += $route->getOptions();
$route_attributes['requirements'] += $route->getRequirements();
$route_attributes['defaults'] += $route->getDefaults();
}
$is_internal = static fn (string $option_name): bool => \str_starts_with($option_name, '_');
foreach ($route_attributes as $name => $attributes) {
$route_attributes[$name] = \array_filter(\array_keys($route_attributes[$name]), $is_internal);
\sort($route_attributes[$name]);
}
return $route_attributes;
}
}