1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | <?php namespace DrSlump\Protobuf; use DrSlump\Protobuf; class Field { public $number; public $name; public $type = Protobuf::TYPE_UNKNOWN; public $rule = Protobuf::RULE_OPTIONAL; public $reference; public $default; public $packed = false; public $extension = false; public function __construct(array $opts = array()) { if (!empty($opts)) { if (isset($opts['number'])) $this->number = (int)$opts['number']; if (isset($opts['name'])) $this->name = $opts['name']; if (isset($opts['type'])) $this->type = (int)$opts['type']; if (isset($opts['rule'])) $this->rule = (int)$opts['rule']; if (isset($opts['packed'])) $this->packed = (bool)$opts['packed']; if (isset($opts['reference'])) $this->reference = $opts['reference']; if (isset($opts['default'])) $this->default = $opts['default']; if (isset($opts['extension'])) $this->extension = (bool)$opts['extension']; } } public function getNumber() { return $this->number; } public function getType() { return $this->type; } public function getName() { return $this->name; } public function getReference() { return $this->reference; } public function getDefault() { return $this->default; } public function hasDefault() { return $this->default !== NULL; } public function isOptional() { return $this->rule === Protobuf::RULE_OPTIONAL; } public function isRequired() { return $this->rule === Protobuf::RULE_REQUIRED; } public function isRepeated() { return $this->rule === Protobuf::RULE_REPEATED; } public function isPacked() { return $this->packed; } public function isExtension() { return $this->extension; } } |