-
Notifications
You must be signed in to change notification settings - Fork 0
Home ja
USAMI Kenta edited this page Feb 22, 2015
·
1 revision
このようなプロパティを持った単純なクラスがあるとします。
<?php
namespace MyApp;
final class Book
{
/** @var string */
public $title;
/** @var \MyApp\Author[] */
public $authors;
/** @var \MyApp\ISBN */
public $isbn;
/** @var string */
public $lang; // expects en|fr|zh|ru|es|ar
}
以下のように書き直すことで、実行時に型チェックをすることができるようになります。
<?php
namespace MyApp;
/**
* @property string $title
* @property \MyApp\Author[] $authors
* @property \MyApp\ISBN $isbn
* @property string $lang
*/
final class Book
{
use \Teto\Object\TypedProperty;
protected static $property_types = [
'title' => 'string',
'authors' => 'MyApp\Author[]',
'isbn' => '?MyApp\ISBN',
'lang' => 'enum',
];
protected static $property_types = [
'lang' => ['en', 'fr', 'zh', 'ru', 'es', 'ar'],
];
}