{
    "componentChunkName": "component---src-templates-blog-post-jsx",
    "path": "/post/write-interface-of-modern-template-engine-in-php/",
    "result": {"data":{"site":{"siteMetadata":{"title":"WEB EGG","author":"Leko - CTO at Yuimedi"}},"markdownRemark":{"id":"798d3393-6028-5a0e-867a-b125869c26cf","excerpt":"こんにちは。 突然ですが、FuelPHPのビューを書く場合、デフォルトでは生PHP + Viewクラスの構成だと思います。 Viewクラス自体がエスケープ機構を備えているのでXSSは塞げるんですが、生のPHPで書くとisset地獄だったりif…","html":"<p>こんにちは。<br>\n突然ですが、<a href=\"http://fuelphp.com/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">FuelPHP</a>のビューを書く場合、デフォルトでは生PHP + Viewクラスの構成だと思います。<br>\nViewクラス自体がエスケープ機構を備えているのでXSSは塞げるんですが、生のPHPで書くとisset地獄だったりifが増えたりと不便なところが多く、テンプレートエンジン使いたいと思うことが多々あります。</p>\n<p>そんなFuelPHPには<a href=\"https://github.com/fuel/parser\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">parser</a>というパッケージがあるので、設定を変更すればテンプレートエンジンが簡単に利用できます。</p>\n<blockquote>\n<p><a href=\"http://dolphin.hatenablog.jp/entry/2014/05/02/124522\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">fuelphpでhaml導入したった – ド忘れ防止雑記帳</a></p>\n</blockquote>\n<p><strong>が、しかし</strong> 対応しているテンプレートエンジンの一覧を見てみると、どれも古い。とにかく古い。<br>\n良く言えば枯れてるんですが、調べてみると <strong>メンテナンスされてないだろこれ…</strong> という感じのものが結構ありました。</p>\n<p>ということで自分の知見をアップデートするため昨今のテンプレートエンジンについて調べつつ、<br>\nparserパッケージのように複数テンプレートエンジンを同一のインタフェースで扱える仕組みを作ってみました。</p>\n<!--more-->\n<h2 id=\"採用基準\" style=\"position:relative;\"><a href=\"#%E6%8E%A1%E7%94%A8%E5%9F%BA%E6%BA%96\" aria-label=\"採用基準 permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>採用基準</h2>\n<ul>\n<li>開発が継続している</li>\n<li>ある程度Githubのstarが集まっている</li>\n<li>もしくは”大御所”と呼べるくらい広く使われて枯れている</li>\n</ul>\n<h2 id=\"採用したテンプレートエンジン\" style=\"position:relative;\"><a href=\"#%E6%8E%A1%E7%94%A8%E3%81%97%E3%81%9F%E3%83%86%E3%83%B3%E3%83%97%E3%83%AC%E3%83%BC%E3%83%88%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%B3\" aria-label=\"採用したテンプレートエンジン permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>採用したテンプレートエンジン</h2>\n<p>これらのテンプレートエンジンに対応しました。</p>\n<ul>\n<li><a href=\"https://github.com/everzet/jade.php\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Jade</a></li>\n<li><a href=\"https://github.com/fenom-template/fenom\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Fenom</a></li>\n<li><a href=\"https://github.com/dwoo-project/dwoo\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Dwoo</a></li>\n<li><a href=\"https://github.com/FoilPHP/Foil\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">FOIL</a></li>\n<li><a href=\"https://github.com/thephpleague/plates\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Plate</a></li>\n<li><a href=\"https://github.com/twigphp/Twig\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Twig</a></li>\n<li><a href=\"https://github.com/smarty-php/smarty\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Smarty</a></li>\n<li><a href=\"https://github.com/nette/latte\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Latte</a></li>\n</ul>\n<p>色々と聞きなれない名前のテンプレートエンジンが多く見つかりました。</p>\n<p>偶然見つけたPlatesに限らず、最近ライブラリを調べていると<code>thephpleague</code>というお名前のブランドをよく見かけます。<br>\nそれぞれいい感じのモジュール化されていて、ドキュメントも充実しており、高品質です。</p>\n<p>とはいえ、これといって革新的なものはなかったので、個々のテンプレートエンジンについては触れません。</p>\n<h2 id=\"採用しなかったテンプレートエンジン\" style=\"position:relative;\"><a href=\"#%E6%8E%A1%E7%94%A8%E3%81%97%E3%81%AA%E3%81%8B%E3%81%A3%E3%81%9F%E3%83%86%E3%83%B3%E3%83%97%E3%83%AC%E3%83%BC%E3%83%88%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%B3\" aria-label=\"採用しなかったテンプレートエンジン permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>採用しなかったテンプレートエンジン</h2>\n<ul>\n<li><a href=\"https://laravel.com/docs/5.0/templates\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Blade</a>\n<ul>\n<li>Laravelのテンプレートエンジン。単体のライブラリになっていない</li>\n</ul>\n</li>\n<li><a href=\"https://docs.phalconphp.com/en/latest/reference/volt.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Volt</a>\n<ul>\n<li>Phalconのテンプレートエンジン。ライブラリになっていない</li>\n</ul>\n</li>\n<li><a href=\"https://github.com/speedmax/h2o-php\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">H2O</a>\n<ul>\n<li>メンテされていない。composerない</li>\n</ul>\n</li>\n<li><a href=\"https://github.com/rainphp/raintpl3\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">RainTPL3</a>\n<ul>\n<li>issue溜まってる。メンテされていない</li>\n</ul>\n</li>\n<li><a href=\"https://github.com/pagekit/razr\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Razr</a>\n<ul>\n<li>メンテされてない</li>\n</ul>\n</li>\n<li><a href=\"https://github.com/nramenta/flow\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Flow</a>\n<ul>\n<li>開発途中で止まってるっぽい？</li>\n</ul>\n</li>\n<li><a href=\"https://github.com/Evertt/Slade\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Slade</a>\n<ul>\n<li>開発途中で止まっている</li>\n</ul>\n</li>\n<li><a href=\"https://github.com/rgamba/tonic\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Tonic</a>\n<ul>\n<li>開発途中で止まっている</li>\n</ul>\n</li>\n<li><a href=\"https://github.com/bobthecow/mustache.php\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Mustache</a>\n<ul>\n<li>開発が止まっている</li>\n</ul>\n</li>\n</ul>\n<h2 id=\"作ったライブラリ\" style=\"position:relative;\"><a href=\"#%E4%BD%9C%E3%81%A3%E3%81%9F%E3%83%A9%E3%82%A4%E3%83%96%E3%83%A9%E3%83%AA\" aria-label=\"作ったライブラリ permalink\" class=\"autolink-header before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>作ったライブラリ</h2>\n<p><a href=\"https://github.com/Leko/php-view-strategies\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">rush/php-view-strategies</a>という名前で公開しています。</p>\n<p>説明や使い方などはREADMEを御覧下さい。<br>\n記事を執筆した時点では最低限の機能しか提供していないので、ご要望やご提案などあれば<a href=\"https://github.com/Leko/php-view-strategies/issues\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Issue</a>にお願いします。</p>","timeToRead":4,"frontmatter":{"title":"昨今のPHPのテンプレートエンジンについて調べて共通インタフェースを作った","tags":["Github","PHP","Template Engine"],"date":"March 02, 2016","featuredImage":null}}},"pageContext":{"slug":"/write-interface-of-modern-template-engine-in-php/","previous":{"fields":{"slug":"/how-to-create-native-apps-with-fluid-from-web-apps/"},"frontmatter":{"title":"Fluidで任意のWebページをアプリ化する","tags":["Google Analytics","Mac"]}},"next":{"fields":{"slug":"/how-to-implement-framework-with-php-in-5-minutes/"},"frontmatter":{"title":"5分で作るPHPフレームワーク（技術調査、設計編）","tags":["Framework","Nodejs","PHP","PSR"]}}}},
    "staticQueryHashes": ["2585454260","2954598359"]}