{"id":16721053,"url":"https://github.com/khalyomede/odata-query-parser","last_synced_at":"2025-04-10T10:05:15.531Z","repository":{"id":57006158,"uuid":"225968119","full_name":"khalyomede/odata-query-parser","owner":"khalyomede","description":"Parse OData v4 query strings.","archived":false,"fork":false,"pushed_at":"2024-09-07T12:45:09.000Z","size":20,"stargazers_count":2,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T01:35:16.098Z","etag":null,"topics":["odata-query-parser","php"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/khalyomede/odata-query-parser","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/khalyomede.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-04T22:24:00.000Z","updated_at":"2024-09-07T12:45:13.000Z","dependencies_parsed_at":"2024-09-07T14:01:53.260Z","dependency_job_id":null,"html_url":"https://github.com/khalyomede/odata-query-parser","commit_stats":{"total_commits":9,"total_committers":1,"mean_commits":9.0,"dds":0.0,"last_synced_commit":"8155a8f5a21f92de7ca9b7e70a5fd6e8f447cd94"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fodata-query-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fodata-query-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fodata-query-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fodata-query-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/khalyomede","download_url":"https://codeload.github.com/khalyomede/odata-query-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248198879,"owners_count":21063628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["odata-query-parser","php"],"created_at":"2024-10-12T22:28:29.964Z","updated_at":"2025-04-10T10:05:15.509Z","avatar_url":"https://github.com/khalyomede.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unmaintained notice\n\nBe aware I am not longer able to provide updates regularily. Please check this repository for a more up-to-date version: [https://github.com/Globy-App/odata-query-parser](https://github.com/Globy-App/odata-query-parser).\n\n# odata-query-parser\n\nParse OData v4 query strings.\n\n[![Packagist Version](https://img.shields.io/packagist/v/khalyomede/odata-query-parser)](https://packagist.org/packages/khalyomede/odata-query-parser) [![Packagist](https://img.shields.io/packagist/l/khalyomede/odata-query-parser)](https://github.com/khalyomede/odata-query-parser/blob/master/LICENSE) [![PHP from Packagist](https://img.shields.io/packagist/php-v/khalyomede/odata-query-parser)](https://github.com/khalyomede/odata-query-parser/blob/master/composer.json#L14) [![Build Status](https://travis-ci.com/khalyomede/odata-query-parser.svg?branch=master)](https://travis-ci.com/khalyomede/odata-query-parser) [![Maintainability](https://api.codeclimate.com/v1/badges/1ca8f176fedec7db81a2/maintainability)](https://codeclimate.com/github/khalyomede/odata-query-parser/maintainability) [![Known Vulnerabilities](https://snyk.io/test/github/khalyomede/odata-query-parser/badge.svg?targetFile=composer.lock)](https://snyk.io/test/github/khalyomede/odata-query-parser?targetFile=composer.lock)\n\n## Summary\n\n- [About](#about)\n- [Features](#features)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Examples](#examples)\n- [API](#api)\n- [Known issues](#known-issues)\n\n## About\n\nI needed to only parse query strings to convert OData v4 commands into an understandable array that I could use to make a Laravel package to offer a way to automatically use Eloquent to filter the response according to this parsed array of OData v4 command.\n\nAs I did not see a package exclusively dealing with parsing the query strings, and saw that [some people worked on their own without open sourcing it](https://stackoverflow.com/questions/14145604/parse-odata-query-uri-into-php-array), I decided I would start one myself.\n\n## Features\n\n- Parses an URL and returns an array\n- Supports `$select`, `$top`, `$skip`, `$orderby`, `$count`\n- Partial support for `$filter` (see [Known issues](#known-issues) section)\n- You can use a parse mode that let you parse these keywords without prepending `$`\n\n## Requirements\n\n- PHP \u003e= 7.2.0\n- [Composer](https://getcomposer.org/)\n\n## Installation\n\nAdd the package to your dependencies:\n\n```bash\ncomposer require khalyomede/odata-query-parser\n```\n\n## Examples\n\n- [1. Use \\$select to filter on some fields](#1-use-select-to-filter-on-some-fields)\n- [2. Use non dollar syntax](#2-use-non-dollar-syntax)\n\n### 1. Use \\$select to filter on some fields\n\nIn this example, we will use the `$select` OData query string command to filter the fields returned by our API.\n\n```php\nuse Khalyomede\\OdataQueryParser;\n\n$data = OdataQueryParser::parse('http://example.com/api/user?$select=id,name,age');\n```\n\nIf you inspect `$data`, this is what you will get:\n\n```php\n[\n  \"select\" =\u003e [\n    \"id\",\n    \"name\",\n    \"age\"\n  ]\n]\n```\n\n### 2. Use non dollar syntax\n\nIn this example, we will use a unique feature of this library: to be able to not specify any dollar, while still being able to use the OData v4 URL query parameter grammar.\n\n```php\nuse Khalyomede/OdataQueryParser;\n\n$data = OdataQueryParser::parse(\"http://example.com/api/user?select=id,name,age\", $withDollar = false);\n```\n\nIf you inspect `$data`, this is what you will get:\n\n```php\n[\n  \"select\" =\u003e [\n    \"id\",\n    \"name\",\n    \"age\"\n  ]\n]\n```\n\n## API\n\n```php\nOdataQueryParser::parse(string $url, bool $withDollar = true): array;\n```\n\n**parameters**\n\n- string `$url`: The URL to parse the query strings from. It should be a \"complete\" or \"full\" URL, which means that `http://example.com` will pass while `example.com` will not pass\n- bool `$withDollar`: Set it to false if you want to parse query strings without having to add the `$` signs before each keys.\n\n**returns**\n\nAn associative array:\n\n```php\nreturn = [\n\tstring? \"select\" =\u003e array\u003cstring\u003e,\n\tstring? \"count\" =\u003e bool,\n\tstring? \"top\" =\u003e int,\n\tstring? \"skip\" =\u003e int,\n\tstring? \"orderBy\" =\u003e array\u003cOrderBy\u003e,\n\tstring? \"filter\" =\u003e array\u003cFilter\u003e\n];\n\nOrderBy = [\n\tstring \"property\" =\u003e string,\n\tstring \"direction\" =\u003e Direction\n]\n\nDirection = \"asc\" | \"desc\"\n\nFilter = [\n\tstring \"left\" =\u003e string,\n\tstring \"operator\" =\u003e string,\n\tstring \"right\" =\u003e mixed\n]\n```\n\n**throws**\n\n- `InvalidArgumentException`\n  - If the parameter `$url` is not a valid URL (see the parameter description to know what is a valid URL)\n  - If the `$top` query string value is not an integer\n  - If the `$top` query string value is lower than 0\n  - If the `$skip` query string value is not an integer\n  - If the `$skip` query string value is lower than 0\n  - If the direction of the `$orderby` query string value is neither `asc` or `desc`\n\n## Known issues\n\n- `$filter` command will not parse `or` and functions (like `contains()` of `substringof`), because I did not focused on this for the moment (the parser for `$filter` is too simplist, I should find a way to create an AST).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhalyomede%2Fodata-query-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhalyomede%2Fodata-query-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhalyomede%2Fodata-query-parser/lists"}