しわっす!@riaf です!
タイトルどおりなんですが、最近どうやら Google Feed API が Deprecated になり、ちょっとしたところに活用してた人たちが悲鳴をあげてるのを目にしたので、リリースされたばかりの Symfony 3.0 のテストも兼ねて、似たようなサービスを作ってみようと思いました。
ついでに、開発中だった otobank/facebook-bundle も一緒に使ってしまおう。と、無意味に Facebook ログインが必須になっとりますが、ユーザー情報の保存とか、面倒で実装してないので、コネクトしたと言っても特に悪さしたりしませんので、安心してください(それでいいのか)
作ったのはこちらです。 https://feedjson.otolabo.jp
サービスの使い方とかに関してはもうちょっとちゃんと作った後にでも紹介しますね。
Symfony 3.0 を使ってみる
Symfony 3.0 のプロジェクト作成には Symfony Installer (1.4.4) を使いました。
app/console が bin/console になってたり、キャッシュとかログとかが var/ ディレクトリに入ってたり、慣れてると引っかかる罠がいくつか潜んでいます。詳しくは CHANGELOG を確認してくださいね!
symfony new feedjson
...
Preparing project...
✔ Symfony 3.0.0 was successfully installed. Now you can:
* Change your current directory to /path/to/feedjson
* Configure your application in app/config/parameters.yml file.
* Run your application:
1. Execute the php bin/console server:run command.
2. Browse to the http://localhost:8000 URL.
* Read the documentation at http://symfony.com/doc
もともと Symfony 2.7 を使っていたので、それほど違いを感じることなく、アプリを作りきってしまいました。まあ、大したことやってませんしね。
で、今度はこれをウェブサーバーにセットアップするわけですが、とりあえずデプロイの仕組みを考える前に git clone ... して試してみることにしました。
通常、Symfony アプリであれば、clone した後に composer で依存パッケージを取得して、parameters.yml を設定すればまあ、とりあえず bin/console server:run までは動くでしょう。ということで、やってみます。
git clone ...; cd ... composer install ... > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache Could not open input file: app/console Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-install-cmd event terminated with an exception [RuntimeException] An error occurred when executing the "'cache:clear --no-warmup'" command: Could not open input file: app/console
ん?なぜか app/console を探しに行ってしまうようですね。Symfony Installer を使ってセットアップした環境では composer の script が止まることはなかったので、何か違いがあるんでしょう...。
せっかくなのでコードを読んでみました。clearCache で止まっているので、該当箇所 を確認すると、
<?php (...) if (static::useNewDirectoryStructure($options)) { if (!static::hasDirectory($event, 'symfony-bin-dir', $options['symfony-bin-dir'], $actionName)) { return; } return $options['symfony-bin-dir']; } if (!static::hasDirectory($event, 'symfony-app-dir', $options['symfony-app-dir'], 'execute command')) { return; } return $options['symfony-app-dir'];
useNewDirectoryStructure で判定しているようです。このメソッドは
<?php (...) protected static function useNewDirectoryStructure(array $options) { return isset($options['symfony-var-dir']) && is_dir($options['symfony-var-dir']); }
これだけのようです。ということで、symfony-var-dir を確認してみます。composer.json では
"extra": {
"symfony-app-dir": "app",
"symfony-bin-dir": "bin",
"symfony-var-dir": "var",
"symfony-web-dir": "web",
"symfony-tests-dir": "tests",
このようになっているので、options 自体は存在していそうです。しかし、clone したディレクトリを確認してみると var/ ディレクトリが存在してませんでした。
おやおや、アプリ作成のタイミングでは、Symfony Installer が置いてくれた .gitignore をそのまま使ったはずだけどな...。.gitignore を見てみます。
/app/config/parameters.yml /bin/ /build/ /composer.phar /vendor/ /web/bundles/ /var/ !var/cache/.gitkeep !var/logs/.gitkeep !var/sessions/.gitkeep /phpunit.xml
どうやら .gitkeep を置いて、Ignore から除外しようとしているようですが、試しに git add してみると
git add var/logs/.gitkeep The following paths are ignored by one of your .gitignore files: var/logs/.gitkeep Use -f if you really want to add them.
うん、そうですよね。
っていうかちゃんと見ると bin/ ディレクトリも除外しちゃってるじゃないか...!
と、ここまで書いておいてあれですが、既に Pull Request (Fix .gitignore for var dir #863) がマージされております。が、Symfony Installer を使うと Symfony Installer 内の createGitIgnore メソッド で作っていて、こっち側に反映されていないっていうことのようです。
この問題については既に Issue (.gitignore sync #211) が登録されているので、把握はされているようですね。
というわけで、Symfony 3.0 を使ったアプリ開発を Symfony Installer を使って始めたい場合は、symfony new した後に symfony-standard から .gitignore を持ってくると幸せになれそうです。