PhpStorm 是一款很只能的PHP編輯器,絕大部分的class 都能智能的提示對應類型。但是有一些使用 __call() 來實現的映射功能 無法自動獲取。 譬如 laravel或自定義的一些特殊映射功能。 PhpStorm 的 .phpstorm.meta.php 這時候就派上了用場。
直接在項目的根目錄創建一個文檔.phpstorm.meta.php內容格式如下:
<?php
namespace PHPSTORM_META {
//metadata directives
}override() 定義函數返回類型,例如:
override(\app(), map([
"" => "@",
"tree" => \App\Services\TreeService::class,
"common" => \App\Services\CommonService::class,
]));上面列子中 app('tree') 自動會匹配 \App\Services\TreeService
expectedArguments() 定義函數接受的參數,例如:
expectedArguments(
\fun1(),
0,
'tree',
'common'
);上列中 在編輯器中輸入 fun1() 自動彈出提示參數 tree common
更詳細的參考文檔: https://www.jetbrains.com/help/phpstorm/ide-advanced-metadata.html