ihor / ouchbase
由 Zephir 编写的 Couchbase 对象键/值映射器(OKVM)
dev-master / 0.1.x-dev
2014-06-15 17:23 UTC
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-08-28 03:37:57 UTC
README
Ouchbase 是 Couchbase 的对象键/值映射器(OKVM)。它使用 Zephir 编写,允许您在不经历 C 开发周期中的头痛和浪费时间的情况下编写高性能 PHP 扩展。
安装
只需克隆 Ouchbase 仓库并运行 ./install.sh
。如果您已安装 Zephir,则可以执行 ./build.sh。
要使用 composer 安装 Ouchbase,请在您的 composer.json 中添加以下内容
"require": {
"ihor/ouchbase": "0.1.*@dev"
},
"scripts": {
"post-install-cmd": ["./vendor/ihor/ouchbase/install.sh"],
"post-update-cmd": ["./vendor/ihor/ouchbase/install.sh"]
},
用法
class TestEntity implements \Ouchbase\Entity { private $id; public $property; public function __construct($id, $property) { $this->id = $id; $this->property = $property; } public function getId() { return $this->id; } public function getProperty() { return $this->property; } } class TestEntityRepository extends \Ouchbase\Repository { public $keyPrefix = 'test:'; protected $className = 'OuchbaseTest\TestEntity'; public function findByProperty($property) { /** @todo */ } public function toObject($data) { return new TestEntity($data['id'], $data['property']); } public function toArray($entity) { return array( 'id' => $entity->getId(), 'property' => $entity->getProperty(), ); } } $em = new \Ouchbase\EntityManager(new \Couchbase('localhost')); $em->registerManagedEntityClass('TestEntity', 'TestEntityRepository'); $entity = new TestEntity('test-id', array('hello' => 'world')); $em->persist($entity); $em->flush(); $entity->property = array('world' => 'hello'); $em->flush(); $em->delete($entity); $em->flush(); $entities = $em->getRepository('TestEntity')->findByProperty(42);
您可以在 test/OuchbaseTest/OuchbaseTest.php 中找到更多示例
文档
请查看 stub.php 以查看带有文档的 Ouchbase API。同时,使用 stub.php 在您喜欢的 IDE 中进行自动完成。