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


PHP Label::LABEL_REQUIRED方法代码示例

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


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

示例1: generateRequiredFieldException

 /**
  * @param \Protobuf\Compiler\Entity             $entity
  * @param \google\protobuf\FieldDescriptorProto $field
  *
  * @return string[]
  */
 protected function generateRequiredFieldException(Entity $entity, FieldDescriptorProto $field)
 {
     $name = $field->getName();
     $label = $field->getLabel();
     $tag = $field->getNumber();
     $isRequired = $label === Label::LABEL_REQUIRED();
     if (!$isRequired) {
         return [];
     }
     $class = $entity->getNamespacedName();
     $format = 'Field "%s#%s" (tag %s) is required but has no value.';
     $message = var_export(sprintf($format, $class, $name, $tag), true);
     $body[] = 'if ($this->' . $name . ' === null) {';
     $body[] = '    throw new \\UnexpectedValueException(' . $message . ');';
     $body[] = '}';
     $body[] = null;
     return $body;
 }
开发者ID:protobuf-php,项目名称:protobuf-plugin,代码行数:24,代码来源:WriteToGenerator.php

示例2: descriptor

 /**
  * {@inheritdoc}
  */
 public static function descriptor()
 {
     return \google\protobuf\DescriptorProto::fromArray(['name' => 'NamePart', 'field' => [\google\protobuf\FieldDescriptorProto::fromArray(['number' => 1, 'name' => 'name_part', 'type' => \google\protobuf\FieldDescriptorProto\Type::TYPE_STRING(), 'label' => \google\protobuf\FieldDescriptorProto\Label::LABEL_REQUIRED()]), \google\protobuf\FieldDescriptorProto::fromArray(['number' => 2, 'name' => 'is_extension', 'type' => \google\protobuf\FieldDescriptorProto\Type::TYPE_BOOL(), 'label' => \google\protobuf\FieldDescriptorProto\Label::LABEL_REQUIRED()])]]);
 }
开发者ID:protobuf-php,项目名称:google-protobuf-proto,代码行数:7,代码来源:NamePart.php

示例3: generateDefaultValues

 /**
  * @param \Protobuf\Compiler\Entity $entity
  *
  * @return array
  */
 protected function generateDefaultValues(Entity $entity)
 {
     $descriptor = $entity->getDescriptor();
     $fields = $descriptor->getFieldList() ?: [];
     $size = count($fields);
     $lines = [];
     foreach ($fields as $i => $field) {
         $name = $field->getName();
         $comma = $i + 1 < $size ? ',' : '';
         $value = $this->getDefaultFieldValue($field);
         // required field throw InvalidArgumentException
         if ($field->getLabel() === Label::LABEL_REQUIRED()) {
             continue;
         }
         if ($field->getLabel() === Label::LABEL_REPEATED()) {
             $value = '[]';
         }
         $lines[] = "'{$name}' => {$value}" . $comma;
     }
     return $lines;
 }
开发者ID:protobuf-php,项目名称:protobuf-plugin,代码行数:26,代码来源:FromArrayGenerator.php

示例4: generateSetterMethod

 /**
  * @param \Protobuf\Compiler\Entity            $entity
  * @param google\protobuf\FieldDescriptorProto $field
  *
  * @return \Zend\Code\Generator\GeneratorInterface
  */
 protected function generateSetterMethod(Entity $entity, FieldDescriptorProto $field)
 {
     $body = [];
     $fieldName = $field->getName();
     $fieldType = $field->getType();
     $fieldLabel = $field->getLabel();
     $typeHint = $this->getTypeHint($field);
     if ($fieldType === Type::TYPE_BYTES() && $fieldLabel !== Label::LABEL_REPEATED()) {
         $body[] = 'if ($value !== null && ! $value instanceof \\Protobuf\\Stream) {';
         $body[] = '    $value = \\Protobuf\\Stream::wrap($value);';
         $body[] = '}';
         $body[] = null;
         $typeHint = null;
     }
     $body[] = '$this->' . $fieldName . ' = $value;';
     $methodName = $this->getAccessorName('set', $field);
     $method = MethodGenerator::fromArray(['name' => $methodName, 'body' => implode(PHP_EOL, $body), 'parameters' => [['name' => 'value', 'type' => $typeHint]], 'docblock' => ['shortDescription' => "Set '{$fieldName}' value", 'tags' => [['name' => 'param', 'description' => $this->getDocBlockType($field) . ' $value']]]]);
     $method->getDocblock()->setWordWrap(false);
     if ($fieldLabel !== Label::LABEL_REQUIRED()) {
         $method->getParameters()['value']->setDefaultValue(null);
     }
     return $method;
 }
开发者ID:protobuf-php,项目名称:protobuf-plugin,代码行数:29,代码来源:FieldsGenerator.php


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