PHPackages                             mrcnpdlk/url-search-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. mrcnpdlk/url-search-parser

ActiveLibrary[HTTP &amp; Networking](/categories/http)

mrcnpdlk/url-search-parser
==========================

URL search parser - filter &amp; search params manipulation

v2.7.0(3y ago)19661MITPHPPHP &gt;=7.2CI failing

Since Jun 16Pushed 3y agoCompare

[ Source](https://github.com/mrcnpdlk/url-search-parser)[ Packagist](https://packagist.org/packages/mrcnpdlk/url-search-parser)[ RSS](/packages/mrcnpdlk-url-search-parser/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (6)Versions (26)Used By (0)

mrcnpdlk/url-search-parser
==========================

[](#mrcnpdlkurl-search-parser)

[![Latest Stable Version](https://camo.githubusercontent.com/fababced2d3863d490b8db5203a90025236c18865897ffc7a489e6b1f40c0821/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6d72636e70646c6b2f75726c2d7365617263682d7061727365722e737667)](https://packagist.org/packages/mrcnpdlk/url-search-parser)[![Latest Unstable Version](https://camo.githubusercontent.com/3e88a290668cedc320a67af08cf7cc9c9d299430f85f6e9c30fffc2c9437466f/68747470733a2f2f706f7365722e707567782e6f72672f6d72636e70646c6b2f75726c2d7365617263682d7061727365722f762f756e737461626c652e706e67)](https://packagist.org/packages/mrcnpdlk/url-search-parser)[![Total Downloads](https://camo.githubusercontent.com/e64b815d4f1fde83cb60527717480628fb5e078b43cb766e49b92507f2edf430/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d72636e70646c6b2f75726c2d7365617263682d7061727365722e737667)](https://packagist.org/packages/mrcnpdlk/url-search-parser)[![Monthly Downloads](https://camo.githubusercontent.com/f4c90ff9d801521e8f1ba998bc001300cc6e70960b7c9911c84182b7ac05566d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6d72636e70646c6b2f75726c2d7365617263682d7061727365722e737667)](https://packagist.org/packages/mrcnpdlk/url-search-parser)[![License](https://camo.githubusercontent.com/a6d4cf9e828fbb0c7e7d8776494a10aba7903972253080708a429b0cc3b2b6ec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d72636e70646c6b2f75726c2d7365617263682d7061727365722e737667)](https://packagist.org/packages/mrcnpdlk/url-search-parser)[![FOSSA Status](https://camo.githubusercontent.com/0e1d9d8e3c600df1d6bb89703b1ccd667e2f9e241364686290d31efa338466fe/68747470733a2f2f6170702e666f7373612e696f2f6170692f70726f6a656374732f6769742532426769746875622e636f6d2532466d72636e70646c6b25324675726c2d7365617263682d7061727365722e7376673f747970653d736869656c64)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmrcnpdlk%2Furl-search-parser?ref=badge_shield)

---

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/5321cfb66cee6f78048f61249a06911d05507ddb3564a184823e201c85db1095/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d72636e70646c6b2f75726c2d7365617263682d7061727365722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mrcnpdlk/url-search-parser/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/07fec8d22f8a7c7f0cf97e46ff830530d38d85651895a5cc09ce8dd602413ff0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d72636e70646c6b2f75726c2d7365617263682d7061727365722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mrcnpdlk/url-search-parser/?branch=master)[![Build Status](https://camo.githubusercontent.com/053714b79d3acba47b16f3b0d9b6d6f337865f3cb71fc98c976e68e06f355e50/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d72636e70646c6b2f75726c2d7365617263682d7061727365722f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mrcnpdlk/url-search-parser/build-status/master)

[![Code Climate](https://camo.githubusercontent.com/0a62ebe01b557b70097dc90b6c0d9d75d8ef5cce5f3821cdddecf2af7e66f244/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6d72636e70646c6b2f75726c2d7365617263682d7061727365722f6261646765732f6770612e737667)](https://codeclimate.com/github/mrcnpdlk/url-search-parser)[![Issue Count](https://camo.githubusercontent.com/916857c1f53707f02424ea1c35bbd0d58af6700fbbbbf8c36cb064a667f13119/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6d72636e70646c6b2f75726c2d7365617263682d7061727365722f6261646765732f69737375655f636f756e742e737667)](https://codeclimate.com/github/mrcnpdlk/url-search-parser)

[![Build Status](https://camo.githubusercontent.com/8564b3f963327d942607f1933a8ab08750badc1567b7e14d428a00190eb1c549/68747470733a2f2f7472617669732d63692e636f6d2f6d72636e70646c6b2f75726c2d7365617263682d7061727365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/mrcnpdlk/url-search-parser)

Contents
========

[](#contents)

This boundle has been created for parsing advanced queries to easy-to-use objects.

Based on

1. [Installation](#installation)
2. [Supported parameters](#supported-parameters)
    1. [Sort](#sort)
    2. [Filter](#filter)
    3. [Limit](#limit)
    4. [Page](#page)
    5. [Phrase](#phrase)
    6. [Others](#other-params)
3. [Usage](#usage)

Installation
------------

[](#installation)

Install the latest version with [composer](https://packagist.org/packages/mrcnpdlk/teryt-api)

```
composer require mrcnpdlk/url-search-parser
```

Supported parameters
--------------------

[](#supported-parameters)

```
$oParser = new \Mrcnpdlk\Lib\UrlQueryParser\RequestParser($query);
```

### Sort

[](#sort)

Generic parameter `sort` can be used to describe sorting rules. Accommodate complex sorting requirements by letting the sort parameter take in list of comma separated fields, each with a possible unary negative to imply descending sort order. Let's look at some examples:

- `GET /messages?sort=-createDate` - Retrieves a list of messages in descending order of createDate;
- `GET /messages?sort=-type,createDate` - Retrieves a list of messages in descending order of type. Within a specific type, older messages are ordered first;

```
/**
 * @var $oSort \Mrcnpdlk\Lib\UrlQueryParser\Criteria\Sort
 */
$oSort = $oParser->getSort();
```

### Filter

[](#filter)

Filtering is more complex then sorting. Array notation is used. Let's look at some examples:

- `GET /messages?filter[created][lt]=2018-06-01` - Retrieves a list of messages where createDate is lower than 2018-06-01;
- `GET /messages?filter[type][in]=urgent,warning,error` - Retrieves a list of messages where type is urgent, warning or error;
- `GET /messages?filter[type][null]` - Retrieves a list of messages where type is NULL;

Allowed operators: `eq`,`lt`,`lte`,`gt`,`gte`,`like`,`llike`,`rlike`,`in`,`notin`,`null`,`notnull`,`regexp`

In case using not allowed operator `mrcnpdlk\Lib\UrlQueryParser\Exception\InvalidParamException` is thrown.

```
/**
 * @var $oFilter \Mrcnpdlk\Lib\UrlQueryParser\Criteria\Filter
 */
$oFilter = $oParser->getFilter();
```

### Limit

[](#limit)

Example:

- `GET /messages?limit=20` - limitation;

```
/**
 * @var $iLimit integer|null
 */
$iLimit = $oParser->getLimit(10); // in NULL default=10
```

### Page

[](#page)

Example:

- `GET /messages?page=1` - pagination. Should be used with `limit` parameter;

```
/**
 * @var $iPage integer|null
 */
$iPage = $oParser->getPage(1); // in NULL default=1
```

### Phrase

[](#phrase)

Example:

- `GET /messages?phrase=foo` - for easier filtering;

```
/**
 * @var $sPhrase string|null
 */
$sPhrase = $oParser->getPhrase(); // if not set NULL ir returned
```

### Other params

[](#other-params)

Use `getQueryParam()` method.

Example:

- `GET /messages?foo=bar&baz=5` - additional params;

```
$sFoo = $oParser->getQueryParam('foo','string'); // return 'bar'
$sBaz = $oParser->getQueryParam('baz','int'); // return 5
```

Usage
-----

[](#usage)

```
// Two ways to get `query` argument for RequestParser constructor:
$query = parse_url($url, PHP_URL_QUERY); // OR
$query = $_SERVER['QUERY_STRING'];

$oParser = new \Mrcnpdlk\Lib\UrlQueryParser\RequestParser($query);
```

### Example

[](#example)

```
$url = 'https://api.expample.com?sort=id,-name&filter[isFoo][eq]=1&filter[age][gt]=12&page=3&limit=10&offset=20';
$query =  parse_url($url, PHP_URL_QUERY);
$oParser = new \Mrcnpdlk\Lib\UrlQueryParser\RequestParser($query);

print_r($oParser->getSort()->toArray());
print_r($oParser->getFilter()->toArray());
print_r($oParser->getLimit());
print_r($oParser->getPage());
print_r($oParser->getPhrase());
```

Result

```
Array
(
    [0] => mrcnpdlk\Lib\UrlQueryParser\Criteria\SortParam Object
        (
            [param] => id
            [direction] => ASC
        )

    [1] => mrcnpdlk\Lib\UrlQueryParser\Criteria\SortParam Object
        (
            [param] => name
            [direction] => DESC
        )

)
Array
(
    [0] => mrcnpdlk\Lib\UrlQueryParser\Criteria\FilterParam Object
        (
            [param] => isFoo
            [operator] => eq
            [sqlOperator] => =
            [value] => 1
        )

    [1] => mrcnpdlk\Lib\UrlQueryParser\Criteria\FilterParam Object
        (
            [param] => age
            [operator] => gt
            [sqlOperator] => >
            [value] => 12
        )

)
10 // limit
3  // page
20 // offset

```

Running the tests
-----------------

[](#running-the-tests)

```
./vendor/bin/phpunit
```

Authors
-------

[](#authors)

- **Marcin Pudełek** - *Initial work* - [mrcnpdlk](https://github.com/mrcnpdlk)

See also the list of [contributors](https://github.com/mrcnpdlk/url-search-parser/graphs/contributors) who participated in this project.

License
-------

[](#license)

Copyright (c) 2018 Marcin Pudełek / mrcnpdlk

This project is licensed under the MIT License - see the [LICENSE](https://github.com/mrcnpdlk/url-search-parser/blob/master/LICENSE) file for details

[![FOSSA Status](https://camo.githubusercontent.com/377eb1b297c047bc63acfcceb112b56ab27cbc88f52ba57f03b18d5864d67f37/68747470733a2f2f6170702e666f7373612e696f2f6170692f70726f6a656374732f6769742532426769746875622e636f6d2532466d72636e70646c6b25324675726c2d7365617263682d7061727365722e7376673f747970653d6c61726765)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmrcnpdlk%2Furl-search-parser?ref=badge_large)

###  Health Score

32

—

LowBetter than 71% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 98.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~62 days

Recently: every ~198 days

Total

24

Last Release

1447d ago

Major Versions

v0.2.0 → v1.0.02018-06-17

v1.5.0 → v2.0.02019-03-29

### Community

Maintainers

![](https://www.gravatar.com/avatar/e9b157a438a90ac875df96b1b332262157576dad35ab4a49ab7837dd1ed4bd2b?d=identicon)[mrcnpdlk](/maintainers/mrcnpdlk)

---

Top Contributors

[![mrcnpdlk](https://avatars.githubusercontent.com/u/22945316?v=4)](https://github.com/mrcnpdlk "mrcnpdlk (51 commits)")[![fossabot](https://avatars.githubusercontent.com/u/29791463?v=4)](https://github.com/fossabot "fossabot (1 commits)")

---

Tags

restparserfilteringsearching

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mrcnpdlk-url-search-parser/health.svg)

```
[![Health](https://phpackages.com/badges/mrcnpdlk-url-search-parser/health.svg)](https://phpackages.com/packages/mrcnpdlk-url-search-parser)
```

###  Alternatives

[graviton/rql-parser

3196.2k3](/packages/graviton-rql-parser)[graviton/php-rql-parser

doctrine-odm query building wrapper to graviton/rql-parser

1758.6k1](/packages/graviton-php-rql-parser)[gointegro/hateoas

GOintegro HATEOAS Lib

408.0k1](/packages/gointegro-hateoas)[okwinza/cloudflare-api

Simple yet flexible PHP library for CloudFlare API.

1095.7k](/packages/okwinza-cloudflare-api)[phrest/api

REST API Package for Phalcon PHP

304.2k](/packages/phrest-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
