Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Message.php

function Message::initWithGeneratedPool

@ignore

1 call to Message::initWithGeneratedPool()
Message::__construct in vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php
@ignore

File

vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php, line 69

Class

Message
Parent class of all proto messages. Users should not instantiate this class or extend this class or its child classes by their own. See the comment of specific functions for more details.

Namespace

Google\Protobuf\Internal

Code

private function initWithGeneratedPool() {
    $pool = DescriptorPool::getGeneratedPool();
    $this->desc = $pool->getDescriptorByClassName(get_class($this));
    if (is_null($this->desc)) {
        throw new \InvalidArgumentException(get_class($this) . " is not found in descriptor pool. " . 'Only generated classes may derive from Message.');
    }
    foreach ($this->desc
        ->getField() as $field) {
        $setter = $field->getSetter();
        if ($field->isMap()) {
            $message_type = $field->getMessageType();
            $key_field = $message_type->getFieldByNumber(1);
            $value_field = $message_type->getFieldByNumber(2);
            switch ($value_field->getType()) {
                case GPBType::MESSAGE:
                case GPBType::GROUP:
                    $map_field = new MapField($key_field->getType(), $value_field->getType(), $value_field->getMessageType()
                        ->getClass());
                    $this->{$setter}($map_field);
                    break;
                case GPBType::ENUM:
                    $map_field = new MapField($key_field->getType(), $value_field->getType(), $value_field->getEnumType()
                        ->getClass());
                    $this->{$setter}($map_field);
                    break;
                default:
                    $map_field = new MapField($key_field->getType(), $value_field->getType());
                    $this->{$setter}($map_field);
                    break;
            }
        }
        else {
            if ($field->getLabel() === GPBLabel::REPEATED) {
                switch ($field->getType()) {
                    case GPBType::MESSAGE:
                    case GPBType::GROUP:
                        $repeated_field = new RepeatedField($field->getType(), $field->getMessageType()
                            ->getClass());
                        $this->{$setter}($repeated_field);
                        break;
                    case GPBType::ENUM:
                        $repeated_field = new RepeatedField($field->getType(), $field->getEnumType()
                            ->getClass());
                        $this->{$setter}($repeated_field);
                        break;
                    default:
                        $repeated_field = new RepeatedField($field->getType());
                        $this->{$setter}($repeated_field);
                        break;
                }
            }
            else {
                if ($field->getOneofIndex() !== -1) {
                    $oneof = $this->desc
                        ->getOneofDecl()[$field->getOneofIndex()];
                    $oneof_name = $oneof->getName();
                    $this->{$oneof_name} = new OneofField($oneof);
                }
                else {
                    if ($field->getLabel() === GPBLabel::OPTIONAL && PHP_INT_SIZE == 4) {
                        switch ($field->getType()) {
                            case GPBType::INT64:
                            case GPBType::UINT64:
                            case GPBType::FIXED64:
                            case GPBType::SFIXED64:
                            case GPBType::SINT64:
                                $this->{$setter}("0");
                        }
                    }
                }
            }
        }
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal