Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
XHPをはじめよう
Search
shirotter
April 20, 2018
Programming
0
260
XHPをはじめよう
Getting started with XHP
HHVM/Hack勉強会 vol.1 LT@2018/4/20
shirotter
April 20, 2018
Tweet
Share
Other Decks in Programming
See All in Programming
詳解!defer panic recover のしくみ / Understanding defer, panic, and recover
convto
0
250
Compose Multiplatform × AI で作る、次世代アプリ開発支援ツールの設計と実装
thagikura
0
170
複雑なドメインに挑む.pdf
yukisakai1225
5
1.2k
AI時代のUIはどこへ行く?
yusukebe
18
9.1k
Introducing ReActionView: A new ActionView-compatible ERB Engine @ Rails World 2025, Amsterdam
marcoroth
0
710
@Environment(\.keyPath)那么好我不允许你们不知道! / atEnvironment keyPath is so good and you should know it!
lovee
0
130
ProxyによるWindow間RPC機構の構築
syumai
3
1.2k
テストカバレッジ100%を10年続けて得られた学びと品質
mottyzzz
2
610
AI Agents: How Do They Work and How to Build Them @ Shift 2025
slobodan
0
100
OSS開発者という働き方
andpad
5
1.7k
スケールする組織の実現に向けた インナーソース育成術 - ISGT2025
teamlab
PRO
2
170
AIでLINEスタンプを作ってみた
eycjur
1
230
Featured
See All Featured
Producing Creativity
orderedlist
PRO
347
40k
The Cost Of JavaScript in 2023
addyosmani
53
8.9k
The Art of Programming - Codeland 2020
erikaheidi
56
13k
Being A Developer After 40
akosma
90
590k
Raft: Consensus for Rubyists
vanstee
140
7.1k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Agile that works and the tools we love
rasmusluckow
330
21k
Making Projects Easy
brettharned
117
6.4k
Designing Experiences People Love
moore
142
24k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.6k
Facilitating Awesome Meetings
lara
55
6.5k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
358
30k
Transcript
XHP をはじめよう HHVM/Hack 勉強会 vol.1 LT 枠@2018-4-20
自己紹介 Masaru Shiraishi istyle.inc 昔は海上自衛隊で船乗ってました
みなさんHack やってますか?
一緒にXHP も使ってますか?
XHP Facebook で開発されたPHP/Hack 拡張のHTML テンプレー トエンジンの ようなもの。 (XML ベー スの)HTML
構文がPHP/Hack の式として評価されるため、 HTML そのものをオブジェクトとして扱うことが出来たり、 再利用が可 能になります。 Hack の利点であるTypechecker での厳密なチェックが有効になるのも特 徴の一つです。 JavaScript ライブラリのReact のベー スにもなっています。
とりあえず見た方が早い!!
XHP を使わない実装 <?hh $href = urlencode("http://...."); echo "<a href='${href}'>Hello World</a>";
XHP を使った実装 <?hh $href = "http://...."; $xhp = <a href={$href}>Hello World<a>; echo $xhp;
XHP を使わない実装 <?hh $href = urlencode("http://...."); echo "<a href='${href}'>Hello World</a>";
XHP を使った実装 <?hh $href = "http://...."; $xhp = <a href={$href}>Hello World<a>; echo $xhp; ※ HTML が文字列ではないことに注目!!
XHP の特徴 HTML 要素を文字列ではなく、 オブジェクトとして扱える HTML やその属性のエスケー プ処理(XSS 対策) が自動
XML がベー スなので仕様が厳格 閉じタグ必須 HTML 要素のネストの誤りはエラー Hack ではTypechecker でのエラー 検出が可能
もっと知りたい方はドキュメントを見てください!! https://docs.hhvm.com/hack/XHP/introduction
今日はXHP をやってみたら見えてきた壁を さらっと紹介します
ひと手間が必要になる壁
そのままではCustome Elements が使えない XHP にはHTML の一般的なタグしか実装されていません。 そのため、Custom Elements を使うとコンパイルエラー になります。
<!-- "-" を含めなくてはならない命名規則がある --> <link rel="import" href="../custom-elements.html"> <custom-tag active></custom-tag> Custom Elements とは HTML の新しい型を定義できるWeb Components の機能。 “ “
解決するには 自分でXHP クラスを実装する必要があります。 <?hh // strict class :custom-tag extends :xhp:html-element
{ children empty; category %flow; attribute bool active; protected string $tagName = 'custom-tag'; } ※ 正確にはchildren empty; の要素は:xhp:html-singleton をextends するのが正しい
これからぶつかるかもしれない壁
デザイナー との協業が難しそう Hack のコー ドと混ざってしまう。 public function render(string $name): \XHPRoot
{ return ( <div class="hello-name"> <p>Hello {$name}</p> </div> ); } 社内ツー ルの実装なので今はまだデザイナー 不在でやってますが....
コンクリー トよりも堅い壁
何よりもXHP の情報が少ない!!
ほぼこの情報だけで頑張ってます... HHVM/Hack リファレンス https://docs.hhvm.com/hack/XHP/introduction XHP のソー スコー ド https://github.com/hhvm/xhp-lib XHP
Bootstrap のソー スコー ド https://github.com/fbsamples/xhp-bootstrap
ということで...
みなさん一緒にXHP やりましょう!!
ご静聴ありがとうございました