2017-07-14 15:08:47 +03:00
|
|
|
<?php
|
|
|
|
namespace GraphQL\Server;
|
2017-07-16 14:52:38 +03:00
|
|
|
|
2017-07-14 15:08:47 +03:00
|
|
|
/**
|
|
|
|
* Class QueryParams
|
|
|
|
* Represents all available parsed query parameters
|
|
|
|
*
|
|
|
|
* @package GraphQL\Server
|
|
|
|
*/
|
|
|
|
class OperationParams
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $query;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $queryId;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $operation;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $variables;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private $originalInput;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
2017-07-17 12:57:30 +03:00
|
|
|
private $readOnly;
|
2017-07-14 15:08:47 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an instance from given array
|
|
|
|
*
|
|
|
|
* @param array $params
|
2017-07-17 12:57:30 +03:00
|
|
|
* @param bool $readonly
|
2017-07-14 15:08:47 +03:00
|
|
|
*
|
|
|
|
* @return static
|
|
|
|
*/
|
2017-07-17 12:57:30 +03:00
|
|
|
public static function create(array $params, $readonly = false)
|
2017-07-14 15:08:47 +03:00
|
|
|
{
|
|
|
|
$instance = new static();
|
|
|
|
|
|
|
|
$params = array_change_key_case($params, CASE_LOWER);
|
2017-07-19 15:30:39 +03:00
|
|
|
$instance->originalInput = $params;
|
2017-07-14 15:08:47 +03:00
|
|
|
|
|
|
|
$params += [
|
|
|
|
'query' => null,
|
|
|
|
'queryid' => null,
|
|
|
|
'documentid' => null, // alias to queryid
|
|
|
|
'operation' => null,
|
|
|
|
'variables' => null
|
|
|
|
];
|
|
|
|
|
2017-07-19 15:30:39 +03:00
|
|
|
if (is_string($params['variables'])) {
|
|
|
|
$tmp = json_decode($params['variables'], true);
|
|
|
|
if (!json_last_error()) {
|
|
|
|
$params['variables'] = $tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-14 15:08:47 +03:00
|
|
|
$instance->query = $params['query'];
|
|
|
|
$instance->queryId = $params['queryid'] ?: $params['documentid'];
|
|
|
|
$instance->operation = $params['operation'];
|
|
|
|
$instance->variables = $params['variables'];
|
2017-07-17 12:57:30 +03:00
|
|
|
$instance->readOnly = (bool) $readonly;
|
2017-07-14 15:08:47 +03:00
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-07-19 15:30:39 +03:00
|
|
|
* @param string $key
|
|
|
|
* @return mixed
|
2017-07-14 15:08:47 +03:00
|
|
|
*/
|
2017-07-19 15:30:39 +03:00
|
|
|
public function getOriginalInput($key)
|
2017-07-14 15:08:47 +03:00
|
|
|
{
|
2017-07-19 15:30:39 +03:00
|
|
|
return isset($this->originalInput[$key]) ? $this->originalInput[$key] : null;
|
2017-07-14 15:08:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2017-07-17 12:57:30 +03:00
|
|
|
public function isReadOnly()
|
2017-07-14 15:08:47 +03:00
|
|
|
{
|
2017-07-17 12:57:30 +03:00
|
|
|
return $this->readOnly;
|
2017-07-14 15:08:47 +03:00
|
|
|
}
|
|
|
|
}
|