PHPを始めようと思い、環境作りを色々調べてみたので備忘録
なんで今更PHP?
うちのサービスでサポートしてる言語の中で、僕が一番触ったことない言語がPHPだなーとはなんとなく思っていた。
そんな中、最近色々調べ物とかしてるとPHPの話に触れている記事を目にすることがちょくちょくあり、その中でPHPの特徴として「作るまでが早いけどコードが汚い」みたいなのがあった。なんとなく自分の性格と相性がいいのでは?と思い改めて触ってみることに。
入れたもの
とはいえ大したことはしてない。
composerとvimの設定のみ
composerについて
Rubyでいうgem、Nodeでいうnpm
依存ファイルをjsonで書くからそのどちらかならnpmっぽいかな
それよりcomposerのいいとこは、composerで入れたパッケージはコード内で
require 'vendor/autoload.php';
と書いとけば使うときに勝手に読み込んでくれるってところ
requireしてなくてどうこうみたいなことにならないのはちょっぴり嬉しいね
この辺を参考にインストールした
$ curl -sS https://getcomposer.org/installer | php [/Users/keisuke] #!/usr/bin/env php All settings correct for using Composer Downloading... Composer successfully installed to: /Users/keisuke/composer.phar Use it: php composer.phar $ sudo mv composer.phar /usr/local/bin/composer
homebrewも使えるみたいだけど普通にglobalインストールしちゃいました
試しにcomposerと打ってみる
$ composer [/Users/keisuke] ______ / ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/ Composer version a045ab345980bfe4a1daec1a34d345f13a2810dc 2013-11-06 22:13:14 Usage: [options] command [arguments] Options: --help -h Display this help message. --quiet -q Do not output any message. --verbose -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug --version -V Display this application version. --ansi Force ANSI output. --no-ansi Disable ANSI output. --no-interaction -n Do not ask any interactive question. --profile Display timing and memory usage information --working-dir -d If specified, use the given directory as working directory. Available commands: about Short information about Composer archive Create an archive of this composer package config Set config options create-project Create new project from a package into given directory. depends Shows which packages depend on the given package diagnose Diagnoses the system to identify common errors. dump-autoload Dumps the autoloader dumpautoload Dumps the autoloader global Allows running commands in the global composer dir ($COMPOSER_HOME). help Displays help for a command init Creates a basic composer.json file in current directory. install Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json. licenses Show information about licenses of dependencies list Lists commands require Adds required packages to your composer.json and installs them run-script Run the scripts defined in composer.json. search Search for packages self-update Updates composer.phar to the latest version. selfupdate Updates composer.phar to the latest version. show Show information about packages status Show a list of locally modified packages update Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file. validate Validates a composer.json [keisuke@localhost]$ composer about [/Users/keisuke] Composer - Package Management for PHP Composer is a dependency manager tracking local dependencies of your projects and libraries. See http://getcomposer.org/ for more information.
ちゃんと動いてるね
vimの設定
ざっと調べてみたけど他の言語と違ってgithubにライブラリとか置いてる空気じゃなくて手動で辞書をどっかからもってきて、自動補完できるようにするといいよって感じっぽい
僕は手動で辞書を作る方法を選んだ。phpのコマンドで作るっぽい
$ php -r '$f=get_defined_functions();echo join("\n",$f["internal"]);'|sort > ~/.vim/dict/php.dict
これ最初にやった時~/.vim/dictがないって怒られたから、mkdirで.vim/dict作った
.vimrcに下記追加
autocmd FileType php,ctp :set dictionary=~/.vim/dict/php.dict
これでneocoplcacheとかが動いてれば自動で補完される
この後
とりあえずフレームワークが色々あるっぽいのでひと通り触ってみて良さげなのを見つけたいってのと、PHPテストフレームワークを覚えなきゃね
ぱっと見た感じ比較的新しいフレームワークであるfuelPHPがきになる。テストはPHPUnitが一番ドキュメント充実してそうだからそこからかな。spec系使いたかったけど残念