LoginSignup
5
5

More than 5 years have passed since last update.

開発作業時にコマンドラインから利用すると便利なPHPライブラリ

Last updated at Posted at 2015-11-19

開発作業時にコマンドラインから利用すると便利なPHPライブラリ

僕は主にvimでコーディングしています。
ただし、vimのプラグインはかけないため、効率を上げるためにもっぱらvimのバッファと外部ツールを 標準出力/標準入力 で接続するという方法をとっています。

標準出力/標準入力 経由で操作すると非常に便利なツールのうち、以下のコマンドで簡単にセットアップできるものをピックアップしてみました。

composer global require 'xxx/yyy'

php-cs-fixer

便利度

役割

phpのソースコードを整形してくれる。

composer global require "fabpot/php-cs-fixer"

sql-formatter

便利度

役割

エンジニアなら SQL を1日に一回以上は記述していると思う。
特に急いでいるときは SQL をささっとワンライナーで入力したりするが、
作業履歴として整理する際には整形されていないと見にくい。

以下のツールを利用すれば、SQLが一発で整形できる。

composer global require "jdorn/sql-formatter"

以下のようなスクリプトを用意しておき、標準入力から食わせてやる。

sqlformatter.php

#!/usr/bin/env php
<?php
require getenv('HOME') . '/.composer/vendor/autoload.php';

$query = file_get_contents('php://stdin');
echo SqlFormatter::format($query, false);

利用

$ echo "select * from test where x = 3;"| sqlformatter.php

select
  *
from
  test
where
  x = 3;
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5