[英]How to tell PhpStorm that function argument is file path
In PhpStorm (and other JetBrains IDE), is it possible to make function attributes as file / resource path?在 PhpStorm(和其他 JetBrains IDE)中,是否可以将 function 属性作为文件/资源路径?
Eg in this function:例如在这个 function 中:
function mix($file): string
{
// check mix maninfest for $file and return path from mix manifest
return $fire_path_with_cachebuster;
}
I'd like PHP to suggest files in the project as I define $file
attribute when calling mix function.我希望 PHP 在项目中建议文件,因为我在调用 mix function 时定义$file
属性。
Only manually for the moment, when calling that function.暂时只能手动调用 function。 And it's a temp injection (for a session) so it's not convenient:这是一个临时注入(用于会话),所以不方便:
mix('')
Hopefully they will implement the following tickets for a permanent solution:希望他们将实施以下票证以获得永久解决方案:
#[Language]
PHP attribute at the function declaration : https://youtrack.jetbrains.com/issue/WI-56996在 function 声明中使用#[Language]
PHP 属性: https://youtrack.jetbrains.com/issue/WI-59Watch those tickets (star/vote/comment) to get notified on any progress (and hopefully speed it up by bringing dev's attention).观看这些票(星/投票/评论)以获得任何进展的通知(并希望通过引起开发人员的注意来加速它)。
Like LazyOne stated, there is currently no way to declare a parameter as being a file reference.正如LazyOne所说,目前无法将参数声明为文件引用。
However, you can get a more permanent File Reference "injection" by [mis]using __DIR__
.但是,您可以通过[错误]使用__DIR__
获得更永久的文件引用“注入”。
PhpStorm considers a string mixed with the __DIR__
constant to be a file path: PhpStorm 将与__DIR__
常量混合的字符串视为文件路径:
It isn't perfect as it depends on what directory you are currently located in. If you only want the filename passed to your method, you can wrap the string in basename
, or handle that from within your method.它并不完美,因为它取决于您当前所在的目录。如果您只想将文件名传递给您的方法,您可以将字符串包装在basename
中,或者从您的方法中处理它。
echo mix(basename(__DIR__ . '/slack_bot.php'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.