geraint/odata-query-builder

A simple OData Query Builder with fluent interface

v1.2.0 2025-03-28 09:31 UTC

This package is auto-updated.

Last update: 2025-05-28 14:46:51 UTC


README

Build and Test

This is basic query builder with a fluent interface for constructing OData URL's.

It is not intended to be a full implementation but, if your needs are modest, then it could be a good fit for your project.

Install

composer require geraint/odata-query-builder

Example

<?php

use ODataQueryBuilder\ODataQueryBuilder;

$serviceRootUrl = 'https://services.odata.org/V4/TripPinService/';
$resourcePath = 'People';
$builder = new ODataQueryBuilder($serviceRootUrl, $resourcePath);
$query = $builder
    ->filter("FirstName eq 'Scott'")
    ->select('UserName, LastName, FirstName')
    ->orderBy('LastName asc')
    ->format('json')
    ->build();

$query should now contain the following:

https://services.odata.org/V4/TripPinService/People?$filter=FirstName%20eq%20%27Scott%27&$select=UserName%2C%20LastName%2C%20FirstName&$orderby=LastName%20asc&$format=json

See doc/methods.md for more info.

License

See the LICENSE file for license rights and limitations (GNU GPLv3).

Alternatives