2017-07-26 26 views
1

enter image description herePhpStorm - 上Laravel某些警告門面

  1. 我做Laravel的外牆使用權和PhpStorm給我的警告,這是爲什麼?

  2. 而在圖像上,我指出「x」表示某些...類型的數據?在我使用的函數中,爲什麼有這些?如何刪除它們?

+0

[這是phpstorm 2017.1的一個特性](https://blog.jetbrains.com/phpstorm/2017/03/new-in-phpstorm-2017-1-parameter-hints/)。博客鏈接還提供有關如何刪除它的說明:*「或者,您可以通過導航到編輯器|常規|外觀並取消選擇顯示參數名稱提示來完全關閉提示。」* – h2ooooooo

+0

那麼外牆警告怎麼辦? @ h2ooooooo –

+1

您不使用外牆。您已經導入了類,在第一個類中,IDE告訴您get方法不是靜態方法。 –

回答

6

使用外牆與Laravel

Luke Waite is right

您沒有使用外牆。您已經導入了類,並且首先在類別上,IDE告訴您get方法不是 靜態方法。

只需導入外觀(如果存在)。

有關如何使用available facadeshow to define your own的詳細信息,請參閱documentation on Facades

的立面類應該是這樣的:

use Illuminate\Support\Facades\Facade; 

class Cache extends Facade 
{ 
    /** 
    * Get the registered name of the component. 
    * 
    * @return string 
    */ 
    protected static function getFacadeAccessor() 
    { 
     return 'cache'; 
    } 
} 

'cache'字符串是service container綁定的名稱,並在service provider定義是這樣的:

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(); 
     }); 
    } 
} 

用外牆固定警告

這就是說,我厭倦了警告和失蹤的自動完成和突出與外牆,所以我還尋找一種方法來解決這些問題。

我遇到了laravel-ide-helper,它添加了Laravel CLI命令,用於生成僅供IDE解析的php文件。

安裝

需要使用下面的命令這個包與作曲家:

composer require barryvdh/laravel-ide-helper 

更新作曲家後,服務提供者添加到提供商 陣列中config/app.php

Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,爲了 僅在開發系統上安裝此軟件包,請添加--dev f滯後 您作曲家命令:

composer require --dev barryvdh/laravel-ide-helper 

在Laravel,而不是在 config/app.php文件中添加服務提供商,可以將下面的代碼添加到您的 app/Providers/AppServiceProvider.php文件時,register() 方法中:

public function register() 
{ 
    if ($this->app->environment() !== 'production') { 
     $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class); 
    } 
    // ... 
} 

這將允許您的應用程序通過 非生產環境加載Laravel IDE Helper。

自動PHPDoc的一代對於Laravel外立面

現在,您可以重新生成自己的文檔(爲未來的更新)

php artisan ide-helper:generate 

注:bootstrap/compiled.php首先必須清除,所以之前運行php artisan clear-compiled生成(和php artisan optimize之後)。

您可以配置composer.json以後每次提交做到這一點:

"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因爲你不想犯這些。

+0

不錯。非常感謝你。請你能解釋我爲什麼不使用門面?我一直聽到這種說法:使用外牆; :< –

+0

@KrystianPolska我更新了答案,以在門面上添加更多信息。 –