libriciel/php-odata
Composer 安装命令:
composer require libriciel/php-odata
包简介
A lightweight PHP toolbox to parse and handle OData queries
README 文档
README
OData 4.01 parser utility for PHP
Convert OData query strings into structured tokens, and generate SQL queries.
📦 Installation
composer require libriciel/php-odata
🚀 Usage
Integration with HTTP Requests
use Libriciel\PhpOData\Http\Parser;
$url = 'https://example.com' . $_SERVER['REQUEST_URI'];
$parser = Parser::fromUrl($url);
$parsed = $parser->parse();
$pdo = new PDO('sqlite:/path/to/database.sqlite');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $pdo->prepare($parsed['sql']);
$stmt->execute($parsed['params']);
// results
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
print_r($data);
Direct Usage with Static URL
use Libriciel\PhpOData\Http\Parser;
$parser = Parser::fromUrl('https://example.com/odata/Users?$filter=age gt 18 and active eq true');
$result = $parser->parse();
echo $result['sql'];
// SELECT * FROM users WHERE age > :param1 AND active = :param2
print_r($result['params']);
// [':param1' => 18, ':param2' => true]
print_r($result['fields']);
// ['age', 'active']
print_r($result['base_model']);
// Users
✅ Output
parse() returns:
[
'base_model' => 'Users', // From the URL path
'fields' => ['age', 'active'], // Fields used in the filter
'sql' => 'SELECT * FROM ...', // Generated SQL (with :paramX)
'params' => [ // Values to bind (PDO-safe)
':param1' => 18,
':param2' => true
]
]
📚 License
AGPL-3.0-only – (c) 2025 Libriciel SCOP
统计信息
- 总下载量: 277
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: AGPL-3.0-only
- 更新时间: 2025-05-13