2018-11-25 23:42:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace BeyondCode\LaravelWebSockets;
|
|
|
|
|
|
|
|
|
|
use Psr\Http\Message\RequestInterface;
|
|
|
|
|
|
|
|
|
|
class QueryParameters
|
|
|
|
|
{
|
2020-08-18 17:21:22 +00:00
|
|
|
/**
|
|
|
|
|
* The Request object.
|
|
|
|
|
*
|
|
|
|
|
* @var \Psr\Http\Message\RequestInterface
|
|
|
|
|
*/
|
2018-11-25 23:42:45 +00:00
|
|
|
protected $request;
|
|
|
|
|
|
|
|
|
|
public static function create(RequestInterface $request)
|
|
|
|
|
{
|
|
|
|
|
return new static($request);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 17:21:22 +00:00
|
|
|
/**
|
|
|
|
|
* Initialize the class.
|
|
|
|
|
*
|
|
|
|
|
* @param \Psr\Http\Message\RequestInterface $request
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2018-11-25 23:42:45 +00:00
|
|
|
public function __construct(RequestInterface $request)
|
|
|
|
|
{
|
|
|
|
|
$this->request = $request;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 17:21:22 +00:00
|
|
|
/**
|
|
|
|
|
* Get all query parameters.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2018-11-25 23:42:45 +00:00
|
|
|
public function all(): array
|
|
|
|
|
{
|
|
|
|
|
$queryParameters = [];
|
|
|
|
|
|
|
|
|
|
parse_str($this->request->getUri()->getQuery(), $queryParameters);
|
|
|
|
|
|
|
|
|
|
return $queryParameters;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 17:21:22 +00:00
|
|
|
/**
|
|
|
|
|
* Get a specific query parameter.
|
|
|
|
|
*
|
|
|
|
|
* @param string $name
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2018-11-25 23:42:45 +00:00
|
|
|
public function get(string $name): string
|
|
|
|
|
{
|
|
|
|
|
return $this->all()[$name] ?? '';
|
|
|
|
|
}
|
2018-12-04 21:22:33 +00:00
|
|
|
}
|