當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。