jinnguyen / puja-entity
Puja-Entity是一个用于管理实体对象和轻松获取Docblock文档的抽象层
v1.3.1
2016-12-18 12:30 UTC
Requires
- php: >=5.3
This package is not auto-updated.
Last update: 2024-09-23 14:07:59 UTC
README
Puja-Entity是一个用于管理实体对象和轻松获取Docblock文档的抽象层
安装
composer required jinnguyen/puja-entity
用法
include '/path/to/vendor/autoload.php'; use Puja\Entity\Entity;
示例
/**
* This comment is copied from ContentEntity->getDocblock(); you should do it each time you change the ContentEntity->attributes
* @method int getId()
* @method setId(int $attr)
* @method hasId()
* @method unsetId()
* @method string getName()
* @method setName(string $attr)
* @method hasName()
* @method unsetName()
* @method string getCreatedAt()
* @method setCreatedAt(string $attr)
* @method hasCreatedAt()
* @method unsetCreatedAt()
* @method string getCreatedAt()
* @method setCreatedAt(string $attr)
* @method hasCreatedAt()
* @method unsetCreatedAt()
* @method Category getCategory()
* @method setCategory(Category $attr)
* @method hasCategory()
* @method unsetCategory()
*/
class ContentEntity extends Entity
{
protected $attributes = array(
'id' => Entity::DATATYPE_INT,
'name' => Entity::DATATYPE_STRING,
'created_at' => Entity::DATATYPE_STRING,
'price' => Entity::DATATYPE_INT,
'category' => 'Category',
);
protected $defaults = array(
'price' => 5,
);
}
class Category
{
public $id = 1;
public $name = 'Category 1';
}
$content = new ContentEntity(array(
'id' => 1,
'name' => 'Content 1',
'created_at' => '2016-11-18 00:00:00',
'category' => new Category()
));
echo $content->getId(); // 1
echo $content->getName(); // Content 1
echo $content->getCreatedAt(); // 2016-11-18 00:00:00
echo $content->getId(); // 5
$category = $content->getCategory();
echo $category->name; // Category 1
echo $content->getDocblock(); // The dockbock content is used above class ContentEntity
注意:ContentEntity是Entity,但Category不是。