Skip to content

Instantly share code, notes, and snippets.

@hidakatsuya
Last active September 7, 2015 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hidakatsuya/2946e9944e83779f0999 to your computer and use it in GitHub Desktop.
Save hidakatsuya/2946e9944e83779f0999 to your computer and use it in GitHub Desktop.
Report#addPage でレイアウトファイルを指定するときの仕様案

はじめに

これは thinreports-php の v0.8.0 で実装される複数レイアウト機能の API の仕様案。 以下の仕様を踏まえて「ver-A.php」「ver-B.php」のどちらの案が良いか検討。

仕様

複数ファイルの仕様

  • Thinreports\Report のコンストラクタで指定されたレイアウトは、デフォルトレイアウトとなる
  • Report#addPage でレイアウトが指定されなかった場合は、デフォルトレイアウトでページが作成される
  • Report#addPage でレイアウトが指定された場合は、指定されたレイアウトファイルでページが作成される

Report#addPagecount オプションについて

  • 0.8.0-alpha1 で実装
  • false の場合、そのページはページ数としてカウントされない
  • デフォルトは true

A

$report->addPage(array('layout' => '/path/to/other_layout.tlf'));

# ユースケース

# count オプションと一緒に指定する
$report->addPage(array(
  'layout' => '/path/to/other_layout.tlf',
  'count'  => false
));

# count オプションのみ指定する
$report->addPage(array('count' => false'));

B

$report->addPage('/path/to/other_layout.tlf');

# ユースケース

# count オプションと一緒に指定する
$report->addPage('/path/to/other_layout.tlf', false);

# count オプションのみ指定する
$report->addPage(null, false);

# ちなみに ↑ のケースは func_get_args() でがんばって以下のようにする案もあるが、
# リーダブルではないので却下
$report->addPage(false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment