nkey / caribu
基于注解的 PHP 对象关系映射框架
v1.0.1
2016-01-02 17:07 UTC
Requires
- php: ~5.6|~7.0
- ext-date: *
- ext-pdo: *
- ext-reflection: *
- nkey/phpgenerics: dev-master
- psr/log: ~1.0
Requires (Dev)
- pdepend/pdepend: ~2.0
- phploc/phploc: ~2.0
- phpmd/phpmd: ~2.0
- phpunit/dbunit: ~2.0
- phpunit/phpunit: ~4.8|~5.0
- sebastian/phpcpd: ~2.0
- squizlabs/php_codesniffer: ~2.0
- theseer/phpdox: ~0.8
This package is auto-updated.
Last update: 2024-09-29 04:48:38 UTC
README
caribu
基于注解的 PHP 对象关系映射器
本项目旨在提供一个易于使用的对象关系映射器。主要目标是支持开发者编写只包含简单属性的类,并将其作为实体存储到数据库中。
它支持注解,因此非常灵活。
以下是一个非常基本的示例(针对 sqlite)
CREATE TABLE super_duper_content (id INTEGER PRIMARY KEY, content TEXT);
/* SuperDuperEntity.php */ /** * @table super_duper_content */ class SuperDuperEntity extends AbstractModel { /** * @column id */ private $sid; private $content; public function setSid($sid) { $this->sid = $sid; } public function getSid() { return $this->sid; } public function setContent($content) { $this->content = $content; } public function getContent() { return $this->content; } }
/* write-data-example.php */ use \Nkey\Caribu\Orm\Orm; /* First configure the ORM */ Orm::configure(array( 'type' => 'sqlite', 'file' => ':memory:' )); // Create sqlite database table for memory storage // Orm::getInstance()->getConnection()->exec("CREATE TABLE super_duper_content (id INTEGER PRIMARY KEY, content TEXT)"); /* Now create a new entity and persist it to database */ $entity = new SuperDuperEntity(); $entity->setContent("Mega important content"); $entity->persist();
/* read-data-example.php */ /* First read the entity from database */ $entity = SuperDuperEntity::find(array('content' => "Mega important content")); /* Display the content */ echo $entity->getContent();
无需自己编写基础设施和样板代码。让 ORM 为您完成繁重的工作。
Caribu 通过支持注解提供约定优于配置的行为。
有关功能和使用方法的更多信息,请参阅维基。