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


PHP Parameter::getMinItems方法代码示例

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


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

示例1: recursiveProcess


//.........这里部分代码省略.........
foreach ($diff as $key) {
$this->recursiveProcess($additional, $value[$key], "{$path}[{$key}]", $depth);
}
} else {

 $keys = array_keys($value);
$this->errors[] = sprintf('%s[%s] is not an allowed property', $path, reset($keys));
}
}
}


 
 
 if ($temporaryValue && empty($value)) {
$value = null;
$valueIsArray = false;
}
}

} elseif ($type == 'array' && $valueIsArray && $param->getItems()) {
foreach ($value as $i => &$item) {

 $this->recursiveProcess($param->getItems(), $item, $path . "[{$i}]", $depth + 1);
}
}


 if ($required && $value === null && $type != 'null') {
$message = "{$path} is " . ($param->getType() ? ('a required ' . implode(' or ', (array) $param->getType())) : 'required');
if ($param->getDescription()) {
$message .= ': ' . $param->getDescription();
}
$this->errors[] = $message;
return false;
}


 
 if ($type && (!$type = $this->determineType($type, $value))) {
if ($this->castIntegerToStringType && $param->getType() == 'string' && is_integer($value)) {
$value = (string) $value;
} else {
$this->errors[] = "{$path} must be of type " . implode(' or ', (array) $param->getType());
}
}


 if ($type == 'string') {


 if (($enum = $param->getEnum()) && !in_array($value, $enum)) {
$this->errors[] = "{$path} must be one of " . implode(' or ', array_map(function ($s) {
return '"' . addslashes($s) . '"';
}, $enum));
}

 if (($pattern = $param->getPattern()) && !preg_match($pattern, $value)) {
$this->errors[] = "{$path} must match the following regular expression: {$pattern}";
}

$strLen = null;
if ($min = $param->getMinLength()) {
$strLen = strlen($value);
if ($strLen < $min) {
$this->errors[] = "{$path} length must be greater than or equal to {$min}";
}
}
if ($max = $param->getMaxLength()) {
if (($strLen ?: strlen($value)) > $max) {
$this->errors[] = "{$path} length must be less than or equal to {$max}";
}
}

} elseif ($type == 'array') {

$size = null;
if ($min = $param->getMinItems()) {
$size = count($value);
if ($size < $min) {
$this->errors[] = "{$path} must contain {$min} or more elements";
}
}
if ($max = $param->getMaxItems()) {
if (($size ?: count($value)) > $max) {
$this->errors[] = "{$path} must contain {$max} or fewer elements";
}
}

} elseif ($type == 'integer' || $type == 'number' || $type == 'numeric') {
if (($min = $param->getMinimum()) && $value < $min) {
$this->errors[] = "{$path} must be greater than or equal to {$min}";
}
if (($max = $param->getMaximum()) && $value > $max) {
$this->errors[] = "{$path} must be less than or equal to {$max}";
}
}

return empty($this->errors);
}
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:101,代码来源:SchemaValidator.php

示例2: recursiveProcess


