Raml\Validator\ValidatorSchemaHelper::getQueryParameters PHP Метод

getQueryParameters() публичный Метод

public getQueryParameters ( string $method, string $path, boolean $requiredOnly = false ) : Raml\NamedParameter[]
$method string
$path string
$requiredOnly boolean
Результат Raml\NamedParameter[]
    public function getQueryParameters($method, $path, $requiredOnly = false)
    {
        $method = $this->getMethod($method, $path);
        $out = [];
        /** @var NamedParameter $parameter */
        foreach ($method->getQueryParameters() as $parameter) {
            if ($requiredOnly && !$parameter->isRequired()) {
                continue;
            }
            $out[$parameter->getKey()] = $parameter;
        }
        return $out;
    }

Usage Example

 /**
  * @param RequestInterface $request
  * @throws ValidatorRequestException
  */
 private function assertValidParameters(RequestInterface $request)
 {
     $method = $request->getMethod();
     $path = $request->getUri()->getPath();
     $schemaParameters = $this->schemaHelper->getQueryParameters($method, $path);
     $requestParameters = $this->getRequestParameters($request);
     /** @var NamedParameter $schemaParameter */
     foreach ($schemaParameters as $schemaParameter) {
         $key = $schemaParameter->getKey();
         if (!array_key_exists($key, $requestParameters)) {
             continue;
         }
         try {
             $schemaParameter->validate($requestParameters[$key]);
         } catch (ValidationException $exception) {
             $message = sprintf('Request parameter does not match schema for `%s %s`: %s', strtoupper($method), $path, $exception->getMessage());
             throw new ValidatorRequestException($message, 0, $exception);
         }
     }
 }