Esempio n. 1
0
 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 ($extends = $description->getModel($data['extends'])) {
                 $data += $extends->toArray();
             }
         }
     }
     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;
     }
 }
Esempio n. 2
0
 /**
  * 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'])) {
             // Replace references to models with the actual model data
             if ($model = $description->getModel($data['$ref'])) {
                 $data = $model->toArray();
             }
         } 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;
     }
 }
 /**
  * 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'])) {
                 // The name of the original parameter should override the ref name if one is available
                 $name = empty($data['name']) ? null : $data['name'];
                 $data = $model->toArray();
                 if ($name) {
                     $data['name'] = $name;
                 }
             }
         } 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;
     }
 }
Esempio n. 4
0
 /**
  * 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)
 {
     // Replace references to models with the actual model data
     if ($description && isset($data['$ref']) && $description->getModel($data['$ref'])) {
         $data = $description->getModel($data['$ref'])->toArray();
     }
     // Pull configuration data into the parameter
     foreach ($data as $key => $value) {
         $this->{$key} = $value;
     }
     $this->required = (bool) $this->required;
     $this->data = (array) $this->data;
     if ($this->filters) {
         $this->setFilters((array) $this->filters);
     }
     if ($this->type == 'object') {
         if ($this->properties) {
             $this->properties = array();
             foreach ($data['properties'] as $name => $property) {
                 $property['name'] = $name;
                 $this->addProperty(new static($property, $description));
             }
         }
         if ($this->additionalProperties && is_array($this->additionalProperties)) {
             $this->setAdditionalProperties(new static($this->additionalProperties, $description));
         } elseif ($this->additionalProperties === null) {
             $this->additionalProperties = true;
         }
     } elseif ($this->type == 'array' && $this->items) {
         $this->setItems(new static($this->items, $description));
     }
 }