//.........这里部分代码省略.........
             }
             $additional = $param->getAdditionalProperties();
             if ($additional !== true) {
                 // If additional properties were found, then validate each against the additionalProperties attr.
                 $keys = array_keys($value);
                 // Determine the keys that were specified that were not listed in the properties of the schema
                 $diff = array_diff($keys, array_keys($properties));
                 if (!empty($diff)) {
                     // Determine which keys are not in the properties
                     if ($additional instanceof Parameter) {
                         foreach ($diff as $key) {
                             $this->recursiveProcess($additional, $value[$key], "{$path}[{$key}]", $depth);
                         }
                     } else {
                         // if additionalProperties is set to false and there are additionalProperties in the values, then fail
                         foreach ($diff as $prop) {
                             $this->errors[] = sprintf('%s[%s] is not an allowed property', $path, $prop);
                         }
                     }
                 }
             }
             // A temporary value will be used to traverse elements that have no corresponding input value.
             // This allows nested required parameters with default values to bubble up into the input.
             // Here we check if we used a temp value and nothing bubbled up, then we need to remote the value.
             if ($temporaryValue && empty($value)) {
                 $value = null;
                 $valueIsArray = false;
             }
         }
     } elseif ($type == 'array' && $valueIsArray && $param->getItems()) {
         foreach ($value as $i => &$item) {
             // Validate each item in an array against the items attribute of the schema
             $this->recursiveProcess($param->getItems(), $item, $path . "[{$i}]", $depth + 1);
         }
     }
     // If the value is required and the type is not null, then there is an error if the value is not set
     if ($required && $value === null && $type != 'null') {
         $message = "{$path} is " . ($param->getType() ? 'a required ' . implode(' or ', (array) $param->getType()) : 'required');
         if ($param->getDescription()) {
             $message .= ': ' . $param->getDescription();
         }
         $this->errors[] = $message;
         return false;
     }
     // Validate that the type is correct. If the type is string but an integer was passed, the class can be
     // instructed to cast the integer to a string to pass validation. This is the default behavior.
     if ($type && !($type = $this->determineType($type, $value))) {
         if ($this->castIntegerToStringType && $param->getType() == 'string' && is_integer($value)) {
             $value = (string) $value;
         } else {
             $this->errors[] = "{$path} must be of type " . implode(' or ', (array) $param->getType());
         }
     }
     // Perform type specific validation for strings, arrays, and integers
     if ($type == 'string') {
         // Strings can have enums which are a list of predefined values
         if (($enum = $param->getEnum()) && !in_array($value, $enum)) {
             $this->errors[] = "{$path} must be one of " . implode(' or ', array_map(function ($s) {
                 return '"' . addslashes($s) . '"';
             }, $enum));
         }
         // Strings can have a regex pattern that the value must match
         if (($pattern = $param->getPattern()) && !preg_match($pattern, $value)) {
             $this->errors[] = "{$path} must match the following regular expression: {$pattern}";
         }
         $strLen = null;
         if ($min = $param->getMinLength()) {
             $strLen = strlen($value);
             if ($strLen < $min) {
                 $this->errors[] = "{$path} length must be greater than or equal to {$min}";
             }
         }
         if ($max = $param->getMaxLength()) {
             if (($strLen ?: strlen($value)) > $max) {
                 $this->errors[] = "{$path} length must be less than or equal to {$max}";
             }
         }
     } elseif ($type == 'array') {
         $size = null;
         if ($min = $param->getMinItems()) {
             $size = count($value);
             if ($size < $min) {
                 $this->errors[] = "{$path} must contain {$min} or more elements";
             }
         }
         if ($max = $param->getMaxItems()) {
             if (($size ?: count($value)) > $max) {
                 $this->errors[] = "{$path} must contain {$max} or fewer elements";
             }
         }
     } elseif ($type == 'integer' || $type == 'number' || $type == 'numeric') {
         if (($min = $param->getMinimum()) && $value < $min) {
             $this->errors[] = "{$path} must be greater than or equal to {$min}";
         }
         if (($max = $param->getMaximum()) && $value > $max) {
             $this->errors[] = "{$path} must be less than or equal to {$max}";
         }
     }
     return empty($this->errors);
 }
开发者ID:nstanard,项目名称:webpagetest,代码行数:101,代码来源:SchemaValidator.php

示例3: testCanBuildUpParams

 public function testCanBuildUpParams()
 {
     $p = new Parameter(array());
     $p->setName('foo')->setDescription('c')->setFilters(array('d'))->setLocation('e')->setSentAs('f')->setMaxLength(1)->setMinLength(1)->setMinimum(2)->setMaximum(2)->setMinItems(3)->setMaxItems(3)->setRequired(true)->setStatic(true)->setDefault('h')->setType('i');
     $p->addFilter('foo');
     $this->assertEquals('foo', $p->getName());
     $this->assertEquals('h', $p->getDefault());
     $this->assertEquals('c', $p->getDescription());
     $this->assertEquals(array('d', 'foo'), $p->getFilters());
     $this->assertEquals('e', $p->getLocation());
     $this->assertEquals('f', $p->getSentAs());
     $this->assertEquals(1, $p->getMaxLength());
     $this->assertEquals(1, $p->getMinLength());
     $this->assertEquals(2, $p->getMaximum());
     $this->assertEquals(2, $p->getMinimum());
     $this->assertEquals(3, $p->getMaxItems());
     $this->assertEquals(3, $p->getMinItems());
     $this->assertEquals(true, $p->getRequired());
     $this->assertEquals(true, $p->getStatic());
     $this->assertEquals('i', $p->getType());
 }
开发者ID:Frinstio,项目名称:AlfredWorkflow.com,代码行数:21,代码来源:ParameterTest.php


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