本文整理汇总了PHP中Guzzle\Service\Description\Parameter类的典型用法代码示例。如果您正苦于以下问题:PHP Parameter类的具体用法?PHP Parameter怎么用?PHP Parameter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Parameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: recursiveProcess
/**
* Recursively process a parameter while applying filters
*
* @param Parameter $param API parameter being validated
* @param mixed $value Value to validate and process. The value may change during this process.
*/
protected function recursiveProcess(Parameter $param, &$value)
{
if ($value === null) {
return;
}
if (is_array($value)) {
$type = $param->getType();
if ($type == 'array') {
foreach ($value as &$item) {
$this->recursiveProcess($param->getItems(), $item);
}
} elseif ($type == 'object' && !isset($value[0])) {
// On the above line, we ensure that the array is associative and not numerically indexed
if ($properties = $param->getProperties()) {
foreach ($properties as $property) {
$name = $property->getName();
$key = $property->getWireName();
if (isset($value[$key])) {
$this->recursiveProcess($property, $value[$key]);
if ($key != $name) {
$value[$name] = $value[$key];
unset($value[$key]);
}
}
}
}
}
}
$value = $param->filter($value);
}
示例2: visit
/**
* {@inheritdoc}
*/
public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
{
if ($value instanceof PostFileInterface) {
$request->addPostFile($value);
} else {
$request->addPostFile($param->getWireName(), $value);
}
}
示例3: visit
public function visit(
CommandInterface $command,
Response $response,
Parameter $param,
&$value,
$context = null
) {
$value[$param->getName()] = $param->filter($response->getBody());
}
示例4: tagsOrAliases
/**
* Validates an array of tags or aliases (just strings)
*
* @param array $aliases
* @param Parameter $parameter
*
* @return array
* @throws \Guzzle\Service\Exception\ValidationException
*/
public static function tagsOrAliases(array $aliases, Parameter $parameter)
{
foreach ($aliases as $alias) {
if (!is_string($alias) || strlen($alias) > 128) {
throw new ValidationException("Invalid value [{$alias}] in {$parameter->getName()}");
}
}
return $aliases;
}
示例5: visit
public function visit(
CommandInterface $command,
Response $response,
Parameter $param,
&$value,
$context = null
) {
$value[$param->getName()] = $response->getStatusCode();
}
示例6: validateLinkStructure
/**
* Validates the structure of a link (from the service description)
*
* @param \Guzzle\Service\Description\Parameter $structure
*
* @throws \Desk\Exception\UnexpectedValueException If it's invalid
*/
public function validateLinkStructure(Parameter $structure)
{
if (!$structure->getData('operation')) {
throw new UnexpectedValueException("Parameter with 'links' location requires 'operation'");
}
if (!$structure->getData('pattern')) {
throw new UnexpectedValueException("Parameter with 'links' location requires 'pattern'");
}
}
示例7: visit
/**
* {@inheritdoc}
*/
public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
{
$entityBody = EntityBody::factory($value);
$request->setBody($entityBody);
$this->addExpectHeader($request, $entityBody, $param->getData('expect_header'));
// Add the Content-Encoding header if one is set on the EntityBody
if ($encoding = $entityBody->getContentEncoding()) {
$request->setHeader('Content-Encoding', $encoding);
}
}
示例8: visit
public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
{
if (isset($this->data[$command])) {
$json = $this->data[$command];
} else {
$json = array();
}
$json[$param->getWireName()] = $this->prepareValue($value, $param);
$this->data[$command] = $json;
}
示例9: addPrefixedHeaders
/**
* Add a prefixed array of headers to the request
*
* @param RequestInterface $request Request to update
* @param Parameter $param Parameter object
* @param array $value Header array to add
*
* @throws InvalidArgumentException
*/
protected function addPrefixedHeaders(RequestInterface $request, Parameter $param, $value)
{
if (!is_array($value)) {
throw new InvalidArgumentException('An array of mapped headers expected, but received a single value');
}
$prefix = $param->getSentAs();
foreach ($value as $headerName => $headerValue) {
$request->setHeader($prefix . $headerName, $headerValue);
}
}
示例10: process
/**
* Processes model data according to a parameter schema
*
* @param Desk\Relationship\Resource\EmbeddedCommand $command
* @param Guzzle\Service\Description\Parameter $schema
* @param array $data
*
* @return array
*/
public function process(EmbeddedCommand $command, Parameter $schema, array $data)
{
$result = array();
$visitors = array();
$properties = $schema->getProperties();
foreach ($properties as $property) {
$location = $property->getLocation();
if ($location && !isset($visitors[$location])) {
// add visitor for this location and trigger before()
$visitor = $this->visitors->getResponseVisitor($location);
$visitor->before($command, $result);
$visitors[$location] = $visitor;
}
}
$response = $command->getResponse();
// Visit additional properties when it is an actual schema
$additional = $schema->getAdditionalProperties();
if ($additional instanceof Parameter) {
// Only visit when a location is specified
$location = $additional->getLocation();
if ($location) {
if (!isset($visitors[$location])) {
$visitors[$location] = $this->visitors->getResponseVisitor($location);
$visitors[$location]->before($command, $result);
}
// Only traverse if an array was parsed from the before() visitors
if (is_array($result)) {
// Find each additional property
foreach (array_keys($result) as $key) {
// Check if the model actually knows this property. If so, then it is not additional
if (!$schema->getProperty($key)) {
// Set the name to the key so that we can parse it with each visitor
$additional->setName($key);
$visitors[$location]->visit($command, $response, $additional, $result);
}
}
// Reset the additionalProperties name to null
$additional->setName(null);
}
}
}
// Apply the parameter value with the location visitor
foreach ($properties as $property) {
$location = $property->getLocation();
if ($location) {
$visitors[$location]->visit($command, $response, $property, $result);
}
}
// Call the after() method of each found visitor
foreach ($visitors as $visitor) {
$visitor->after($command);
}
return $result;
}
示例11: visit
/**
* {@inheritdoc}
*/
public function visit(CommandInterface $command, Response $response, Parameter $param, &$value, $context = null)
{
// check if there's a link provided for the param's "wire" name
$links = $this->get($command, 'links');
if (!empty($links[$param->getWireName()])) {
// create a command representing the link
$linkCommand = $this->builder->createLinkCommand($command, $param, $links[$param->getWireName()]);
// store the created link command in the results array
$value[self::ELEMENT][$param->getName()] = $linkCommand;
}
}
示例12: processXmlAttribute
protected function processXmlAttribute(Parameter $property, array &$value)
{
$sentAs = $property->getWireName();
if (isset($value['@attributes'][$sentAs])) {
$value[$property->getName()] = $value['@attributes'][$sentAs];
unset($value['@attributes'][$sentAs]);
if (empty($value['@attributes'])) {
unset($value['@attributes']);
}
}
}
示例13: visit
/**
* {@inheritdoc}
*/
public function visit(CommandInterface $command, Response $response, Parameter $param, &$value, $context = null)
{
// check if there's embedded resource data for the parameter
$resourceData = $this->get($command, $this->getFieldName());
if (!empty($resourceData[$param->getWireName()])) {
// create the resource representing the embedded resource data
$resource = $this->createResourceFromData($command, $param, $resourceData[$param->getWireName()]);
// store the created embedded resource in the results array
$value[$this->getOutputFieldName()][$param->getName()] = $resource;
}
}
示例14: processPrefixedHeaders
protected function processPrefixedHeaders(Response $response, Parameter $param, &$value)
{
if ($prefix = $param->getSentAs()) {
$container = $param->getName();
$len = strlen($prefix);
foreach ($response->getHeaders()->toArray() as $key => $header) {
if (stripos($key, $prefix) === 0) {
$value[$container][substr($key, $len)] = count($header) == 1 ? end($header) : $header;
}
}
}
}
示例15: resolveArray
/**
* Custom handling for arrays
*
* @param Parameter $param Parameter for the object
* @param array $value Value that is set for this parameter
* @param string $prefix Prefix for the resulting key
* @param array $query Query string array passed by reference
*/
protected function resolveArray(Parameter $param, array $value, $prefix, array &$query)
{
$offset = $param->getData('offset') ?: 1;
foreach ($value as $index => $v) {
$index += $offset;
if (is_array($v) && ($items = $param->getItems())) {
$this->customResolver($v, $items, $query, $prefix . '.' . $index);
} else {
$query[$prefix . '.' . $index] = $param->filter($v);
}
}
}