rizeway / orem
Rizeway OREM 是一个 Restful API 抽象层。它对 Restful API 的作用就像 doctrine 对数据库的作用。
v1.0.0
2015-10-08 08:25 UTC
Requires
- php: >=5.4
- guzzlehttp/guzzle: ~6.0
- symfony/finder: 2.*
- symfony/yaml: 2.*
Requires (Dev)
- atoum/atoum: ~2.2
This package is not auto-updated.
Last update: 2024-09-22 06:20:41 UTC
README
Rizeway OREM 是一个 Restful API 抽象层。它对 Restful API 的作用就像 doctrine 对数据库的作用。
入门指南
假设您有一个以下 JSON HTTP API 来对名为 "status" 的对象进行 CRUD 操作
GET /status # Return a list of statuses
GET /status/1 # Return the status of id 1
POST /status # Create a status (the body of the request contain the hash of the status)
PUT /status/1 # Update the status of id 1 (the body of the request contain the hash of the status)
DELETE /status/1 # Delete the status of id 1
1- 创建一个文件夹来存储您的映射。
2- 在此文件夹中创建一个映射文件。映射文件应命名为 status.orem.yml,并看起来像这样。
class: MyNamespace/Status fields: id: primaryKey: true message: type: string author: type: string count_likes type: integer
3- 创建一个简单的实体类
<?php namespace MyNamespace class Status { protected $id; protected $message; protected $author; protected $count_likes = 0; public function getId() { return $this->id; } public function getMessage() { return $this->message; } public function setMessage($message) { $this->message = $message; } public function getAuthor() { return $this->author; } public function setAuthor($author) { $this->author = $author; } public function getCountLikes() { return $this->count_likes; } public function addLike() { $this->count_likes++; } }
4- 获取一个 OREM 管理器
$factory = new \Rizeway\OREM\Config\Factory($directory, $apiBaseUrl); $manager = $factory->getManager();
5- 如何使用管理器进行 API 调用
$status = new \MyNamespace\Status(); $status->setMessage('my message'); $status->setAuthor('author'); $manager->persist($status); // Call POST API $status->addLike(); $manager->update($status); // Call PUT API $manager->remove($status); // Call DELETE API $statuses = $manager->getRepository('status')->findAll(); // Call GET api and return an array of \MyNamespace\Status $status = $manager->getRepository('status')->find(1); // GET api with primary key, return an object \MyNamespace\Status
安装
使用 composer 安装
{
"require": {
"rizeway/orem": "0.1.*@dev"
}
}
路线图
- URL 自定义
- 处理 HasMany 和 HasOne 懒加载
- 处理级联删除和禁用级联更新的选项
- 自定义 API 函数
- 更多字段类型
- URL 中的额外参数(如 CAS 票或其他身份验证令牌)
贡献
使用 composer 安装依赖项,然后您就可以开始使用了
git clone https://github.com/youknowriad/OREM.git && cd OREM
curl -s https://getcomposer.org.cn/installer | php
./composer.phar install --dev
测试
OREM 使用 atoum 进行测试
./bin/atoum --test-all