当前位置: 首页>>代码示例>>PHP>>正文


PHP Collection::inject方法代码示例

本文整理汇总了PHP中Guzzle\Common\Collection::inject方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::inject方法的具体用法?PHP Collection::inject怎么用?PHP Collection::inject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Guzzle\Common\Collection的用法示例。


在下文中一共展示了Collection::inject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate

 /**
  * {@inheritdoc}
  * @throws ValidationException when validation errors occur
  */
 public function validate(Collection $config, Inspector $inspector = null)
 {
     $inspector = $inspector ?: Inspector::getInstance();
     $typeValidation = $inspector->getTypeValidation();
     $errors = array();
     foreach ($this->params as $name => $arg) {
         $currentValue = $config->get($name);
         $configValue = $arg->getValue($currentValue);
         // Inject configuration information into the config value
         if ($configValue && is_string($configValue)) {
             $configValue = $config->inject($configValue);
         }
         // Ensure that required arguments are set
         if ($arg->getRequired() && ($configValue === null || $configValue === '')) {
             $errors[] = 'Requires that the ' . $name . ' argument be supplied.' . ($arg->getDoc() ? '  (' . $arg->getDoc() . ').' : '');
             continue;
         }
         // Ensure that the correct data type is being used
         if ($typeValidation && $configValue !== null && ($argType = $arg->getType())) {
             $validation = $inspector->validateConstraint($argType, $configValue, $arg->getTypeArgs());
             if ($validation !== true) {
                 $errors[] = $name . ': ' . $validation;
                 $config->set($name, $configValue);
                 continue;
             }
         }
         $configValue = $arg->filter($configValue);
         // Update the config value if it changed
         if (!$configValue !== $currentValue) {
             $config->set($name, $configValue);
         }
         // Check the length values if validating data
         $argMinLength = $arg->getMinLength();
         if ($argMinLength && strlen($configValue) < $argMinLength) {
             $errors[] = 'Requires that the ' . $name . ' argument be >= ' . $arg->getMinLength() . ' characters.';
         }
         $argMaxLength = $arg->getMaxLength();
         if ($argMaxLength && strlen($configValue) > $argMaxLength) {
             $errors[] = 'Requires that the ' . $name . ' argument be <= ' . $arg->getMaxLength() . ' characters.';
         }
     }
     if (!empty($errors)) {
         $e = new ValidationException('Validation errors: ' . implode("\n", $errors));
         $e->setErrors($errors);
         throw $e;
     }
 }
开发者ID:jsnshrmn,项目名称:Suma,代码行数:51,代码来源:ApiCommand.php

示例2: testInjectsConfigData

 /**
  * @dataProvider dataProvider
  */
 public function testInjectsConfigData($output, $input, $config)
 {
     $collection = new Collection($config);
     $this->assertEquals($output, $collection->inject($input));
 }
开发者ID:alvarobfdev,项目名称:applog,代码行数:8,代码来源:CollectionTest.php

示例3: validateConfig

 /**
  * Validates that all required args are included in a config object,
  * and if not, throws an InvalidArgumentException with a helpful error message.  Adds
  * default args to the passed config object if the parameter was not
  * set in the config object.
  *
  * @param array      $params   Params to validate
  * @param Collection $config   Configuration settings
  * @param bool       $strict   Set to FALSE to allow missing required fields
  * @param bool       $validate Set to TRUE or FALSE to validate data.
  *                             Set to false when you only need to add
  *                             default values and statics.
  *
  * @return array|bool Returns an array of errors or TRUE on success
  *
  * @throws InvalidArgumentException if any args are missing and $strict is TRUE
  */
 public function validateConfig(array $params, Collection $config, $strict = true, $validate = true)
 {
     $errors = array();
     foreach ($params as $name => $arg) {
         // Set the default or static value if it is not set
         $configValue = $arg->getValue($config->get($name));
         // Inject configuration information into the config value
         if ($configValue && is_string($configValue)) {
             $configValue = $config->inject($configValue);
         }
         // Ensure that required arguments are set
         if ($validate && $arg->getRequired() && ($configValue === null || $configValue === '')) {
             $errors[] = 'Requires that the ' . $name . ' argument be supplied.' . ($arg->getDoc() ? '  (' . $arg->getDoc() . ').' : '');
             continue;
         }
         // Ensure that the correct data type is being used
         if ($validate && $this->typeValidation && $configValue !== null && ($argType = $arg->getType())) {
             $validation = $this->validateConstraint($argType, $configValue);
             if ($validation !== true) {
                 $errors[] = $name . ': ' . $validation;
                 continue;
             }
         }
         // Run the value through attached filters
         $configValue = $arg->filter($configValue);
         $config->set($name, $configValue);
         // Check the length values if validating data
         if ($validate) {
             $argMinLength = $arg->getMinLength();
             if ($argMinLength && strlen($configValue) < $argMinLength) {
                 $errors[] = 'Requires that the ' . $name . ' argument be >= ' . $arg->getMinLength() . ' characters.';
             }
             $argMaxLength = $arg->getMaxLength();
             if ($argMaxLength && strlen($configValue) > $argMaxLength) {
                 $errors[] = 'Requires that the ' . $name . ' argument be <= ' . $arg->getMaxLength() . ' characters.';
             }
         }
     }
     if (empty($errors)) {
         return true;
     } elseif ($strict) {
         throw new ValidationException('Validation errors: ' . implode("\n", $errors));
     }
     return $errors;
 }
开发者ID:norv,项目名称:guzzle,代码行数:62,代码来源:Inspector.php


注:本文中的Guzzle\Common\Collection::inject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。