private function stockHeader(Parameter $schema, $paramValue, array &$options)
 {
     $paramName = $schema->getName();
     if (stripos($paramName, 'metadata') !== false) {
         return $this->stockMetadataHeader($schema, $paramValue, $options);
     }
     $options['headers'] += is_scalar($paramValue) ? [$schema->getPrefixedName() => $paramValue] : [];
 }
 /**
  * A generic method that will populate a JSON structure with a value according to a schema. It
  * supports multiple types and will delegate accordingly.
  *
  * @param Parameter $param     The schema that defines how the JSON field is being populated
  * @param mixed     $userValue The user value that is populating a JSON field
  * @param array     $json      The existing JSON structure that will be populated
  *
  * @return array
  */
 public function stockJson(Parameter $param, $userValue, array $json) : array
 {
     if ($param->isArray()) {
         $userValue = $this->stockArrayJson($param, $userValue);
     } elseif ($param->isObject()) {
         $userValue = $this->stockObjectJson($param, $this->serializeObjectValue($userValue));
     }
     // Populate the final value
     return $this->stockValue($param, $userValue, $json);
 }
 /**
  * A generic method that will populate a JSON structure with a value according to a schema. It
  * supports multiple types and will delegate accordingly.
  *
  * @param mixed     $userValue The user value that is populating a JSON field
  * @param Parameter $param     The schema that defines how the JSON field is being populated
  * @param array     $json      The existing JSON structure that will be populated
  *
  * @return array
  */
 private function stockJson($userValue, Parameter $param, $json)
 {
     if ($param->isArray()) {
         $userValue = $this->stockArrayJson($userValue, $param);
     } elseif ($param->isObject()) {
         $userValue = $this->stockObjectJson($userValue, $param);
     }
     // Populate the final value
     return $this->stockValue($userValue, $param, $json);
 }
 private static function parseHeader(Parameter $param, $name, $value)
 {
     if ($name == 'metadata' || $name == 'removeMetadata') {
         $headers = [];
         foreach ($value as $key => $keyVal) {
             $schema = $param->getItemSchema() ?: new Parameter(['prefix' => $param->getPrefix(), 'name' => $key]);
             $headers += self::parseHeader($schema, $key, $keyVal);
         }
         return $headers;
     }
     return is_string($value) || is_numeric($value) ? [$param->getPrefix() . $param->getName() => $value] : [];
 }
Beispiel #5
0
 /**
  * Retrieves the child parameter for an object parameter.
  *
  * @param string $name The name of the child property
  *
  * @return null|Parameter
  */
 public function getProperty(string $name)
 {
     if ($this->properties instanceof Parameter) {
         $this->properties->setName($name);
         return $this->properties;
     }
     return isset($this->properties[$name]) ? $this->properties[$name] : null;
 }
Beispiel #6
0
 public function test_it_passes_validation_when_all_subproperties_pass()
 {
     $params = ['type' => 'object', 'properties' => ['foo' => ['type' => 'string']]];
     $userVals = ['foo' => 'baz'];
     $param = new Parameter($params);
     $this->assertTrue($param->validate($userVals));
 }
 /**
  * @expectedException \Exception
  */
 public function test_exception_is_thrown_when_value_is_not_in_enum_list()
 {
     $data = $this->data;
     $data['enum'] = ['foo'];
     $param = new Parameter($data);
     $param->validate('blah');
 }