for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Subreality\Dilmun\Anshar\Http\UriParts;
/**
* Class Query
* @package Subreality\Dilmun\Anshar\Http\UriParts
*/
class Query
{
private $unreserved_pattern = '\w\-\.~';
private $pct_encoded_pattern = '%[A-Fa-f0-9]{2}';
private $sub_delims_pattern = '\!\$&\'\(\)\*\+,;\=';
private $pchar_pattern = '\:@';
private $valid_pattern;
* Query constructor. Accepts a string representing a URI query. Construction will throw an exception if the
* query is either not a string or does not conform to the RFC3986 URI query specification.
*
* scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
* @param $query
public function __construct($query)
$this->compileValidPattern();
if (!is_string($query)) {
throw new \InvalidArgumentException("Query must be a string");
} elseif (!preg_match($this->valid_pattern, $query)) {
throw new \InvalidArgumentException("Query must conform to RFC3986 specification");
}
* Compiles a regexp pattern based on predefined patterns that define allowed characters for a query. Note that the
* pipe indicates that a query can either contain all defined characters or contain percent encoded characters.
private function compileValidPattern()
$this->valid_pattern = '/^([\/\?' .
$this->unreserved_pattern .
$this->sub_delims_pattern .
$this->pchar_pattern .
']|' .
$this->pct_encoded_pattern .
')*$/';