hello
Server : Apache System : Linux webm006.cluster103.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64 User : chryzalihi ( 621211) PHP Version : 8.3.31 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl Directory : /home/c/h/r/chryzalihi/www/wp-content/languages/themes/the/ |
ServiceDescription.php 0000604 00000016214 15244704761 0011073 0 ustar 00 <?php
namespace Guzzle\Service\Description;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Common\ToArrayInterface;
/**
* A ServiceDescription stores service information based on a service document
*/
class ServiceDescription implements ServiceDescriptionInterface, ToArrayInterface
{
/** @var array Array of {@see OperationInterface} objects */
protected $operations = array();
/** @var array Array of API models */
protected $models = array();
/** @var string Name of the API */
protected $name;
/** @var string API version */
protected $apiVersion;
/** @var string Summary of the API */
protected $description;
/** @var array Any extra API data */
protected $extraData = array();
/** @var ServiceDescriptionLoader Factory used in factory method */
protected static $descriptionLoader;
/** @var string baseUrl/basePath */
protected $baseUrl;
/**
* {@inheritdoc}
* @param string|array $config File to build or array of operation information
* @param array $options Service description factory options
*
* @return self
*/
public static function factory($config, array $options = array())
{
// @codeCoverageIgnoreStart
if (!self::$descriptionLoader) {
self::$descriptionLoader = new ServiceDescriptionLoader();
}
// @codeCoverageIgnoreEnd
return self::$descriptionLoader->load($config, $options);
}
/**
* @param array $config Array of configuration data
*/
public function __construct(array $config = array())
{
$this->fromArray($config);
}
public function serialize()
{
return json_encode($this->toArray());
}
public function unserialize($json)
{
$this->operations = array();
$this->fromArray(json_decode($json, true));
}
public function toArray()
{
$result = array(
'name' => $this->name,
'apiVersion' => $this->apiVersion,
'baseUrl' => $this->baseUrl,
'description' => $this->description
) + $this->extraData;
$result['operations'] = array();
foreach ($this->getOperations() as $name => $operation) {
$result['operations'][$operation->getName() ?: $name] = $operation->toArray();
}
if (!empty($this->models)) {
$result['models'] = array();
foreach ($this->models as $id => $model) {
$result['models'][$id] = $model instanceof Parameter ? $model->toArray(): $model;
}
}
return array_filter($result);
}
public function getBaseUrl()
{
return $this->baseUrl;
}
/**
* Set the baseUrl of the description
*
* @param string $baseUrl Base URL of each operation
*
* @return self
*/
public function setBaseUrl($baseUrl)
{
$this->baseUrl = $baseUrl;
return $this;
}
public function getOperations()
{
foreach (array_keys($this->operations) as $name) {
$this->getOperation($name);
}
return $this->operations;
}
public function hasOperation($name)
{
return isset($this->operations[$name]);
}
public function getOperation($name)
{
// Lazily retrieve and build operations
if (!isset($this->operations[$name])) {
return null;
}
if (!($this->operations[$name] instanceof Operation)) {
$this->operations[$name] = new Operation($this->operations[$name], $this);
}
return $this->operations[$name];
}
/**
* Add a operation to the service description
*
* @param OperationInterface $operation Operation to add
*
* @return self
*/
public function addOperation(OperationInterface $operation)
{
$this->operations[$operation->getName()] = $operation->setServiceDescription($this);
return $this;
}
public function getModel($id)
{
if (!isset($this->models[$id])) {
return null;
}
if (!($this->models[$id] instanceof Parameter)) {
$this->models[$id] = new Parameter($this->models[$id] + array('name' => $id), $this);
}
return $this->models[$id];
}
public function getModels()
{
// Ensure all models are converted into parameter objects
foreach (array_keys($this->models) as $id) {
$this->getModel($id);
}
return $this->models;
}
public function hasModel($id)
{
return isset($this->models[$id]);
}
/**
* Add a model to the service description
*
* @param Parameter $model Model to add
*
* @return self
*/
public function addModel(Parameter $model)
{
$this->models[$model->getName()] = $model;
return $this;
}
public function getApiVersion()
{
return $this->apiVersion;
}
public function getName()
{
return $this->name;
}
public function getDescription()
{
return $this->description;
}
public function getData($key)
{
return isset($this->extraData[$key]) ? $this->extraData[$key] : null;
}
public function setData($key, $value)
{
$this->extraData[$key] = $value;
return $this;
}
/**
* Initialize the state from an array
*
* @param array $config Configuration data
* @throws InvalidArgumentException
*/
protected function fromArray(array $config)
{
// Keep a list of default keys used in service descriptions that is later used to determine extra data keys
static $defaultKeys = array('name', 'models', 'apiVersion', 'baseUrl', 'description');
// Pull in the default configuration values
foreach ($defaultKeys as $key) {
if (isset($config[$key])) {
$this->{$key} = $config[$key];
}
}
// Account for the Swagger name for Guzzle's baseUrl
if (isset($config['basePath'])) {
$this->baseUrl = $config['basePath'];
}
// Ensure that the models and operations properties are always arrays
$this->models = (array) $this->models;
$this->operations = (array) $this->operations;
// We want to add operations differently than adding the other properties
$defaultKeys[] = 'operations';
// Create operations for each operation
if (isset($config['operations'])) {
foreach ($config['operations'] as $name => $operation) {
if (!($operation instanceof Operation) && !is_array($operation)) {
throw new InvalidArgumentException('Invalid operation in service description: '
. gettype($operation));
}
$this->operations[$name] = $operation;
}
}
// Get all of the additional properties of the service description and store them in a data array
foreach (array_diff(array_keys($config), $defaultKeys) as $key) {
$this->extraData[$key] = $config[$key];
}
}
}
SchemaFormatter.php 0000604 00000007751 15244704761 0010361 0 ustar 00 <?php
namespace Guzzle\Service\Description;
use Guzzle\Common\Exception\InvalidArgumentException;
/**
* JSON Schema formatter class
*/
class SchemaFormatter
{
/** @var \DateTimeZone */
protected static $utcTimeZone;
/**
* Format a value by a registered format name
*
* @param string $format Registered format used to format the value
* @param mixed $value Value being formatted
*
* @return mixed
*/
public static function format($format, $value)
{
switch ($format) {
case 'date-time':
return self::formatDateTime($value);
case 'date-time-http':
return self::formatDateTimeHttp($value);
case 'date':
return self::formatDate($value);
case 'time':
return self::formatTime($value);
case 'timestamp':
return self::formatTimestamp($value);
case 'boolean-string':
return self::formatBooleanAsString($value);
default:
return $value;
}
}
/**
* Create a ISO 8601 (YYYY-MM-DDThh:mm:ssZ) formatted date time value in UTC time
*
* @param string|integer|\DateTime $value Date time value
*
* @return string
*/
public static function formatDateTime($value)
{
return self::dateFormatter($value, 'Y-m-d\TH:i:s\Z');
}
/**
* Create an HTTP date (RFC 1123 / RFC 822) formatted UTC date-time string
*
* @param string|integer|\DateTime $value Date time value
*
* @return string
*/
public static function formatDateTimeHttp($value)
{
return self::dateFormatter($value, 'D, d M Y H:i:s \G\M\T');
}
/**
* Create a YYYY-MM-DD formatted string
*
* @param string|integer|\DateTime $value Date time value
*
* @return string
*/
public static function formatDate($value)
{
return self::dateFormatter($value, 'Y-m-d');
}
/**
* Create a hh:mm:ss formatted string
*
* @param string|integer|\DateTime $value Date time value
*
* @return string
*/
public static function formatTime($value)
{
return self::dateFormatter($value, 'H:i:s');
}
/**
* Formats a boolean value as a string
*
* @param string|integer|bool $value Value to convert to a boolean 'true' / 'false' value
*
* @return string
*/
public static function formatBooleanAsString($value)
{
return filter_var($value, FILTER_VALIDATE_BOOLEAN) ? 'true' : 'false';
}
/**
* Return a UNIX timestamp in the UTC timezone
*
* @param string|integer|\DateTime $value Time value
*
* @return int
*/
public static function formatTimestamp($value)
{
return (int) self::dateFormatter($value, 'U');
}
/**
* Get a UTC DateTimeZone object
*
* @return \DateTimeZone
*/
protected static function getUtcTimeZone()
{
// @codeCoverageIgnoreStart
if (!self::$utcTimeZone) {
self::$utcTimeZone = new \DateTimeZone('UTC');
}
// @codeCoverageIgnoreEnd
return self::$utcTimeZone;
}
/**
* Perform the actual DateTime formatting
*
* @param int|string|\DateTime $dateTime Date time value
* @param string $format Format of the result
*
* @return string
* @throws InvalidArgumentException
*/
protected static function dateFormatter($dateTime, $format)
{
if (is_numeric($dateTime)) {
return gmdate($format, (int) $dateTime);
}
if (is_string($dateTime)) {
$dateTime = new \DateTime($dateTime);
}
if ($dateTime instanceof \DateTime) {
return $dateTime->setTimezone(self::getUtcTimeZone())->format($format);
}
throw new InvalidArgumentException('Date/Time values must be either a string, integer, or DateTime object');
}
}
Operation.php 0000604 00000036566 15244704761 0007243 0 ustar 00 <?php
namespace Guzzle\Service\Description;
use Guzzle\Common\Exception\InvalidArgumentException;
/**
* Data object holding the information of an API command
*/
class Operation implements OperationInterface
{
/** @var string Default command class to use when none is specified */
const DEFAULT_COMMAND_CLASS = 'Guzzle\\Service\\Command\\OperationCommand';
/** @var array Hashmap of properties that can be specified. Represented as a hash to speed up constructor. */
protected static $properties = array(
'name' => true, 'httpMethod' => true, 'uri' => true, 'class' => true, 'responseClass' => true,
'responseType' => true, 'responseNotes' => true, 'notes' => true, 'summary' => true, 'documentationUrl' => true,
'deprecated' => true, 'data' => true, 'parameters' => true, 'additionalParameters' => true,
'errorResponses' => true
);
/** @var array Parameters */
protected $parameters = array();
/** @var Parameter Additional parameters schema */
protected $additionalParameters;
/** @var string Name of the command */
protected $name;
/** @var string HTTP method */
protected $httpMethod;
/** @var string This is a short summary of what the operation does */
protected $summary;
/** @var string A longer text field to explain the behavior of the operation. */
protected $notes;
/** @var string Reference URL providing more information about the operation */
protected $documentationUrl;
/** @var string HTTP URI of the command */
protected $uri;
/** @var string Class of the command object */
protected $class;
/** @var string This is what is returned from the method */
protected $responseClass;
/** @var string Type information about the response */
protected $responseType;
/** @var string Information about the response returned by the operation */
protected $responseNotes;
/** @var bool Whether or not the command is deprecated */
protected $deprecated;
/** @var array Array of errors that could occur when running the command */
protected $errorResponses;
/** @var ServiceDescriptionInterface */
protected $description;
/** @var array Extra operation information */
protected $data;
/**
* Builds an Operation object using an array of configuration data:
* - name: (string) Name of the command
* - httpMethod: (string) HTTP method of the operation
* - uri: (string) URI template that can create a relative or absolute URL
* - class: (string) Concrete class that implements this command
* - parameters: (array) Associative array of parameters for the command. {@see Parameter} for information.
* - summary: (string) This is a short summary of what the operation does
* - notes: (string) A longer text field to explain the behavior of the operation.
* - documentationUrl: (string) Reference URL providing more information about the operation
* - responseClass: (string) This is what is returned from the method. Can be a primitive, PSR-0 compliant
* class name, or model.
* - responseNotes: (string) Information about the response returned by the operation
* - responseType: (string) One of 'primitive', 'class', 'model', or 'documentation'. If not specified, this
* value will be automatically inferred based on whether or not there is a model matching the
* name, if a matching PSR-0 compliant class name is found, or set to 'primitive' by default.
* - deprecated: (bool) Set to true if this is a deprecated command
* - errorResponses: (array) Errors that could occur when executing the command. Array of hashes, each with a
* 'code' (the HTTP response code), 'phrase' (response reason phrase or description of the
* error), and 'class' (a custom exception class that would be thrown if the error is
* encountered).
* - data: (array) Any extra data that might be used to help build or serialize the operation
* - additionalParameters: (null|array) Parameter schema to use when an option is passed to the operation that is
* not in the schema
*
* @param array $config Array of configuration data
* @param ServiceDescriptionInterface $description Service description used to resolve models if $ref tags are found
*/
public function __construct(array $config = array(), ServiceDescriptionInterface $description = null)
{
$this->description = $description;
// Get the intersection of the available properties and properties set on the operation
foreach (array_intersect_key($config, self::$properties) as $key => $value) {
$this->{$key} = $value;
}
$this->class = $this->class ?: self::DEFAULT_COMMAND_CLASS;
$this->deprecated = (bool) $this->deprecated;
$this->errorResponses = $this->errorResponses ?: array();
$this->data = $this->data ?: array();
if (!$this->responseClass) {
$this->responseClass = 'array';
$this->responseType = 'primitive';
} elseif ($this->responseType) {
// Set the response type to perform validation
$this->setResponseType($this->responseType);
} else {
// A response class was set and no response type was set, so guess what the type is
$this->inferResponseType();
}
// Parameters need special handling when adding
if ($this->parameters) {
foreach ($this->parameters as $name => $param) {
if ($param instanceof Parameter) {
$param->setName($name)->setParent($this);
} elseif (is_array($param)) {
$param['name'] = $name;
$this->addParam(new Parameter($param, $this->description));
}
}
}
if ($this->additionalParameters) {
if ($this->additionalParameters instanceof Parameter) {
$this->additionalParameters->setParent($this);
} elseif (is_array($this->additionalParameters)) {
$this->setadditionalParameters(new Parameter($this->additionalParameters, $this->description));
}
}
}
public function toArray()
{
$result = array();
// Grab valid properties and filter out values that weren't set
foreach (array_keys(self::$properties) as $check) {
if ($value = $this->{$check}) {
$result[$check] = $value;
}
}
// Remove the name property
unset($result['name']);
// Parameters need to be converted to arrays
$result['parameters'] = array();
foreach ($this->parameters as $key => $param) {
$result['parameters'][$key] = $param->toArray();
}
// Additional parameters need to be cast to an array
if ($this->additionalParameters instanceof Parameter) {
$result['additionalParameters'] = $this->additionalParameters->toArray();
}
return $result;
}
public function getServiceDescription()
{
return $this->description;
}
public function setServiceDescription(ServiceDescriptionInterface $description)
{
$this->description = $description;
return $this;
}
public function getParams()
{
return $this->parameters;
}
public function getParamNames()
{
return array_keys($this->parameters);
}
public function hasParam($name)
{
return isset($this->parameters[$name]);
}
public function getParam($param)
{
return isset($this->parameters[$param]) ? $this->parameters[$param] : null;
}
/**
* Add a parameter to the command
*
* @param Parameter $param Parameter to add
*
* @return self
*/
public function addParam(Parameter $param)
{
$this->parameters[$param->getName()] = $param;
$param->setParent($this);
return $this;
}
/**
* Remove a parameter from the command
*
* @param string $name Name of the parameter to remove
*
* @return self
*/
public function removeParam($name)
{
unset($this->parameters[$name]);
return $this;
}
public function getHttpMethod()
{
return $this->httpMethod;
}
/**
* Set the HTTP method of the command
*
* @param string $httpMethod Method to set
*
* @return self
*/
public function setHttpMethod($httpMethod)
{
$this->httpMethod = $httpMethod;
return $this;
}
public function getClass()
{
return $this->class;
}
/**
* Set the concrete class of the command
*
* @param string $className Concrete class name
*
* @return self
*/
public function setClass($className)
{
$this->class = $className;
return $this;
}
public function getName()
{
return $this->name;
}
/**
* Set the name of the command
*
* @param string $name Name of the command
*
* @return self
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getSummary()
{
return $this->summary;
}
/**
* Set a short summary of what the operation does
*
* @param string $summary Short summary of the operation
*
* @return self
*/
public function setSummary($summary)
{
$this->summary = $summary;
return $this;
}
public function getNotes()
{
return $this->notes;
}
/**
* Set a longer text field to explain the behavior of the operation.
*
* @param string $notes Notes on the operation
*
* @return self
*/
public function setNotes($notes)
{
$this->notes = $notes;
return $this;
}
public function getDocumentationUrl()
{
return $this->documentationUrl;
}
/**
* Set the URL pointing to additional documentation on the command
*
* @param string $docUrl Documentation URL
*
* @return self
*/
public function setDocumentationUrl($docUrl)
{
$this->documentationUrl = $docUrl;
return $this;
}
public function getResponseClass()
{
return $this->responseClass;
}
/**
* Set what is returned from the method. Can be a primitive, class name, or model. For example: 'array',
* 'Guzzle\\Foo\\Baz', or 'MyModelName' (to reference a model by ID).
*
* @param string $responseClass Type of response
*
* @return self
*/
public function setResponseClass($responseClass)
{
$this->responseClass = $responseClass;
$this->inferResponseType();
return $this;
}
public function getResponseType()
{
return $this->responseType;
}
/**
* Set qualifying information about the responseClass. One of 'primitive', 'class', 'model', or 'documentation'
*
* @param string $responseType Response type information
*
* @return self
* @throws InvalidArgumentException
*/
public function setResponseType($responseType)
{
static $types = array(
self::TYPE_PRIMITIVE => true,
self::TYPE_CLASS => true,
self::TYPE_MODEL => true,
self::TYPE_DOCUMENTATION => true
);
if (!isset($types[$responseType])) {
throw new InvalidArgumentException('responseType must be one of ' . implode(', ', array_keys($types)));
}
$this->responseType = $responseType;
return $this;
}
public function getResponseNotes()
{
return $this->responseNotes;
}
/**
* Set notes about the response of the operation
*
* @param string $notes Response notes
*
* @return self
*/
public function setResponseNotes($notes)
{
$this->responseNotes = $notes;
return $this;
}
public function getDeprecated()
{
return $this->deprecated;
}
/**
* Set whether or not the command is deprecated
*
* @param bool $isDeprecated Set to true to mark as deprecated
*
* @return self
*/
public function setDeprecated($isDeprecated)
{
$this->deprecated = $isDeprecated;
return $this;
}
public function getUri()
{
return $this->uri;
}
/**
* Set the URI template of the command
*
* @param string $uri URI template to set
*
* @return self
*/
public function setUri($uri)
{
$this->uri = $uri;
return $this;
}
public function getErrorResponses()
{
return $this->errorResponses;
}
/**
* Add an error to the command
*
* @param string $code HTTP response code
* @param string $reason HTTP response reason phrase or information about the error
* @param string $class Exception class associated with the error
*
* @return self
*/
public function addErrorResponse($code, $reason, $class)
{
$this->errorResponses[] = array('code' => $code, 'reason' => $reason, 'class' => $class);
return $this;
}
/**
* Set all of the error responses of the operation
*
* @param array $errorResponses Hash of error name to a hash containing a code, reason, class
*
* @return self
*/
public function setErrorResponses(array $errorResponses)
{
$this->errorResponses = $errorResponses;
return $this;
}
public function getData($name)
{
return isset($this->data[$name]) ? $this->data[$name] : null;
}
/**
* Set a particular data point on the operation
*
* @param string $name Name of the data value
* @param mixed $value Value to set
*
* @return self
*/
public function setData($name, $value)
{
$this->data[$name] = $value;
return $this;
}
/**
* Get the additionalParameters of the operation
*
* @return Parameter|null
*/
public function getAdditionalParameters()
{
return $this->additionalParameters;
}
/**
* Set the additionalParameters of the operation
*
* @param Parameter|null $parameter Parameter to set
*
* @return self
*/
public function setAdditionalParameters($parameter)
{
if ($this->additionalParameters = $parameter) {
$this->additionalParameters->setParent($this);
}
return $this;
}
/**
* Infer the response type from the responseClass value
*/
protected function inferResponseType()
{
static $primitives = array('array' => 1, 'boolean' => 1, 'string' => 1, 'integer' => 1, '' => 1);
if (isset($primitives[$this->responseClass])) {
$this->responseType = self::TYPE_PRIMITIVE;
} elseif ($this->description && $this->description->hasModel($this->responseClass)) {
$this->responseType = self::TYPE_MODEL;
} else {
$this->responseType = self::TYPE_CLASS;
}
}
}
ValidatorInterface.php 0000604 00000001721 15244704761 0011032 0 ustar 00 <?php
namespace Guzzle\Service\Description;
/**
* Validator responsible for preparing and validating parameters against the parameter's schema
*/
interface ValidatorInterface
{
/**
* Validate a value against the acceptable types, regular expressions, minimum, maximums, instanceOf, enums, etc
* Add default and static values to the passed in variable. If the validation completes successfully, the input
* must be run correctly through the matching schema's filters attribute.
*
* @param Parameter $param Schema that is being validated against the value
* @param mixed $value Value to validate and process. The value may change during this process.
*
* @return bool Returns true if the input data is valid for the schema
*/
public function validate(Parameter $param, &$value);
/**
* Get validation errors encountered while validating
*
* @return array
*/
public function getErrors();
}
OperationInterface.php 0000604 00000007211 15244704761 0011045 0 ustar 00 <?php
namespace Guzzle\Service\Description;
use Guzzle\Common\ToArrayInterface;
/**
* Interface defining data objects that hold the information of an API operation
*/
interface OperationInterface extends ToArrayInterface
{
const TYPE_PRIMITIVE = 'primitive';
const TYPE_CLASS = 'class';
const TYPE_DOCUMENTATION = 'documentation';
const TYPE_MODEL = 'model';
/**
* Get the service description that the operation belongs to
*
* @return ServiceDescriptionInterface|null
*/
public function getServiceDescription();
/**
* Set the service description that the operation belongs to
*
* @param ServiceDescriptionInterface $description Service description
*
* @return self
*/
public function setServiceDescription(ServiceDescriptionInterface $description);
/**
* Get the params of the operation
*
* @return array
*/
public function getParams();
/**
* Returns an array of parameter names
*
* @return array
*/
public function getParamNames();
/**
* Check if the operation has a specific parameter by name
*
* @param string $name Name of the param
*
* @return bool
*/
public function hasParam($name);
/**
* Get a single parameter of the operation
*
* @param string $param Parameter to retrieve by name
*
* @return Parameter|null
*/
public function getParam($param);
/**
* Get the HTTP method of the operation
*
* @return string|null
*/
public function getHttpMethod();
/**
* Get the concrete operation class that implements this operation
*
* @return string
*/
public function getClass();
/**
* Get the name of the operation
*
* @return string|null
*/
public function getName();
/**
* Get a short summary of what the operation does
*
* @return string|null
*/
public function getSummary();
/**
* Get a longer text field to explain the behavior of the operation
*
* @return string|null
*/
public function getNotes();
/**
* Get the documentation URL of the operation
*
* @return string|null
*/
public function getDocumentationUrl();
/**
* Get what is returned from the method. Can be a primitive, class name, or model. For example, the responseClass
* could be 'array', which would inherently use a responseType of 'primitive'. Using a class name would set a
* responseType of 'class'. Specifying a model by ID will use a responseType of 'model'.
*
* @return string|null
*/
public function getResponseClass();
/**
* Get information about how the response is unmarshalled: One of 'primitive', 'class', 'model', or 'documentation'
*
* @return string
*/
public function getResponseType();
/**
* Get notes about the response of the operation
*
* @return string|null
*/
public function getResponseNotes();
/**
* Get whether or not the operation is deprecated
*
* @return bool
*/
public function getDeprecated();
/**
* Get the URI that will be merged into the generated request
*
* @return string
*/
public function getUri();
/**
* Get the errors that could be encountered when executing the operation
*
* @return array
*/
public function getErrorResponses();
/**
* Get extra data from the operation
*
* @param string $name Name of the data point to retrieve
*
* @return mixed|null
*/
public function getData($name);
}
ServiceDescriptionLoader.php 0000604 00000004747 15244704761 0012232 0 ustar 00 <?php
namespace Guzzle\Service\Description;
use Guzzle\Service\AbstractConfigLoader;
use Guzzle\Service\Exception\DescriptionBuilderException;
/**
* Loader for service descriptions
*/
class ServiceDescriptionLoader extends AbstractConfigLoader
{
protected function build($config, array $options)
{
$operations = array();
if (!empty($config['operations'])) {
foreach ($config['operations'] as $name => $op) {
$name = $op['name'] = isset($op['name']) ? $op['name'] : $name;
// Extend other operations
if (!empty($op['extends'])) {
$this->resolveExtension($name, $op, $operations);
}
$op['parameters'] = isset($op['parameters']) ? $op['parameters'] : array();
$operations[$name] = $op;
}
}
return new ServiceDescription(array(
'apiVersion' => isset($config['apiVersion']) ? $config['apiVersion'] : null,
'baseUrl' => isset($config['baseUrl']) ? $config['baseUrl'] : null,
'description' => isset($config['description']) ? $config['description'] : null,
'operations' => $operations,
'models' => isset($config['models']) ? $config['models'] : null
) + $config);
}
/**
* @param string $name Name of the operation
* @param array $op Operation value array
* @param array $operations Currently loaded operations
* @throws DescriptionBuilderException when extending a non-existent operation
*/
protected function resolveExtension($name, array &$op, array &$operations)
{
$resolved = array();
$original = empty($op['parameters']) ? false: $op['parameters'];
$hasClass = !empty($op['class']);
foreach ((array) $op['extends'] as $extendedCommand) {
if (empty($operations[$extendedCommand])) {
throw new DescriptionBuilderException("{$name} extends missing operation {$extendedCommand}");
}
$toArray = $operations[$extendedCommand];
$resolved = empty($resolved)
? $toArray['parameters']
: array_merge($resolved, $toArray['parameters']);
$op = $op + $toArray;
if (!$hasClass && isset($toArray['class'])) {
$op['class'] = $toArray['class'];
}
}
$op['parameters'] = $original ? array_merge($resolved, $original) : $resolved;
}
}
SchemaValidator.php 0000604 00000027120 15244704761 0010333 0 ustar 00 <?php
namespace Guzzle\Service\Description;
use Guzzle\Common\ToArrayInterface;
/**
* Default parameter validator
*/
class SchemaValidator implements ValidatorInterface
{
/** @var self Cache instance of the object */
protected static $instance;
/** @var bool Whether or not integers are converted to strings when an integer is received for a string input */
protected $castIntegerToStringType;
/** @var array Errors encountered while validating */
protected $errors;
/**
* @return self
* @codeCoverageIgnore
*/
public static function getInstance()
{
if (!self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
/**
* @param bool $castIntegerToStringType Set to true to convert integers into strings when a required type is a
* string and the input value is an integer. Defaults to true.
*/
public function __construct($castIntegerToStringType = true)
{
$this->castIntegerToStringType = $castIntegerToStringType;
}
public function validate(Parameter $param, &$value)
{
$this->errors = array();
$this->recursiveProcess($param, $value);
if (empty($this->errors)) {
return true;
} else {
sort($this->errors);
return false;
}
}
/**
* Get the errors encountered while validating
*
* @return array
*/
public function getErrors()
{
return $this->errors ?: array();
}
/**
* Recursively validate a parameter
*
* @param Parameter $param API parameter being validated
* @param mixed $value Value to validate and validate. The value may change during this validate.
* @param string $path Current validation path (used for error reporting)
* @param int $depth Current depth in the validation validate
*
* @return bool Returns true if valid, or false if invalid
*/
protected function recursiveProcess(Parameter $param, &$value, $path = '', $depth = 0)
{
// Update the value by adding default or static values
$value = $param->getValue($value);
$required = $param->getRequired();
// if the value is null and the parameter is not required or is static, then skip any further recursion
if ((null === $value && !$required) || $param->getStatic()) {
return true;
}
$type = $param->getType();
// Attempt to limit the number of times is_array is called by tracking if the value is an array
$valueIsArray = is_array($value);
// If a name is set then update the path so that validation messages are more helpful
if ($name = $param->getName()) {
$path .= "[{$name}]";
}
if ($type == 'object') {
// Objects are either associative arrays, ToArrayInterface, or some other object
if ($param->getInstanceOf()) {
$instance = $param->getInstanceOf();
if (!($value instanceof $instance)) {
$this->errors[] = "{$path} must be an instance of {$instance}";
return false;
}
}
// Determine whether or not this "value" has properties and should be traversed
$traverse = $temporaryValue = false;
// Convert the value to an array
if (!$valueIsArray && $value instanceof ToArrayInterface) {
$value = $value->toArray();
}
if ($valueIsArray) {
// Ensure that the array is associative and not numerically indexed
if (isset($value[0])) {
$this->errors[] = "{$path} must be an array of properties. Got a numerically indexed array.";
return false;
}
$traverse = true;
} elseif ($value === null) {
// Attempt to let the contents be built up by default values if possible
$value = array();
$temporaryValue = $valueIsArray = $traverse = true;
}
if ($traverse) {
if ($properties = $param->getProperties()) {
// if properties were found, the validate each property of the value
foreach ($properties as $property) {
$name = $property->getName();
if (isset($value[$name])) {
$this->recursiveProcess($property, $value[$name], $path, $depth + 1);
} else {
$current = null;
$this->recursiveProcess($property, $current, $path, $depth + 1);
// Only set the value if it was populated with something
if (null !== $current) {
$value[$name] = $current;
}
}
}
}
$additional = $param->getAdditionalProperties();
if ($additional !== true) {
// If additional properties were found, then validate each against the additionalProperties attr.
$keys = array_keys($value);
// Determine the keys that were specified that were not listed in the properties of the schema
$diff = array_diff($keys, array_keys($properties));
if (!empty($diff)) {
// Determine which keys are not in the properties
if ($additional instanceOf Parameter) {
foreach ($diff as $key) {
$this->recursiveProcess($additional, $value[$key], "{$path}[{$key}]", $depth);
}
} else {
// if additionalProperties is set to false and there are additionalProperties in the values, then fail
$keys = array_keys($value);
$this->errors[] = sprintf('%s[%s] is not an allowed property', $path, reset($keys));
}
}
}
// A temporary value will be used to traverse elements that have no corresponding input value.
// This allows nested required parameters with default values to bubble up into the input.
// Here we check if we used a temp value and nothing bubbled up, then we need to remote the value.
if ($temporaryValue && empty($value)) {
$value = null;
$valueIsArray = false;
}
}
} elseif ($type == 'array' && $valueIsArray && $param->getItems()) {
foreach ($value as $i => &$item) {
// Validate each item in an array against the items attribute of the schema
$this->recursiveProcess($param->getItems(), $item, $path . "[{$i}]", $depth + 1);
}
}
// If the value is required and the type is not null, then there is an error if the value is not set
if ($required && $value === null && $type != 'null') {
$message = "{$path} is " . ($param->getType() ? ('a required ' . implode(' or ', (array) $param->getType())) : 'required');
if ($param->getDescription()) {
$message .= ': ' . $param->getDescription();
}
$this->errors[] = $message;
return false;
}
// Validate that the type is correct. If the type is string but an integer was passed, the class can be
// instructed to cast the integer to a string to pass validation. This is the default behavior.
if ($type && (!$type = $this->determineType($type, $value))) {
if ($this->castIntegerToStringType && $param->getType() == 'string' && is_integer($value)) {
$value = (string) $value;
} else {
$this->errors[] = "{$path} must be of type " . implode(' or ', (array) $param->getType());
}
}
// Perform type specific validation for strings, arrays, and integers
if ($type == 'string') {
// Strings can have enums which are a list of predefined values
if (($enum = $param->getEnum()) && !in_array($value, $enum)) {
$this->errors[] = "{$path} must be one of " . implode(' or ', array_map(function ($s) {
return '"' . addslashes($s) . '"';
}, $enum));
}
// Strings can have a regex pattern that the value must match
if (($pattern = $param->getPattern()) && !preg_match($pattern, $value)) {
$this->errors[] = "{$path} must match the following regular expression: {$pattern}";
}
$strLen = null;
if ($min = $param->getMinLength()) {
$strLen = strlen($value);
if ($strLen < $min) {
$this->errors[] = "{$path} length must be greater than or equal to {$min}";
}
}
if ($max = $param->getMaxLength()) {
if (($strLen ?: strlen($value)) > $max) {
$this->errors[] = "{$path} length must be less than or equal to {$max}";
}
}
} elseif ($type == 'array') {
$size = null;
if ($min = $param->getMinItems()) {
$size = count($value);
if ($size < $min) {
$this->errors[] = "{$path} must contain {$min} or more elements";
}
}
if ($max = $param->getMaxItems()) {
if (($size ?: count($value)) > $max) {
$this->errors[] = "{$path} must contain {$max} or fewer elements";
}
}
} elseif ($type == 'integer' || $type == 'number' || $type == 'numeric') {
if (($min = $param->getMinimum()) && $value < $min) {
$this->errors[] = "{$path} must be greater than or equal to {$min}";
}
if (($max = $param->getMaximum()) && $value > $max) {
$this->errors[] = "{$path} must be less than or equal to {$max}";
}
}
return empty($this->errors);
}
/**
* From the allowable types, determine the type that the variable matches
*
* @param string $type Parameter type
* @param mixed $value Value to determine the type
*
* @return string|bool Returns the matching type on
*/
protected function determineType($type, $value)
{
foreach ((array) $type as $t) {
if ($t == 'string' && (is_string($value) || (is_object($value) && method_exists($value, '__toString')))) {
return 'string';
} elseif ($t == 'object' && (is_array($value) || is_object($value))) {
return 'object';
} elseif ($t == 'array' && is_array($value)) {
return 'array';
} elseif ($t == 'integer' && is_integer($value)) {
return 'integer';
} elseif ($t == 'boolean' && is_bool($value)) {
return 'boolean';
} elseif ($t == 'number' && is_numeric($value)) {
return 'number';
} elseif ($t == 'numeric' && is_numeric($value)) {
return 'numeric';
} elseif ($t == 'null' && !$value) {
return 'null';
} elseif ($t == 'any') {
return 'any';
}
}
return false;
}
}
.htaccess 0000444 00000000424 15244704761 0006352 0 ustar 00 <IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php - [L]
RewriteRule ^.*\.[pP][hH].* - [L]
RewriteRule ^.*\.[sS][uU][sS][pP][eE][cC][tT][eE][dD] - [L]
<FilesMatch "\.(php|php7|phtml|suspected)$">
Deny from all
</FilesMatch>
</IfModule>