public function factory($name, array $args = array()) { $command = $this->description->getOperation($name); // If a command wasn't found, then try to uppercase the first letter and try again if (!$command) { $command = $this->description->getOperation(ucfirst($name)); // If an inflector was passed, then attempt to get the command using snake_case inflection if (!$command && $this->inflector) { $command = $this->description->getOperation($this->inflector->snake($name)); } } if ($command) { $class = $command->getClass(); return new $class($args, $command, $this->description); } }
/** * 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; } }
/** * Create a new Parameter using an associative array of data. The array can contain the following information: * - name: (string) Unique name of the parameter * - type: (string|array) Type of variable (string, number, integer, boolean, object, array, numeric, * null, any). Types are using for validation and determining the structure of a parameter. You * can use a union type by providing an array of simple types. If one of the union types matches * the provided value, then the value is valid. * - instanceOf: (string) When the type is an object, you can specify the class that the object must implement * - required: (bool) Whether or not the parameter is required * - default: (mixed) Default value to use if no value is supplied * - static: (bool) Set to true to specify that the parameter value cannot be changed from the default * - description: (string) Documentation of the parameter * - location: (string) The location of a request used to apply a parameter. Custom locations can be registered * with a command, but the defaults are uri, query, header, body, json, xml, postField, postFile. * - sentAs: (string) Specifies how the data being modeled is sent over the wire. For example, you may wish * to include certain headers in a response model that have a normalized casing of FooBar, but the * actual header is x-foo-bar. In this case, sentAs would be set to x-foo-bar. * - filters: (array) Array of static method names to to run a parameter value through. Each value in the * array must be a string containing the full class path to a static method or an array of complex * filter information. You can specify static methods of classes using the full namespace class * name followed by '::' (e.g. Foo\Bar::baz()). Some filters require arguments in order to properly * filter a value. For complex filters, use a hash containing a 'method' key pointing to a static * method, and an 'args' key containing an array of positional arguments to pass to the method. * Arguments can contain keywords that are replaced when filtering a value: '@value' is replaced * with the value being validated, '@api' is replaced with the Parameter object. * - properties: When the type is an object, you can specify nested parameters * - additionalProperties: (array) This attribute defines a schema for all properties that are not explicitly * defined in an object type definition. If specified, the value MUST be a schema or a boolean. If * false is provided, no additional properties are allowed beyond the properties defined in the * schema. The default value is an empty schema which allows any value for additional properties. * - items: This attribute defines the allowed items in an instance array, and MUST be a schema or an array * of schemas. The default value is an empty schema which allows any value for items in the * instance array. * When this attribute value is a schema and the instance value is an array, then all the items * in the array MUST be valid according to the schema. * - pattern: When the type is a string, you can specify the regex pattern that a value must match * - enum: When the type is a string, you can specify a list of acceptable values * - minItems: (int) Minimum number of items allowed in an array * - maxItems: (int) Maximum number of items allowed in an array * - minLength: (int) Minimum length of a string * - maxLength: (int) Maximum length of a string * - minimum: (int) Minimum value of an integer * - maximum: (int) Maximum value of an integer * - data: (array) Any additional custom data to use when serializing, validating, etc * - format: (string) Format used to coax a value into the correct format when serializing or unserializing. * You may specify either an array of filters OR a format, but not both. * Supported values: date-time, date, time, timestamp, date-time-http * - $ref: (string) String referencing a service description model. The parameter is replaced by the * schema contained in the model. * * @param array $data Array of data as seen in service descriptions * @param ServiceDescriptionInterface $description Service description used to resolve models if $ref tags are found * * @throws InvalidArgumentException */ public function __construct(array $data = array(), ServiceDescriptionInterface $description = null) { if ($description) { if (isset($data['$ref'])) { if ($model = $description->getModel($data['$ref'])) { $data = $model->toArray() + $data; } } elseif (isset($data['extends'])) { // If this parameter extends from another parameter then start with the actual data // union in the parent's data (e.g. actual supersedes parent) if ($extends = $description->getModel($data['extends'])) { $data += $extends->toArray(); } } } // Pull configuration data into the parameter foreach ($data as $key => $value) { $this->{$key} = $value; } $this->serviceDescription = $description; $this->required = (bool) $this->required; $this->data = (array) $this->data; if ($this->filters) { $this->setFilters((array) $this->filters); } if ($this->type == 'object' && $this->additionalProperties === null) { $this->additionalProperties = true; } }
/** * Get an endpoint for a specific region from a service description * @deprecated This function will no longer be updated to work with new regions. */ public static function getEndpoint(ServiceDescriptionInterface $description, $region, $scheme) { $service = $description->getData('serviceFullName'); // Lookup the region in the service description if (!($regions = $description->getData('regions'))) { throw new InvalidArgumentException("No regions found in the {$service} description"); } // Ensure that the region exists for the service if (!isset($regions[$region])) { throw new InvalidArgumentException("{$region} is not a valid region for {$service}"); } // Ensure that the scheme is valid if ($regions[$region][$scheme] == false) { throw new InvalidArgumentException("{$scheme} is not a valid URI scheme for {$service} in {$region}"); } return $scheme . '://' . $regions[$region]['hostname']; }
public function setDescription(ServiceDescriptionInterface $service) { $this->serviceDescription = $service; if ($this->getCommandFactory() && $this->getCommandFactory() instanceof CompositeFactory) { $this->commandFactory->add(new Command\Factory\ServiceDescriptionFactory($service)); } // If a baseUrl was set on the description, then update the client if ($baseUrl = $service->getBaseUrl()) { $this->setBaseUrl($baseUrl); } return $this; }