За последние 24 часа нас посетили 22556 программистов и 1014 роботов. Сейчас ищут 711 программистов ...

Как в PhpStorm сделать автозаполнение ключей пользовательского массива

Тема в разделе "Прочие вопросы по PHP", создана пользователем Вероломство, 21 ноя 2021.

  1. Вероломство

    Вероломство Активный пользователь

    С нами с:
    19 июн 2017
    Сообщения:
    615
    Симпатии:
    24
    PHP:
    1. class Router
    2. {
    3.     private array $routes = [];
    4.  
    5.     public function addRoute(string $pattern, string|array $handler, array $methods = []): void
    6.     {
    7.         $this->routes[] = [
    8.             'pattern' => $pattern,
    9.             'handler' => $handler,
    10.             'methods' => $methods
    11.         ];
    12.     }
    13.  
    14.     #[ArrayShape(['handler' => "mixed", 'attribs' => "array"])] public function match(Request $request): array
    15.    {
    16.         foreach ($this->routes as $route) {
    17.  
    18.             if ($route['methods'] && !in_array($request->getMethod(), $route['methods'], true)) {
    19.                 continue;
    20.             }
    21.  
    22.             $pattern = preg_replace('#{([a-z]+)}#', '(?P<$1>[a-z]+)', $route['pattern']);
    23.             $pattern = preg_replace('#{([a-z]+):([^}]+)}#', '(?P<$1>$2)', $pattern);
    24.  
    25.             if (preg_match("#^$pattern$#", $request->getPath(), $matches)) {
    26.                 return [
    27.                     'handler' => $route['handler'],
    28.                     'attribs' => array_filter($matches, 'is_string', ARRAY_FILTER_USE_KEY)
    29.                 ];
    30.             }
    31.         }
    32.  
    33.         throw new Error("Не найден маршрут пути: {$request->getPath()}");
    34.     }
    35. }
    Для метода match шторм сам предложил добавить атрибут ArrayShape и в полученном из него результате работает автозаполнение ключей массива.

    А как мне сделать такое же для метода addRoute или для свойства route?