Kry*_*ska 1 php phpstorm laravel phpstorm-2017.1
我正确使用了Laravel的外墙,PhpStorm给了我警告,为什么呢?
在图像上,我指出"x"表示某些......数据类型?在我使用的功能中,我为什么要这些?如何删除它们?
Emi*_*ron 12
你没有使用外墙.您已导入类,并在第一个类别上,IDE告诉您get方法不是静态方法.
只需导入外观(如果存在).
请参阅有关Facades的文档,以了解有关如何使用可用外墙以及如何定义自己的外墙的更多信息.
Facade类应如下所示:
use Illuminate\Support\Facades\Facade;
class Cache extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'cache';
}
}
Run Code Online (Sandbox Code Playgroud)
其中'cache'字符串是服务容器绑定的名称并在服务提供者中定义,如下所示:
use App\Cache\MyCache;
use Illuminate\Support\ServiceProvider;
class CacheServiceProvider extends ServiceProvider
{
/**
* Register bindings in the container.
*
* @return void
*/
public function register()
{
$this->app->singleton('cache', function ($app) {
return new MyCache();
});
}
}
Run Code Online (Sandbox Code Playgroud)
话虽这么说,我已经厌倦了警告和失踪的自动完成并突出了立面,所以我也搜索找到解决这些问题的方法.
我找到了laravel-ide-helper,它添加了Laravel CLI命令,生成只能由IDE解析的php文件.
安装
使用以下命令将此包与composer一起使用:
Run Code Online (Sandbox Code Playgroud)composer require barryvdh/laravel-ide-helper更新composer后,将服务提供者添加到providers数组中
config/app.php
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,要仅在开发系统上安装此程序包,请将--dev标志添加到composer命令:Run Code Online (Sandbox Code Playgroud)composer require --dev barryvdh/laravel-ide-helper在Laravel,而不是在添加服务提供商
config/app.php的文件,你可以将下面的代码添加到您的app/Providers/AppServiceProvider.php文件时,中register()方法:Run Code Online (Sandbox Code Playgroud)public function register() { if ($this->app->environment() !== 'production') { $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class); } // ... }这将允许您的应用程序在非生产环境中加载Laravel IDE Helper.
Laravel Facades自动生成phpDoc
您现在可以自己重新生成文档(以便将来更新)
Run Code Online (Sandbox Code Playgroud)php artisan ide-helper:generate注意:
bootstrap/compiled.php必须先清除,因此php artisan clear-compiled在生成之前运行(及php artisan optimize之后).您可以配置
composer.json在每次提交后执行此操作:Run Code Online (Sandbox Code Playgroud)"scripts":{ "post-update-cmd": [ "Illuminate\\Foundation\\ComposerScripts::postUpdate", "php artisan ide-helper:generate", "php artisan ide-helper:meta", "php artisan optimize" ] },
在.phpstorm.meta.php和_ide_helper.php文件将被产生,并应添加到您的.gitignore,你不想犯这些.
| 归档时间: |
|
| 查看次数: |
2634 次 |
| 最近记录: |