2017-07-14 15:08:47 +03:00
|
|
|
<?php
|
|
|
|
namespace GraphQL\Server;
|
2017-07-16 14:52:38 +03:00
|
|
|
|
|
|
|
use GraphQL\Utils\Utils;
|
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();
|
|
|
|
$instance->originalInput = $params;
|
|
|
|
|
|
|
|
$params = array_change_key_case($params, CASE_LOWER);
|
|
|
|
|
|
|
|
$params += [
|
|
|
|
'query' => null,
|
|
|
|
'queryid' => null,
|
|
|
|
'documentid' => null, // alias to queryid
|
|
|
|
'operation' => null,
|
|
|
|
'variables' => null
|
|
|
|
];
|
|
|
|
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getOriginalInput()
|
|
|
|
{
|
|
|
|
return $this->originalInput;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
}
|
|
|
|
}
|