$ laravel new blog
如果沒有裝 laravel installer 或者是其他的自己處理,今天 focus 在 IDE 設定上
第一次打開的時候 PHPStorm 會做 indexing, 需要等待一下。
預設會是 PHP5.6,但我們要用 PHP7,要跟 PHPStorm 說
Preferences/Languages&Frameworks/PHP, 也可以順便設定 CLI
http://php.net/manual/en/migration70.new-features.php#migration70.new-features.return-type-declarations
http://www.phpstorm-themes.com/
http://daylerees.github.io/
裝 color IDE plugin
很多方法如果有需要再去改就好了。
這很重要!
http://www.php-fig.org/psr/
http://www.php-fig.org/psr/psr-2/
原本程式是這個樣子
<?php
class Car {
public function run() {
if(0 > 1)
{
return true;
}
}
}
Alt + Command + L
class Car
{
public function run()
{
if (0 > 1) {
return true;
}
}
}
安全、快速的把格式調好,看起來就是賞心悅目,重點就是每個人寫出來的代碼就格式上來說長的都一樣,對於 debug 或 tracing 都有一定作用
pubf
tab
public function ()
{
}
切換下個 pramater: tab
沒關係我們自己來
tab
public function __construct()
{
}
減少人工失誤
(就是重構)
Result
if ($this->user->owns()) {
$owner = $this->user->allow();
}
else {
$owner = $this->user->NotAllow();
}
protected function policy()
{
if ($this->user->owns()) {
$owner = $this->user->allow();
}
else {
$owner = $this->user->NotAllow();
}
}
public function index()
{
$product = $this->user->products()->get();
$storage = $this->storage->save($product);
$user_policy = $this->policy();
return $storage;
}
protected function policy(): void
{
$author = $this->auth();
return $author->owns() ? $author->allow() : $author->NotAllow();
}
https://laravel.com/docs/5.4/providers
如果單純下
$ composer update
他會是 require + require-dev
的包全會安裝。
//裝 dev 的包或更新
$ composer install --dev
$ composer update --dev
//不裝
$ composer install --no-dev
$ composer update --no-dev
$ composer require barryvdh/laravel-debugbar --dev
$ php artisan make:provider LocalServiceProvider
protected $providers = [
\Barryvdh\Debugbar\ServiceProvider::class,
];
protected $aliases = [
'Debugbar' => \Barryvdh\Debugbar\Facade::class,
];
public function register()
{
if ($this->app->isLocal() && ! empty($this->providers)) {
foreach ($this->providers as $provider) {
$this->app->register($provider);
}
if ( ! empty($this->aliases)) {
foreach ($this->aliases as $alias => $facade) {
$this->app->alias($alias, $facade);
}
}
}
}
register LocalServiceProvider
/*
* Development Service Provider
*/
\App\Providers\LocalServiceProvider::class,
$ composer require --dev barryvdh/laravel-ide-helper
protected $providers = [
\Barryvdh\Debugbar\ServiceProvider::class,
\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
];
$ php artisan ide-helper:generate
https://github.com/Mombuyish/yish.im-posts-source/blob/master/Laravel-plugin-on-phpstorm.md
原本這東西 4.2 之前是內建的,但後來 Taylor 覺得這東西是需要再掛載,所以就獨立了
https://github.com/GrahamCampbell/Laravel-Exceptions
$ composer require graham-campbell/exceptions
use Exception;
use GrahamCampbell\Exceptions\NewExceptionHandler;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends NewExceptionHandler
{
....
$ composer require filp/whoops --dev