text
stringlengths 2
104M
| meta
dict |
---|---|
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
if (false) {
/**
* This class is deprecated. Use Google\Protobuf\Internal\DescriptorProto\ReservedRange instead.
* @deprecated
*/
class DescriptorProto_ReservedRange {}
}
class_exists(DescriptorProto\ReservedRange::class);
@trigger_error('Google\Protobuf\Internal\DescriptorProto_ReservedRange is deprecated and will be removed in the next major release. Use Google\Protobuf\Internal\DescriptorProto\ReservedRange instead', E_USER_DEPRECATED);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* The protocol compiler can output a FileDescriptorSet containing the .proto
* files it parses.
*
* Generated from protobuf message <code>google.protobuf.FileDescriptorSet</code>
*/
class FileDescriptorSet extends \Google\Protobuf\Internal\Message
{
/**
* Generated from protobuf field <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code>
*/
private $file;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type array<\Google\Protobuf\Internal\FileDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $file
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getFile()
{
return $this->file;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code>
* @param array<\Google\Protobuf\Internal\FileDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setFile($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FileDescriptorProto::class);
$this->file = $arr;
return $this;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
class GPBWireType
{
const VARINT = 0;
const FIXED64 = 1;
const LENGTH_DELIMITED = 2;
const START_GROUP = 3;
const END_GROUP = 4;
const FIXED32 = 5;
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Describes a complete .proto file.
*
* Generated from protobuf message <code>google.protobuf.FileDescriptorProto</code>
*/
class FileDescriptorProto extends \Google\Protobuf\Internal\Message
{
/**
* file name, relative to root of source tree
*
* Generated from protobuf field <code>optional string name = 1;</code>
*/
protected $name = null;
/**
* e.g. "foo", "foo.bar", etc.
*
* Generated from protobuf field <code>optional string package = 2;</code>
*/
protected $package = null;
/**
* Names of files imported by this file.
*
* Generated from protobuf field <code>repeated string dependency = 3;</code>
*/
private $dependency;
/**
* Indexes of the public imported files in the dependency list above.
*
* Generated from protobuf field <code>repeated int32 public_dependency = 10;</code>
*/
private $public_dependency;
/**
* Indexes of the weak imported files in the dependency list.
* For Google-internal migration only. Do not use.
*
* Generated from protobuf field <code>repeated int32 weak_dependency = 11;</code>
*/
private $weak_dependency;
/**
* All top-level definitions in this file.
*
* Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto message_type = 4;</code>
*/
private $message_type;
/**
* Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 5;</code>
*/
private $enum_type;
/**
* Generated from protobuf field <code>repeated .google.protobuf.ServiceDescriptorProto service = 6;</code>
*/
private $service;
/**
* Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto extension = 7;</code>
*/
private $extension;
/**
* Generated from protobuf field <code>optional .google.protobuf.FileOptions options = 8;</code>
*/
protected $options = null;
/**
* This field contains optional information about the original source code.
* You may safely remove this entire field without harming runtime
* functionality of the descriptors -- the information is needed only by
* development tools.
*
* Generated from protobuf field <code>optional .google.protobuf.SourceCodeInfo source_code_info = 9;</code>
*/
protected $source_code_info = null;
/**
* The syntax of the proto file.
* The supported values are "proto2" and "proto3".
*
* Generated from protobuf field <code>optional string syntax = 12;</code>
*/
protected $syntax = null;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type string $name
* file name, relative to root of source tree
* @type string $package
* e.g. "foo", "foo.bar", etc.
* @type array<string>|\Google\Protobuf\Internal\RepeatedField $dependency
* Names of files imported by this file.
* @type array<int>|\Google\Protobuf\Internal\RepeatedField $public_dependency
* Indexes of the public imported files in the dependency list above.
* @type array<int>|\Google\Protobuf\Internal\RepeatedField $weak_dependency
* Indexes of the weak imported files in the dependency list.
* For Google-internal migration only. Do not use.
* @type array<\Google\Protobuf\Internal\DescriptorProto>|\Google\Protobuf\Internal\RepeatedField $message_type
* All top-level definitions in this file.
* @type array<\Google\Protobuf\Internal\EnumDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $enum_type
* @type array<\Google\Protobuf\Internal\ServiceDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $service
* @type array<\Google\Protobuf\Internal\FieldDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $extension
* @type \Google\Protobuf\Internal\FileOptions $options
* @type \Google\Protobuf\Internal\SourceCodeInfo $source_code_info
* This field contains optional information about the original source code.
* You may safely remove this entire field without harming runtime
* functionality of the descriptors -- the information is needed only by
* development tools.
* @type string $syntax
* The syntax of the proto file.
* The supported values are "proto2" and "proto3".
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* file name, relative to root of source tree
*
* Generated from protobuf field <code>optional string name = 1;</code>
* @return string
*/
public function getName()
{
return isset($this->name) ? $this->name : '';
}
public function hasName()
{
return isset($this->name);
}
public function clearName()
{
unset($this->name);
}
/**
* file name, relative to root of source tree
*
* Generated from protobuf field <code>optional string name = 1;</code>
* @param string $var
* @return $this
*/
public function setName($var)
{
GPBUtil::checkString($var, True);
$this->name = $var;
return $this;
}
/**
* e.g. "foo", "foo.bar", etc.
*
* Generated from protobuf field <code>optional string package = 2;</code>
* @return string
*/
public function getPackage()
{
return isset($this->package) ? $this->package : '';
}
public function hasPackage()
{
return isset($this->package);
}
public function clearPackage()
{
unset($this->package);
}
/**
* e.g. "foo", "foo.bar", etc.
*
* Generated from protobuf field <code>optional string package = 2;</code>
* @param string $var
* @return $this
*/
public function setPackage($var)
{
GPBUtil::checkString($var, True);
$this->package = $var;
return $this;
}
/**
* Names of files imported by this file.
*
* Generated from protobuf field <code>repeated string dependency = 3;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getDependency()
{
return $this->dependency;
}
/**
* Names of files imported by this file.
*
* Generated from protobuf field <code>repeated string dependency = 3;</code>
* @param array<string>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setDependency($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING);
$this->dependency = $arr;
return $this;
}
/**
* Indexes of the public imported files in the dependency list above.
*
* Generated from protobuf field <code>repeated int32 public_dependency = 10;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getPublicDependency()
{
return $this->public_dependency;
}
/**
* Indexes of the public imported files in the dependency list above.
*
* Generated from protobuf field <code>repeated int32 public_dependency = 10;</code>
* @param array<int>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setPublicDependency($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
$this->public_dependency = $arr;
return $this;
}
/**
* Indexes of the weak imported files in the dependency list.
* For Google-internal migration only. Do not use.
*
* Generated from protobuf field <code>repeated int32 weak_dependency = 11;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getWeakDependency()
{
return $this->weak_dependency;
}
/**
* Indexes of the weak imported files in the dependency list.
* For Google-internal migration only. Do not use.
*
* Generated from protobuf field <code>repeated int32 weak_dependency = 11;</code>
* @param array<int>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setWeakDependency($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
$this->weak_dependency = $arr;
return $this;
}
/**
* All top-level definitions in this file.
*
* Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto message_type = 4;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getMessageType()
{
return $this->message_type;
}
/**
* All top-level definitions in this file.
*
* Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto message_type = 4;</code>
* @param array<\Google\Protobuf\Internal\DescriptorProto>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setMessageType($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto::class);
$this->message_type = $arr;
return $this;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 5;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getEnumType()
{
return $this->enum_type;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 5;</code>
* @param array<\Google\Protobuf\Internal\EnumDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setEnumType($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumDescriptorProto::class);
$this->enum_type = $arr;
return $this;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.ServiceDescriptorProto service = 6;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getService()
{
return $this->service;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.ServiceDescriptorProto service = 6;</code>
* @param array<\Google\Protobuf\Internal\ServiceDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setService($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\ServiceDescriptorProto::class);
$this->service = $arr;
return $this;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto extension = 7;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getExtension()
{
return $this->extension;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto extension = 7;</code>
* @param array<\Google\Protobuf\Internal\FieldDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setExtension($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class);
$this->extension = $arr;
return $this;
}
/**
* Generated from protobuf field <code>optional .google.protobuf.FileOptions options = 8;</code>
* @return \Google\Protobuf\Internal\FileOptions|null
*/
public function getOptions()
{
return $this->options;
}
public function hasOptions()
{
return isset($this->options);
}
public function clearOptions()
{
unset($this->options);
}
/**
* Generated from protobuf field <code>optional .google.protobuf.FileOptions options = 8;</code>
* @param \Google\Protobuf\Internal\FileOptions $var
* @return $this
*/
public function setOptions($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FileOptions::class);
$this->options = $var;
return $this;
}
/**
* This field contains optional information about the original source code.
* You may safely remove this entire field without harming runtime
* functionality of the descriptors -- the information is needed only by
* development tools.
*
* Generated from protobuf field <code>optional .google.protobuf.SourceCodeInfo source_code_info = 9;</code>
* @return \Google\Protobuf\Internal\SourceCodeInfo|null
*/
public function getSourceCodeInfo()
{
return $this->source_code_info;
}
public function hasSourceCodeInfo()
{
return isset($this->source_code_info);
}
public function clearSourceCodeInfo()
{
unset($this->source_code_info);
}
/**
* This field contains optional information about the original source code.
* You may safely remove this entire field without harming runtime
* functionality of the descriptors -- the information is needed only by
* development tools.
*
* Generated from protobuf field <code>optional .google.protobuf.SourceCodeInfo source_code_info = 9;</code>
* @param \Google\Protobuf\Internal\SourceCodeInfo $var
* @return $this
*/
public function setSourceCodeInfo($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\SourceCodeInfo::class);
$this->source_code_info = $var;
return $this;
}
/**
* The syntax of the proto file.
* The supported values are "proto2" and "proto3".
*
* Generated from protobuf field <code>optional string syntax = 12;</code>
* @return string
*/
public function getSyntax()
{
return isset($this->syntax) ? $this->syntax : '';
}
public function hasSyntax()
{
return isset($this->syntax);
}
public function clearSyntax()
{
unset($this->syntax);
}
/**
* The syntax of the proto file.
* The supported values are "proto2" and "proto3".
*
* Generated from protobuf field <code>optional string syntax = 12;</code>
* @param string $var
* @return $this
*/
public function setSyntax($var)
{
GPBUtil::checkString($var, True);
$this->syntax = $var;
return $this;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
if (false) {
/**
* This class is deprecated. Use Google\Protobuf\Internal\FieldOptions\JSType instead.
* @deprecated
*/
class FieldOptions_JSType {}
}
class_exists(FieldOptions\JSType::class);
@trigger_error('Google\Protobuf\Internal\FieldOptions_JSType is deprecated and will be removed in the next major release. Use Google\Protobuf\Internal\FieldOptions\JSType instead', E_USER_DEPRECATED);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
class FieldDescriptor
{
use HasPublicDescriptorTrait;
private $name;
private $json_name;
private $setter;
private $getter;
private $number;
private $label;
private $type;
private $message_type;
private $enum_type;
private $packed;
private $oneof_index = -1;
private $proto3_optional;
/** @var OneofDescriptor $containing_oneof */
private $containing_oneof;
public function __construct()
{
$this->public_desc = new \Google\Protobuf\FieldDescriptor($this);
}
public function setOneofIndex($index)
{
$this->oneof_index = $index;
}
public function getOneofIndex()
{
return $this->oneof_index;
}
public function setName($name)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
public function setJsonName($json_name)
{
$this->json_name = $json_name;
}
public function getJsonName()
{
return $this->json_name;
}
public function setSetter($setter)
{
$this->setter = $setter;
}
public function getSetter()
{
return $this->setter;
}
public function setGetter($getter)
{
$this->getter = $getter;
}
public function getGetter()
{
return $this->getter;
}
public function setNumber($number)
{
$this->number = $number;
}
public function getNumber()
{
return $this->number;
}
public function setLabel($label)
{
$this->label = $label;
}
public function getLabel()
{
return $this->label;
}
public function isRepeated()
{
return $this->label === GPBLabel::REPEATED;
}
public function setType($type)
{
$this->type = $type;
}
public function getType()
{
return $this->type;
}
public function setMessageType($message_type)
{
$this->message_type = $message_type;
}
public function getMessageType()
{
return $this->message_type;
}
public function setEnumType($enum_type)
{
$this->enum_type = $enum_type;
}
public function getEnumType()
{
return $this->enum_type;
}
public function setPacked($packed)
{
$this->packed = $packed;
}
public function getPacked()
{
return $this->packed;
}
public function getProto3Optional()
{
return $this->proto3_optional;
}
public function setProto3Optional($proto3_optional)
{
$this->proto3_optional = $proto3_optional;
}
public function getContainingOneof()
{
return $this->containing_oneof;
}
public function setContainingOneof($containing_oneof)
{
$this->containing_oneof = $containing_oneof;
}
public function getRealContainingOneof()
{
return !is_null($this->containing_oneof) && !$this->containing_oneof->isSynthetic()
? $this->containing_oneof : null;
}
public function isPackable()
{
return $this->isRepeated() && self::isTypePackable($this->type);
}
public function isMap()
{
return $this->getType() == GPBType::MESSAGE &&
!is_null($this->getMessageType()->getOptions()) &&
$this->getMessageType()->getOptions()->getMapEntry();
}
public function isTimestamp()
{
return $this->getType() == GPBType::MESSAGE &&
$this->getMessageType()->getClass() === "Google\Protobuf\Timestamp";
}
public function isWrapperType()
{
if ($this->getType() == GPBType::MESSAGE) {
$class = $this->getMessageType()->getClass();
return in_array($class, [
"Google\Protobuf\DoubleValue",
"Google\Protobuf\FloatValue",
"Google\Protobuf\Int64Value",
"Google\Protobuf\UInt64Value",
"Google\Protobuf\Int32Value",
"Google\Protobuf\UInt32Value",
"Google\Protobuf\BoolValue",
"Google\Protobuf\StringValue",
"Google\Protobuf\BytesValue",
]);
}
return false;
}
private static function isTypePackable($field_type)
{
return ($field_type !== GPBType::STRING &&
$field_type !== GPBType::GROUP &&
$field_type !== GPBType::MESSAGE &&
$field_type !== GPBType::BYTES);
}
/**
* @param FieldDescriptorProto $proto
* @return FieldDescriptor
*/
public static function getFieldDescriptor($proto)
{
$type_name = null;
$type = $proto->getType();
switch ($type) {
case GPBType::MESSAGE:
case GPBType::GROUP:
case GPBType::ENUM:
$type_name = $proto->getTypeName();
break;
default:
break;
}
$oneof_index = $proto->hasOneofIndex() ? $proto->getOneofIndex() : -1;
// TODO: once proto2 is supported, this default should be false
// for proto2.
if ($proto->getLabel() === GPBLabel::REPEATED &&
$proto->getType() !== GPBType::MESSAGE &&
$proto->getType() !== GPBType::GROUP &&
$proto->getType() !== GPBType::STRING &&
$proto->getType() !== GPBType::BYTES) {
$packed = true;
} else {
$packed = false;
}
$options = $proto->getOptions();
if ($options !== null) {
$packed = $options->getPacked();
}
$field = new FieldDescriptor();
$field->setName($proto->getName());
if ($proto->hasJsonName()) {
$json_name = $proto->getJsonName();
} else {
$proto_name = $proto->getName();
$json_name = implode('', array_map('ucwords', explode('_', $proto_name)));
if ($proto_name[0] !== "_" && !ctype_upper($proto_name[0])) {
$json_name = lcfirst($json_name);
}
}
$field->setJsonName($json_name);
$camel_name = implode('', array_map('ucwords', explode('_', $proto->getName())));
$field->setGetter('get' . $camel_name);
$field->setSetter('set' . $camel_name);
$field->setType($proto->getType());
$field->setNumber($proto->getNumber());
$field->setLabel($proto->getLabel());
$field->setPacked($packed);
$field->setOneofIndex($oneof_index);
$field->setProto3Optional($proto->getProto3Optional());
// At this time, the message/enum type may have not been added to pool.
// So we use the type name as place holder and will replace it with the
// actual descriptor in cross building.
switch ($type) {
case GPBType::MESSAGE:
$field->setMessageType($type_name);
break;
case GPBType::ENUM:
$field->setEnumType($type_name);
break;
default:
break;
}
return $field;
}
public static function buildFromProto($proto)
{
return FieldDescriptor::getFieldDescriptor($proto);
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBLabel;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\Descriptor;
use Google\Protobuf\Internal\FieldDescriptor;
class MessageBuilderContext
{
private $descriptor;
private $pool;
public function __construct($full_name, $klass, $pool)
{
$this->descriptor = new Descriptor();
$this->descriptor->setFullName($full_name);
$this->descriptor->setClass($klass);
$this->pool = $pool;
}
private function getFieldDescriptor($name, $label, $type,
$number, $type_name = null)
{
$field = new FieldDescriptor();
$field->setName($name);
$camel_name = implode('', array_map('ucwords', explode('_', $name)));
$field->setGetter('get' . $camel_name);
$field->setSetter('set' . $camel_name);
$field->setType($type);
$field->setNumber($number);
$field->setLabel($label);
// At this time, the message/enum type may have not been added to pool.
// So we use the type name as place holder and will replace it with the
// actual descriptor in cross building.
switch ($type) {
case GPBType::MESSAGE:
$field->setMessageType($type_name);
break;
case GPBType::ENUM:
$field->setEnumType($type_name);
break;
default:
break;
}
return $field;
}
public function optional($name, $type, $number, $type_name = null)
{
$this->descriptor->addField($this->getFieldDescriptor(
$name,
GPBLabel::OPTIONAL,
$type,
$number,
$type_name));
return $this;
}
public function repeated($name, $type, $number, $type_name = null)
{
$this->descriptor->addField($this->getFieldDescriptor(
$name,
GPBLabel::REPEATED,
$type,
$number,
$type_name));
return $this;
}
public function required($name, $type, $number, $type_name = null)
{
$this->descriptor->addField($this->getFieldDescriptor(
$name,
GPBLabel::REQUIRED,
$type,
$number,
$type_name));
return $this;
}
public function finalizeToPool()
{
$this->pool->addDescriptor($this->descriptor);
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
class GPBDecodeException extends \Exception
{
public function __construct(
$message,
$code = 0,
\Exception $previous = null)
{
parent::__construct(
"Error occurred during parsing: " . $message,
$code,
$previous);
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>google.protobuf.EnumOptions</code>
*/
class EnumOptions extends \Google\Protobuf\Internal\Message
{
/**
* Set this option to true to allow mapping different tag names to the same
* value.
*
* Generated from protobuf field <code>optional bool allow_alias = 2;</code>
*/
protected $allow_alias = null;
/**
* Is this enum deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum, or it will be completely ignored; in the very least, this
* is a formalization for deprecating enums.
*
* Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code>
*/
protected $deprecated = null;
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
*/
private $uninterpreted_option;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type bool $allow_alias
* Set this option to true to allow mapping different tag names to the same
* value.
* @type bool $deprecated
* Is this enum deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum, or it will be completely ignored; in the very least, this
* is a formalization for deprecating enums.
* @type array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $uninterpreted_option
* The parser stores options it doesn't recognize here. See above.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Set this option to true to allow mapping different tag names to the same
* value.
*
* Generated from protobuf field <code>optional bool allow_alias = 2;</code>
* @return bool
*/
public function getAllowAlias()
{
return isset($this->allow_alias) ? $this->allow_alias : false;
}
public function hasAllowAlias()
{
return isset($this->allow_alias);
}
public function clearAllowAlias()
{
unset($this->allow_alias);
}
/**
* Set this option to true to allow mapping different tag names to the same
* value.
*
* Generated from protobuf field <code>optional bool allow_alias = 2;</code>
* @param bool $var
* @return $this
*/
public function setAllowAlias($var)
{
GPBUtil::checkBool($var);
$this->allow_alias = $var;
return $this;
}
/**
* Is this enum deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum, or it will be completely ignored; in the very least, this
* is a formalization for deprecating enums.
*
* Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code>
* @return bool
*/
public function getDeprecated()
{
return isset($this->deprecated) ? $this->deprecated : false;
}
public function hasDeprecated()
{
return isset($this->deprecated);
}
public function clearDeprecated()
{
unset($this->deprecated);
}
/**
* Is this enum deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum, or it will be completely ignored; in the very least, this
* is a formalization for deprecating enums.
*
* Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code>
* @param bool $var
* @return $this
*/
public function setDeprecated($var)
{
GPBUtil::checkBool($var);
$this->deprecated = $var;
return $this;
}
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getUninterpretedOption()
{
return $this->uninterpreted_option;
}
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @param array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setUninterpretedOption($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $arr;
return $this;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>google.protobuf.MessageOptions</code>
*/
class MessageOptions extends \Google\Protobuf\Internal\Message
{
/**
* Set true to use the old proto1 MessageSet wire format for extensions.
* This is provided for backwards-compatibility with the MessageSet wire
* format. You should not use this for any other reason: It's less
* efficient, has fewer features, and is more complicated.
* The message must be defined exactly as follows:
* message Foo {
* option message_set_wire_format = true;
* extensions 4 to max;
* }
* Note that the message cannot have any defined fields; MessageSets only
* have extensions.
* All extensions of your type must be singular messages; e.g. they cannot
* be int32s, enums, or repeated messages.
* Because this is an option, the above two restrictions are not enforced by
* the protocol compiler.
*
* Generated from protobuf field <code>optional bool message_set_wire_format = 1 [default = false];</code>
*/
protected $message_set_wire_format = null;
/**
* Disables the generation of the standard "descriptor()" accessor, which can
* conflict with a field of the same name. This is meant to make migration
* from proto1 easier; new code should avoid fields named "descriptor".
*
* Generated from protobuf field <code>optional bool no_standard_descriptor_accessor = 2 [default = false];</code>
*/
protected $no_standard_descriptor_accessor = null;
/**
* Is this message deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the message, or it will be completely ignored; in the very least,
* this is a formalization for deprecating messages.
*
* Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code>
*/
protected $deprecated = null;
/**
* Whether the message is an automatically generated map entry type for the
* maps field.
* For maps fields:
* map<KeyType, ValueType> map_field = 1;
* The parsed descriptor looks like:
* message MapFieldEntry {
* option map_entry = true;
* optional KeyType key = 1;
* optional ValueType value = 2;
* }
* repeated MapFieldEntry map_field = 1;
* Implementations may choose not to generate the map_entry=true message, but
* use a native map in the target language to hold the keys and values.
* The reflection APIs in such implementations still need to work as
* if the field is a repeated message field.
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
*
* Generated from protobuf field <code>optional bool map_entry = 7;</code>
*/
protected $map_entry = null;
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
*/
private $uninterpreted_option;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type bool $message_set_wire_format
* Set true to use the old proto1 MessageSet wire format for extensions.
* This is provided for backwards-compatibility with the MessageSet wire
* format. You should not use this for any other reason: It's less
* efficient, has fewer features, and is more complicated.
* The message must be defined exactly as follows:
* message Foo {
* option message_set_wire_format = true;
* extensions 4 to max;
* }
* Note that the message cannot have any defined fields; MessageSets only
* have extensions.
* All extensions of your type must be singular messages; e.g. they cannot
* be int32s, enums, or repeated messages.
* Because this is an option, the above two restrictions are not enforced by
* the protocol compiler.
* @type bool $no_standard_descriptor_accessor
* Disables the generation of the standard "descriptor()" accessor, which can
* conflict with a field of the same name. This is meant to make migration
* from proto1 easier; new code should avoid fields named "descriptor".
* @type bool $deprecated
* Is this message deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the message, or it will be completely ignored; in the very least,
* this is a formalization for deprecating messages.
* @type bool $map_entry
* Whether the message is an automatically generated map entry type for the
* maps field.
* For maps fields:
* map<KeyType, ValueType> map_field = 1;
* The parsed descriptor looks like:
* message MapFieldEntry {
* option map_entry = true;
* optional KeyType key = 1;
* optional ValueType value = 2;
* }
* repeated MapFieldEntry map_field = 1;
* Implementations may choose not to generate the map_entry=true message, but
* use a native map in the target language to hold the keys and values.
* The reflection APIs in such implementations still need to work as
* if the field is a repeated message field.
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
* @type array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $uninterpreted_option
* The parser stores options it doesn't recognize here. See above.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Set true to use the old proto1 MessageSet wire format for extensions.
* This is provided for backwards-compatibility with the MessageSet wire
* format. You should not use this for any other reason: It's less
* efficient, has fewer features, and is more complicated.
* The message must be defined exactly as follows:
* message Foo {
* option message_set_wire_format = true;
* extensions 4 to max;
* }
* Note that the message cannot have any defined fields; MessageSets only
* have extensions.
* All extensions of your type must be singular messages; e.g. they cannot
* be int32s, enums, or repeated messages.
* Because this is an option, the above two restrictions are not enforced by
* the protocol compiler.
*
* Generated from protobuf field <code>optional bool message_set_wire_format = 1 [default = false];</code>
* @return bool
*/
public function getMessageSetWireFormat()
{
return isset($this->message_set_wire_format) ? $this->message_set_wire_format : false;
}
public function hasMessageSetWireFormat()
{
return isset($this->message_set_wire_format);
}
public function clearMessageSetWireFormat()
{
unset($this->message_set_wire_format);
}
/**
* Set true to use the old proto1 MessageSet wire format for extensions.
* This is provided for backwards-compatibility with the MessageSet wire
* format. You should not use this for any other reason: It's less
* efficient, has fewer features, and is more complicated.
* The message must be defined exactly as follows:
* message Foo {
* option message_set_wire_format = true;
* extensions 4 to max;
* }
* Note that the message cannot have any defined fields; MessageSets only
* have extensions.
* All extensions of your type must be singular messages; e.g. they cannot
* be int32s, enums, or repeated messages.
* Because this is an option, the above two restrictions are not enforced by
* the protocol compiler.
*
* Generated from protobuf field <code>optional bool message_set_wire_format = 1 [default = false];</code>
* @param bool $var
* @return $this
*/
public function setMessageSetWireFormat($var)
{
GPBUtil::checkBool($var);
$this->message_set_wire_format = $var;
return $this;
}
/**
* Disables the generation of the standard "descriptor()" accessor, which can
* conflict with a field of the same name. This is meant to make migration
* from proto1 easier; new code should avoid fields named "descriptor".
*
* Generated from protobuf field <code>optional bool no_standard_descriptor_accessor = 2 [default = false];</code>
* @return bool
*/
public function getNoStandardDescriptorAccessor()
{
return isset($this->no_standard_descriptor_accessor) ? $this->no_standard_descriptor_accessor : false;
}
public function hasNoStandardDescriptorAccessor()
{
return isset($this->no_standard_descriptor_accessor);
}
public function clearNoStandardDescriptorAccessor()
{
unset($this->no_standard_descriptor_accessor);
}
/**
* Disables the generation of the standard "descriptor()" accessor, which can
* conflict with a field of the same name. This is meant to make migration
* from proto1 easier; new code should avoid fields named "descriptor".
*
* Generated from protobuf field <code>optional bool no_standard_descriptor_accessor = 2 [default = false];</code>
* @param bool $var
* @return $this
*/
public function setNoStandardDescriptorAccessor($var)
{
GPBUtil::checkBool($var);
$this->no_standard_descriptor_accessor = $var;
return $this;
}
/**
* Is this message deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the message, or it will be completely ignored; in the very least,
* this is a formalization for deprecating messages.
*
* Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code>
* @return bool
*/
public function getDeprecated()
{
return isset($this->deprecated) ? $this->deprecated : false;
}
public function hasDeprecated()
{
return isset($this->deprecated);
}
public function clearDeprecated()
{
unset($this->deprecated);
}
/**
* Is this message deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the message, or it will be completely ignored; in the very least,
* this is a formalization for deprecating messages.
*
* Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code>
* @param bool $var
* @return $this
*/
public function setDeprecated($var)
{
GPBUtil::checkBool($var);
$this->deprecated = $var;
return $this;
}
/**
* Whether the message is an automatically generated map entry type for the
* maps field.
* For maps fields:
* map<KeyType, ValueType> map_field = 1;
* The parsed descriptor looks like:
* message MapFieldEntry {
* option map_entry = true;
* optional KeyType key = 1;
* optional ValueType value = 2;
* }
* repeated MapFieldEntry map_field = 1;
* Implementations may choose not to generate the map_entry=true message, but
* use a native map in the target language to hold the keys and values.
* The reflection APIs in such implementations still need to work as
* if the field is a repeated message field.
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
*
* Generated from protobuf field <code>optional bool map_entry = 7;</code>
* @return bool
*/
public function getMapEntry()
{
return isset($this->map_entry) ? $this->map_entry : false;
}
public function hasMapEntry()
{
return isset($this->map_entry);
}
public function clearMapEntry()
{
unset($this->map_entry);
}
/**
* Whether the message is an automatically generated map entry type for the
* maps field.
* For maps fields:
* map<KeyType, ValueType> map_field = 1;
* The parsed descriptor looks like:
* message MapFieldEntry {
* option map_entry = true;
* optional KeyType key = 1;
* optional ValueType value = 2;
* }
* repeated MapFieldEntry map_field = 1;
* Implementations may choose not to generate the map_entry=true message, but
* use a native map in the target language to hold the keys and values.
* The reflection APIs in such implementations still need to work as
* if the field is a repeated message field.
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
*
* Generated from protobuf field <code>optional bool map_entry = 7;</code>
* @param bool $var
* @return $this
*/
public function setMapEntry($var)
{
GPBUtil::checkBool($var);
$this->map_entry = $var;
return $this;
}
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getUninterpretedOption()
{
return $this->uninterpreted_option;
}
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @param array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setUninterpretedOption($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $arr;
return $this;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
if (false) {
/**
* This class is deprecated. Use Google\Protobuf\Internal\MethodOptions\IdempotencyLevel instead.
* @deprecated
*/
class MethodOptions_IdempotencyLevel {}
}
class_exists(MethodOptions\IdempotencyLevel::class);
@trigger_error('Google\Protobuf\Internal\MethodOptions_IdempotencyLevel is deprecated and will be removed in the next major release. Use Google\Protobuf\Internal\MethodOptions\IdempotencyLevel instead', E_USER_DEPRECATED);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/**
* RepeatedField and RepeatedFieldIter are used by generated protocol message
* classes to manipulate repeated fields.
*/
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBUtil;
use Traversable;
/**
* RepeatedField is used by generated protocol message classes to manipulate
* repeated fields. It can be used like native PHP array.
*/
class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable
{
/**
* @ignore
*/
private $container;
/**
* @ignore
*/
private $type;
/**
* @ignore
*/
private $klass;
/**
* @ignore
*/
private $legacy_klass;
/**
* Constructs an instance of RepeatedField.
*
* @param integer $type Type of the stored element.
* @param string $klass Message/Enum class name (message/enum fields only).
* @ignore
*/
public function __construct($type, $klass = null)
{
$this->container = [];
$this->type = $type;
if ($this->type == GPBType::MESSAGE) {
$pool = DescriptorPool::getGeneratedPool();
$desc = $pool->getDescriptorByClassName($klass);
if ($desc == NULL) {
new $klass; // No msg class instance has been created before.
$desc = $pool->getDescriptorByClassName($klass);
}
$this->klass = $desc->getClass();
$this->legacy_klass = $desc->getLegacyClass();
}
}
/**
* @ignore
*/
public function getType()
{
return $this->type;
}
/**
* @ignore
*/
public function getClass()
{
return $this->klass;
}
/**
* @ignore
*/
public function getLegacyClass()
{
return $this->legacy_klass;
}
/**
* Return the element at the given index.
*
* This will also be called for: $ele = $arr[0]
*
* @param integer $offset The index of the element to be fetched.
* @return mixed The stored element at given index.
* @throws \ErrorException Invalid type for index.
* @throws \ErrorException Non-existing index.
* @todo need to add return type mixed (require update php version to 8.0)
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->container[$offset];
}
/**
* Assign the element at the given index.
*
* This will also be called for: $arr []= $ele and $arr[0] = ele
*
* @param int|null $offset The index of the element to be assigned.
* @param mixed $value The element to be assigned.
* @return void
* @throws \ErrorException Invalid type for index.
* @throws \ErrorException Non-existing index.
* @throws \ErrorException Incorrect type of the element.
* @todo need to add return type void (require update php version to 7.1)
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
switch ($this->type) {
case GPBType::SFIXED32:
case GPBType::SINT32:
case GPBType::INT32:
case GPBType::ENUM:
GPBUtil::checkInt32($value);
break;
case GPBType::FIXED32:
case GPBType::UINT32:
GPBUtil::checkUint32($value);
break;
case GPBType::SFIXED64:
case GPBType::SINT64:
case GPBType::INT64:
GPBUtil::checkInt64($value);
break;
case GPBType::FIXED64:
case GPBType::UINT64:
GPBUtil::checkUint64($value);
break;
case GPBType::FLOAT:
GPBUtil::checkFloat($value);
break;
case GPBType::DOUBLE:
GPBUtil::checkDouble($value);
break;
case GPBType::BOOL:
GPBUtil::checkBool($value);
break;
case GPBType::BYTES:
GPBUtil::checkString($value, false);
break;
case GPBType::STRING:
GPBUtil::checkString($value, true);
break;
case GPBType::MESSAGE:
if (is_null($value)) {
throw new \TypeError("RepeatedField element cannot be null.");
}
GPBUtil::checkMessage($value, $this->klass);
break;
default:
break;
}
if (is_null($offset)) {
$this->container[] = $value;
} else {
$count = count($this->container);
if (!is_numeric($offset) || $offset < 0 || $offset >= $count) {
trigger_error(
"Cannot modify element at the given index",
E_USER_ERROR);
return;
}
$this->container[$offset] = $value;
}
}
/**
* Remove the element at the given index.
*
* This will also be called for: unset($arr)
*
* @param integer $offset The index of the element to be removed.
* @return void
* @throws \ErrorException Invalid type for index.
* @throws \ErrorException The element to be removed is not at the end of the
* RepeatedField.
* @todo need to add return type void (require update php version to 7.1)
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
$count = count($this->container);
if (!is_numeric($offset) || $count === 0 || $offset !== $count - 1) {
trigger_error(
"Cannot remove element at the given index",
E_USER_ERROR);
return;
}
array_pop($this->container);
}
/**
* Check the existence of the element at the given index.
*
* This will also be called for: isset($arr)
*
* @param integer $offset The index of the element to be removed.
* @return bool True if the element at the given offset exists.
* @throws \ErrorException Invalid type for index.
*/
public function offsetExists($offset): bool
{
return isset($this->container[$offset]);
}
/**
* @ignore
*/
public function getIterator(): Traversable
{
return new RepeatedFieldIter($this->container);
}
/**
* Return the number of stored elements.
*
* This will also be called for: count($arr)
*
* @return integer The number of stored elements.
*/
public function count(): int
{
return count($this->container);
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
if (false) {
/**
* This class is deprecated. Use Google\Protobuf\Internal\FieldDescriptorProto\Type instead.
* @deprecated
*/
class FieldDescriptorProto_Type {}
}
class_exists(FieldDescriptorProto\Type::class);
@trigger_error('Google\Protobuf\Internal\FieldDescriptorProto_Type is deprecated and will be removed in the next major release. Use Google\Protobuf\Internal\FieldDescriptorProto\Type instead', E_USER_DEPRECATED);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/**
* MapField and MapFieldIter are used by generated protocol message classes to
* manipulate map fields.
*/
namespace Google\Protobuf\Internal;
/**
* MapFieldIter is used to iterate MapField. It is also need for the foreach
* syntax.
*/
class MapFieldIter implements \Iterator
{
/**
* @ignore
*/
private $container;
/**
* Create iterator instance for MapField.
*
* @param MapField The MapField instance for which this iterator is
* created.
* @param GPBType Map key type.
* @ignore
*/
public function __construct($container, $key_type)
{
$this->container = $container;
$this->key_type = $key_type;
}
/**
* Reset the status of the iterator
*
* @return void
* @todo need to add return type void (require update php version to 7.1)
*/
#[\ReturnTypeWillChange]
public function rewind()
{
reset($this->container);
}
/**
* Return the element at the current position.
*
* @return object The element at the current position.
* @todo need to add return type mixed (require update php version to 8.0)
*/
#[\ReturnTypeWillChange]
public function current()
{
return current($this->container);
}
/**
* Return the current key.
*
* @return object The current key.
* @todo need to add return type mixed (require update php version to 8.0)
*/
#[\ReturnTypeWillChange]
public function key()
{
$key = key($this->container);
switch ($this->key_type) {
case GPBType::INT64:
case GPBType::UINT64:
case GPBType::FIXED64:
case GPBType::SFIXED64:
case GPBType::SINT64:
if (PHP_INT_SIZE === 8) {
return $key;
}
// Intentionally fall through
case GPBType::STRING:
// PHP associative array stores int string as int for key.
return strval($key);
case GPBType::BOOL:
// PHP associative array stores bool as integer for key.
return boolval($key);
default:
return $key;
}
}
/**
* Move to the next position.
*
* @return void
* @todo need to add return type void (require update php version to 7.1)
*/
#[\ReturnTypeWillChange]
public function next()
{
next($this->container);
}
/**
* Check whether there are more elements to iterate.
*
* @return bool True if there are more elements to iterate.
*/
public function valid(): bool
{
return key($this->container) !== null;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
class GPBType
{
const DOUBLE = 1;
const FLOAT = 2;
const INT64 = 3;
const UINT64 = 4;
const INT32 = 5;
const FIXED64 = 6;
const FIXED32 = 7;
const BOOL = 8;
const STRING = 9;
const GROUP = 10;
const MESSAGE = 11;
const BYTES = 12;
const UINT32 = 13;
const ENUM = 14;
const SFIXED32 = 15;
const SFIXED64 = 16;
const SINT32 = 17;
const SINT64 = 18;
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Google\Protobuf\Internal;
/**
* Base class for Google\Protobuf\Any, this contains hand-written convenience
* methods like pack() and unpack().
*/
class AnyBase extends \Google\Protobuf\Internal\Message
{
const TYPE_URL_PREFIX = 'type.googleapis.com/';
/**
* This method will try to resolve the type_url in Any message to get the
* targeted message type. If failed, an error will be thrown. Otherwise,
* the method will create a message of the targeted type and fill it with
* the decoded value in Any.
* @return Message unpacked message
* @throws \Exception Type url needs to be type.googleapis.com/fully-qualified.
* @throws \Exception Class hasn't been added to descriptor pool.
* @throws \Exception cannot decode data in value field.
*/
public function unpack()
{
// Get fully qualified name from type url.
$url_prifix_len = strlen(GPBUtil::TYPE_URL_PREFIX);
if (substr($this->type_url, 0, $url_prifix_len) !=
GPBUtil::TYPE_URL_PREFIX) {
throw new \Exception(
"Type url needs to be type.googleapis.com/fully-qulified");
}
$fully_qualifed_name =
substr($this->type_url, $url_prifix_len);
// Create message according to fully qualified name.
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
$desc = $pool->getDescriptorByProtoName($fully_qualifed_name);
if (is_null($desc)) {
throw new \Exception("Class ".$fully_qualifed_name
." hasn't been added to descriptor pool");
}
$klass = $desc->getClass();
$msg = new $klass();
// Merge data into message.
$msg->mergeFromString($this->value);
return $msg;
}
/**
* The type_url will be created according to the given message’s type and
* the value is encoded data from the given message..
* @param message: A proto message.
*/
public function pack($msg)
{
if (!$msg instanceof Message) {
trigger_error("Given parameter is not a message instance.",
E_USER_ERROR);
return;
}
// Set value using serialized message.
$this->value = $msg->serializeToString();
// Set type url.
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
$desc = $pool->getDescriptorByClassName(get_class($msg));
$fully_qualifed_name = $desc->getFullName();
$this->type_url = GPBUtil::TYPE_URL_PREFIX . $fully_qualifed_name;
}
/**
* This method returns whether the type_url in any_message is corresponded
* to the given class.
* @param klass: The fully qualified PHP class name of a proto message type.
*/
public function is($klass)
{
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
$desc = $pool->getDescriptorByClassName($klass);
$fully_qualifed_name = $desc->getFullName();
$type_url = GPBUtil::TYPE_URL_PREFIX . $fully_qualifed_name;
return $this->type_url === $type_url;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
class Descriptor
{
use HasPublicDescriptorTrait;
private $full_name;
private $field = [];
private $json_to_field = [];
private $name_to_field = [];
private $index_to_field = [];
private $nested_type = [];
private $enum_type = [];
private $klass;
private $legacy_klass;
private $previous_klass;
private $options;
private $oneof_decl = [];
public function __construct()
{
$this->public_desc = new \Google\Protobuf\Descriptor($this);
}
public function addOneofDecl($oneof)
{
$this->oneof_decl[] = $oneof;
}
public function getOneofDecl()
{
return $this->oneof_decl;
}
public function setFullName($full_name)
{
$this->full_name = $full_name;
}
public function getFullName()
{
return $this->full_name;
}
public function addField($field)
{
$this->field[$field->getNumber()] = $field;
$this->json_to_field[$field->getJsonName()] = $field;
$this->name_to_field[$field->getName()] = $field;
$this->index_to_field[] = $field;
}
public function getField()
{
return $this->field;
}
public function addNestedType($desc)
{
$this->nested_type[] = $desc;
}
public function getNestedType()
{
return $this->nested_type;
}
public function addEnumType($desc)
{
$this->enum_type[] = $desc;
}
public function getEnumType()
{
return $this->enum_type;
}
public function getFieldByNumber($number)
{
if (!isset($this->field[$number])) {
return NULL;
} else {
return $this->field[$number];
}
}
public function getFieldByJsonName($json_name)
{
if (!isset($this->json_to_field[$json_name])) {
return NULL;
} else {
return $this->json_to_field[$json_name];
}
}
public function getFieldByName($name)
{
if (!isset($this->name_to_field[$name])) {
return NULL;
} else {
return $this->name_to_field[$name];
}
}
public function getFieldByIndex($index)
{
if (count($this->index_to_field) <= $index) {
return NULL;
} else {
return $this->index_to_field[$index];
}
}
public function setClass($klass)
{
$this->klass = $klass;
}
public function getClass()
{
return $this->klass;
}
public function setLegacyClass($klass)
{
$this->legacy_klass = $klass;
}
public function getLegacyClass()
{
return $this->legacy_klass;
}
public function setPreviouslyUnreservedClass($klass)
{
$this->previous_klass = $klass;
}
public function getPreviouslyUnreservedClass()
{
return $this->previous_klass;
}
public function setOptions($options)
{
$this->options = $options;
}
public function getOptions()
{
return $this->options;
}
public static function buildFromProto($proto, $file_proto, $containing)
{
$desc = new Descriptor();
$message_name_without_package = "";
$classname = "";
$legacy_classname = "";
$previous_classname = "";
$fullname = "";
GPBUtil::getFullClassName(
$proto,
$containing,
$file_proto,
$message_name_without_package,
$classname,
$legacy_classname,
$fullname,
$previous_classname);
$desc->setFullName($fullname);
$desc->setClass($classname);
$desc->setLegacyClass($legacy_classname);
$desc->setPreviouslyUnreservedClass($previous_classname);
$desc->setOptions($proto->getOptions());
foreach ($proto->getField() as $field_proto) {
$desc->addField(FieldDescriptor::buildFromProto($field_proto));
}
// Handle nested types.
foreach ($proto->getNestedType() as $nested_proto) {
$desc->addNestedType(Descriptor::buildFromProto(
$nested_proto, $file_proto, $message_name_without_package));
}
// Handle nested enum.
foreach ($proto->getEnumType() as $enum_proto) {
$desc->addEnumType(EnumDescriptor::buildFromProto(
$enum_proto, $file_proto, $message_name_without_package));
}
// Handle oneof fields.
$index = 0;
foreach ($proto->getOneofDecl() as $oneof_proto) {
$desc->addOneofDecl(
OneofDescriptor::buildFromProto($oneof_proto, $desc, $index));
$index++;
}
return $desc;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
if (false) {
/**
* This class is deprecated. Use Google\Protobuf\Internal\UninterpretedOption\NamePart instead.
* @deprecated
*/
class UninterpretedOption_NamePart {}
}
class_exists(UninterpretedOption\NamePart::class);
@trigger_error('Google\Protobuf\Internal\UninterpretedOption_NamePart is deprecated and will be removed in the next major release. Use Google\Protobuf\Internal\UninterpretedOption\NamePart instead', E_USER_DEPRECATED);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
if (false) {
/**
* This class is deprecated. Use Google\Protobuf\Internal\EnumDescriptorProto\EnumReservedRange instead.
* @deprecated
*/
class EnumDescriptorProto_EnumReservedRange {}
}
class_exists(EnumDescriptorProto\EnumReservedRange::class);
@trigger_error('Google\Protobuf\Internal\EnumDescriptorProto_EnumReservedRange is deprecated and will be removed in the next major release. Use Google\Protobuf\Internal\EnumDescriptorProto\EnumReservedRange instead', E_USER_DEPRECATED);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/**
* MapField and MapFieldIter are used by generated protocol message classes to
* manipulate map fields.
*/
namespace Google\Protobuf\Internal;
use Traversable;
/**
* MapField is used by generated protocol message classes to manipulate map
* fields. It can be used like native PHP array.
*/
class MapField implements \ArrayAccess, \IteratorAggregate, \Countable
{
/**
* @ignore
*/
private $container;
/**
* @ignore
*/
private $key_type;
/**
* @ignore
*/
private $value_type;
/**
* @ignore
*/
private $klass;
/**
* @ignore
*/
private $legacy_klass;
/**
* Constructs an instance of MapField.
*
* @param long $key_type Type of the stored key element.
* @param long $value_type Type of the stored value element.
* @param string $klass Message/Enum class name of value instance
* (message/enum fields only).
* @ignore
*/
public function __construct($key_type, $value_type, $klass = null)
{
$this->container = [];
$this->key_type = $key_type;
$this->value_type = $value_type;
$this->klass = $klass;
if ($this->value_type == GPBType::MESSAGE) {
$pool = DescriptorPool::getGeneratedPool();
$desc = $pool->getDescriptorByClassName($klass);
if ($desc == NULL) {
new $klass; // No msg class instance has been created before.
$desc = $pool->getDescriptorByClassName($klass);
}
$this->klass = $desc->getClass();
$this->legacy_klass = $desc->getLegacyClass();
}
}
/**
* @ignore
*/
public function getKeyType()
{
return $this->key_type;
}
/**
* @ignore
*/
public function getValueType()
{
return $this->value_type;
}
/**
* @ignore
*/
public function getValueClass()
{
return $this->klass;
}
/**
* @ignore
*/
public function getLegacyValueClass()
{
return $this->legacy_klass;
}
/**
* Return the element at the given key.
*
* This will also be called for: $ele = $arr[$key]
*
* @param int|string $key The key of the element to be fetched.
* @return object The stored element at given key.
* @throws \ErrorException Invalid type for index.
* @throws \ErrorException Non-existing index.
* @todo need to add return type mixed (require update php version to 8.0)
*/
#[\ReturnTypeWillChange]
public function offsetGet($key)
{
return $this->container[$key];
}
/**
* Assign the element at the given key.
*
* This will also be called for: $arr[$key] = $value
*
* @param int|string $key The key of the element to be fetched.
* @param object $value The element to be assigned.
* @return void
* @throws \ErrorException Invalid type for key.
* @throws \ErrorException Invalid type for value.
* @throws \ErrorException Non-existing key.
* @todo need to add return type void (require update php version to 7.1)
*/
#[\ReturnTypeWillChange]
public function offsetSet($key, $value)
{
$this->checkKey($this->key_type, $key);
switch ($this->value_type) {
case GPBType::SFIXED32:
case GPBType::SINT32:
case GPBType::INT32:
case GPBType::ENUM:
GPBUtil::checkInt32($value);
break;
case GPBType::FIXED32:
case GPBType::UINT32:
GPBUtil::checkUint32($value);
break;
case GPBType::SFIXED64:
case GPBType::SINT64:
case GPBType::INT64:
GPBUtil::checkInt64($value);
break;
case GPBType::FIXED64:
case GPBType::UINT64:
GPBUtil::checkUint64($value);
break;
case GPBType::FLOAT:
GPBUtil::checkFloat($value);
break;
case GPBType::DOUBLE:
GPBUtil::checkDouble($value);
break;
case GPBType::BOOL:
GPBUtil::checkBool($value);
break;
case GPBType::STRING:
GPBUtil::checkString($value, true);
break;
case GPBType::MESSAGE:
if (is_null($value)) {
trigger_error("Map element cannot be null.", E_USER_ERROR);
}
GPBUtil::checkMessage($value, $this->klass);
break;
default:
break;
}
$this->container[$key] = $value;
}
/**
* Remove the element at the given key.
*
* This will also be called for: unset($arr)
*
* @param int|string $key The key of the element to be removed.
* @return void
* @throws \ErrorException Invalid type for key.
* @todo need to add return type void (require update php version to 7.1)
*/
#[\ReturnTypeWillChange]
public function offsetUnset($key)
{
$this->checkKey($this->key_type, $key);
unset($this->container[$key]);
}
/**
* Check the existence of the element at the given key.
*
* This will also be called for: isset($arr)
*
* @param int|string $key The key of the element to be removed.
* @return bool True if the element at the given key exists.
* @throws \ErrorException Invalid type for key.
*/
public function offsetExists($key): bool
{
$this->checkKey($this->key_type, $key);
return isset($this->container[$key]);
}
/**
* @ignore
*/
public function getIterator(): Traversable
{
return new MapFieldIter($this->container, $this->key_type);
}
/**
* Return the number of stored elements.
*
* This will also be called for: count($arr)
*
* @return integer The number of stored elements.
*/
public function count(): int
{
return count($this->container);
}
/**
* @ignore
*/
private function checkKey($key_type, &$key)
{
switch ($key_type) {
case GPBType::SFIXED32:
case GPBType::SINT32:
case GPBType::INT32:
GPBUtil::checkInt32($key);
break;
case GPBType::FIXED32:
case GPBType::UINT32:
GPBUtil::checkUint32($key);
break;
case GPBType::SFIXED64:
case GPBType::SINT64:
case GPBType::INT64:
GPBUtil::checkInt64($key);
break;
case GPBType::FIXED64:
case GPBType::UINT64:
GPBUtil::checkUint64($key);
break;
case GPBType::BOOL:
GPBUtil::checkBool($key);
break;
case GPBType::STRING:
GPBUtil::checkString($key, true);
break;
default:
trigger_error(
"Given type cannot be map key.",
E_USER_ERROR);
break;
}
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Describes a field within a message.
*
* Generated from protobuf message <code>google.protobuf.FieldDescriptorProto</code>
*/
class FieldDescriptorProto extends \Google\Protobuf\Internal\Message
{
/**
* Generated from protobuf field <code>optional string name = 1;</code>
*/
protected $name = null;
/**
* Generated from protobuf field <code>optional int32 number = 3;</code>
*/
protected $number = null;
/**
* Generated from protobuf field <code>optional .google.protobuf.FieldDescriptorProto.Label label = 4;</code>
*/
protected $label = null;
/**
* If type_name is set, this need not be set. If both this and type_name
* are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
*
* Generated from protobuf field <code>optional .google.protobuf.FieldDescriptorProto.Type type = 5;</code>
*/
protected $type = null;
/**
* For message and enum types, this is the name of the type. If the name
* starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
* rules are used to find the type (i.e. first the nested types within this
* message are searched, then within the parent, on up to the root
* namespace).
*
* Generated from protobuf field <code>optional string type_name = 6;</code>
*/
protected $type_name = null;
/**
* For extensions, this is the name of the type being extended. It is
* resolved in the same manner as type_name.
*
* Generated from protobuf field <code>optional string extendee = 2;</code>
*/
protected $extendee = null;
/**
* For numeric types, contains the original text representation of the value.
* For booleans, "true" or "false".
* For strings, contains the default text contents (not escaped in any way).
* For bytes, contains the C escaped value. All bytes >= 128 are escaped.
*
* Generated from protobuf field <code>optional string default_value = 7;</code>
*/
protected $default_value = null;
/**
* If set, gives the index of a oneof in the containing type's oneof_decl
* list. This field is a member of that oneof.
*
* Generated from protobuf field <code>optional int32 oneof_index = 9;</code>
*/
protected $oneof_index = null;
/**
* JSON name of this field. The value is set by protocol compiler. If the
* user has set a "json_name" option on this field, that option's value
* will be used. Otherwise, it's deduced from the field's name by converting
* it to camelCase.
*
* Generated from protobuf field <code>optional string json_name = 10;</code>
*/
protected $json_name = null;
/**
* Generated from protobuf field <code>optional .google.protobuf.FieldOptions options = 8;</code>
*/
protected $options = null;
/**
* If true, this is a proto3 "optional". When a proto3 field is optional, it
* tracks presence regardless of field type.
* When proto3_optional is true, this field must be belong to a oneof to
* signal to old proto3 clients that presence is tracked for this field. This
* oneof is known as a "synthetic" oneof, and this field must be its sole
* member (each proto3 optional field gets its own synthetic oneof). Synthetic
* oneofs exist in the descriptor only, and do not generate any API. Synthetic
* oneofs must be ordered after all "real" oneofs.
* For message fields, proto3_optional doesn't create any semantic change,
* since non-repeated message fields always track presence. However it still
* indicates the semantic detail of whether the user wrote "optional" or not.
* This can be useful for round-tripping the .proto file. For consistency we
* give message fields a synthetic oneof also, even though it is not required
* to track presence. This is especially important because the parser can't
* tell if a field is a message or an enum, so it must always create a
* synthetic oneof.
* Proto2 optional fields do not set this flag, because they already indicate
* optional with `LABEL_OPTIONAL`.
*
* Generated from protobuf field <code>optional bool proto3_optional = 17;</code>
*/
protected $proto3_optional = null;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type string $name
* @type int $number
* @type int $label
* @type int $type
* If type_name is set, this need not be set. If both this and type_name
* are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
* @type string $type_name
* For message and enum types, this is the name of the type. If the name
* starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
* rules are used to find the type (i.e. first the nested types within this
* message are searched, then within the parent, on up to the root
* namespace).
* @type string $extendee
* For extensions, this is the name of the type being extended. It is
* resolved in the same manner as type_name.
* @type string $default_value
* For numeric types, contains the original text representation of the value.
* For booleans, "true" or "false".
* For strings, contains the default text contents (not escaped in any way).
* For bytes, contains the C escaped value. All bytes >= 128 are escaped.
* @type int $oneof_index
* If set, gives the index of a oneof in the containing type's oneof_decl
* list. This field is a member of that oneof.
* @type string $json_name
* JSON name of this field. The value is set by protocol compiler. If the
* user has set a "json_name" option on this field, that option's value
* will be used. Otherwise, it's deduced from the field's name by converting
* it to camelCase.
* @type \Google\Protobuf\Internal\FieldOptions $options
* @type bool $proto3_optional
* If true, this is a proto3 "optional". When a proto3 field is optional, it
* tracks presence regardless of field type.
* When proto3_optional is true, this field must be belong to a oneof to
* signal to old proto3 clients that presence is tracked for this field. This
* oneof is known as a "synthetic" oneof, and this field must be its sole
* member (each proto3 optional field gets its own synthetic oneof). Synthetic
* oneofs exist in the descriptor only, and do not generate any API. Synthetic
* oneofs must be ordered after all "real" oneofs.
* For message fields, proto3_optional doesn't create any semantic change,
* since non-repeated message fields always track presence. However it still
* indicates the semantic detail of whether the user wrote "optional" or not.
* This can be useful for round-tripping the .proto file. For consistency we
* give message fields a synthetic oneof also, even though it is not required
* to track presence. This is especially important because the parser can't
* tell if a field is a message or an enum, so it must always create a
* synthetic oneof.
* Proto2 optional fields do not set this flag, because they already indicate
* optional with `LABEL_OPTIONAL`.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Generated from protobuf field <code>optional string name = 1;</code>
* @return string
*/
public function getName()
{
return isset($this->name) ? $this->name : '';
}
public function hasName()
{
return isset($this->name);
}
public function clearName()
{
unset($this->name);
}
/**
* Generated from protobuf field <code>optional string name = 1;</code>
* @param string $var
* @return $this
*/
public function setName($var)
{
GPBUtil::checkString($var, True);
$this->name = $var;
return $this;
}
/**
* Generated from protobuf field <code>optional int32 number = 3;</code>
* @return int
*/
public function getNumber()
{
return isset($this->number) ? $this->number : 0;
}
public function hasNumber()
{
return isset($this->number);
}
public function clearNumber()
{
unset($this->number);
}
/**
* Generated from protobuf field <code>optional int32 number = 3;</code>
* @param int $var
* @return $this
*/
public function setNumber($var)
{
GPBUtil::checkInt32($var);
$this->number = $var;
return $this;
}
/**
* Generated from protobuf field <code>optional .google.protobuf.FieldDescriptorProto.Label label = 4;</code>
* @return int
*/
public function getLabel()
{
return isset($this->label) ? $this->label : 0;
}
public function hasLabel()
{
return isset($this->label);
}
public function clearLabel()
{
unset($this->label);
}
/**
* Generated from protobuf field <code>optional .google.protobuf.FieldDescriptorProto.Label label = 4;</code>
* @param int $var
* @return $this
*/
public function setLabel($var)
{
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldDescriptorProto\Label::class);
$this->label = $var;
return $this;
}
/**
* If type_name is set, this need not be set. If both this and type_name
* are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
*
* Generated from protobuf field <code>optional .google.protobuf.FieldDescriptorProto.Type type = 5;</code>
* @return int
*/
public function getType()
{
return isset($this->type) ? $this->type : 0;
}
public function hasType()
{
return isset($this->type);
}
public function clearType()
{
unset($this->type);
}
/**
* If type_name is set, this need not be set. If both this and type_name
* are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
*
* Generated from protobuf field <code>optional .google.protobuf.FieldDescriptorProto.Type type = 5;</code>
* @param int $var
* @return $this
*/
public function setType($var)
{
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldDescriptorProto\Type::class);
$this->type = $var;
return $this;
}
/**
* For message and enum types, this is the name of the type. If the name
* starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
* rules are used to find the type (i.e. first the nested types within this
* message are searched, then within the parent, on up to the root
* namespace).
*
* Generated from protobuf field <code>optional string type_name = 6;</code>
* @return string
*/
public function getTypeName()
{
return isset($this->type_name) ? $this->type_name : '';
}
public function hasTypeName()
{
return isset($this->type_name);
}
public function clearTypeName()
{
unset($this->type_name);
}
/**
* For message and enum types, this is the name of the type. If the name
* starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
* rules are used to find the type (i.e. first the nested types within this
* message are searched, then within the parent, on up to the root
* namespace).
*
* Generated from protobuf field <code>optional string type_name = 6;</code>
* @param string $var
* @return $this
*/
public function setTypeName($var)
{
GPBUtil::checkString($var, True);
$this->type_name = $var;
return $this;
}
/**
* For extensions, this is the name of the type being extended. It is
* resolved in the same manner as type_name.
*
* Generated from protobuf field <code>optional string extendee = 2;</code>
* @return string
*/
public function getExtendee()
{
return isset($this->extendee) ? $this->extendee : '';
}
public function hasExtendee()
{
return isset($this->extendee);
}
public function clearExtendee()
{
unset($this->extendee);
}
/**
* For extensions, this is the name of the type being extended. It is
* resolved in the same manner as type_name.
*
* Generated from protobuf field <code>optional string extendee = 2;</code>
* @param string $var
* @return $this
*/
public function setExtendee($var)
{
GPBUtil::checkString($var, True);
$this->extendee = $var;
return $this;
}
/**
* For numeric types, contains the original text representation of the value.
* For booleans, "true" or "false".
* For strings, contains the default text contents (not escaped in any way).
* For bytes, contains the C escaped value. All bytes >= 128 are escaped.
*
* Generated from protobuf field <code>optional string default_value = 7;</code>
* @return string
*/
public function getDefaultValue()
{
return isset($this->default_value) ? $this->default_value : '';
}
public function hasDefaultValue()
{
return isset($this->default_value);
}
public function clearDefaultValue()
{
unset($this->default_value);
}
/**
* For numeric types, contains the original text representation of the value.
* For booleans, "true" or "false".
* For strings, contains the default text contents (not escaped in any way).
* For bytes, contains the C escaped value. All bytes >= 128 are escaped.
*
* Generated from protobuf field <code>optional string default_value = 7;</code>
* @param string $var
* @return $this
*/
public function setDefaultValue($var)
{
GPBUtil::checkString($var, True);
$this->default_value = $var;
return $this;
}
/**
* If set, gives the index of a oneof in the containing type's oneof_decl
* list. This field is a member of that oneof.
*
* Generated from protobuf field <code>optional int32 oneof_index = 9;</code>
* @return int
*/
public function getOneofIndex()
{
return isset($this->oneof_index) ? $this->oneof_index : 0;
}
public function hasOneofIndex()
{
return isset($this->oneof_index);
}
public function clearOneofIndex()
{
unset($this->oneof_index);
}
/**
* If set, gives the index of a oneof in the containing type's oneof_decl
* list. This field is a member of that oneof.
*
* Generated from protobuf field <code>optional int32 oneof_index = 9;</code>
* @param int $var
* @return $this
*/
public function setOneofIndex($var)
{
GPBUtil::checkInt32($var);
$this->oneof_index = $var;
return $this;
}
/**
* JSON name of this field. The value is set by protocol compiler. If the
* user has set a "json_name" option on this field, that option's value
* will be used. Otherwise, it's deduced from the field's name by converting
* it to camelCase.
*
* Generated from protobuf field <code>optional string json_name = 10;</code>
* @return string
*/
public function getJsonName()
{
return isset($this->json_name) ? $this->json_name : '';
}
public function hasJsonName()
{
return isset($this->json_name);
}
public function clearJsonName()
{
unset($this->json_name);
}
/**
* JSON name of this field. The value is set by protocol compiler. If the
* user has set a "json_name" option on this field, that option's value
* will be used. Otherwise, it's deduced from the field's name by converting
* it to camelCase.
*
* Generated from protobuf field <code>optional string json_name = 10;</code>
* @param string $var
* @return $this
*/
public function setJsonName($var)
{
GPBUtil::checkString($var, True);
$this->json_name = $var;
return $this;
}
/**
* Generated from protobuf field <code>optional .google.protobuf.FieldOptions options = 8;</code>
* @return \Google\Protobuf\Internal\FieldOptions|null
*/
public function getOptions()
{
return $this->options;
}
public function hasOptions()
{
return isset($this->options);
}
public function clearOptions()
{
unset($this->options);
}
/**
* Generated from protobuf field <code>optional .google.protobuf.FieldOptions options = 8;</code>
* @param \Google\Protobuf\Internal\FieldOptions $var
* @return $this
*/
public function setOptions($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FieldOptions::class);
$this->options = $var;
return $this;
}
/**
* If true, this is a proto3 "optional". When a proto3 field is optional, it
* tracks presence regardless of field type.
* When proto3_optional is true, this field must be belong to a oneof to
* signal to old proto3 clients that presence is tracked for this field. This
* oneof is known as a "synthetic" oneof, and this field must be its sole
* member (each proto3 optional field gets its own synthetic oneof). Synthetic
* oneofs exist in the descriptor only, and do not generate any API. Synthetic
* oneofs must be ordered after all "real" oneofs.
* For message fields, proto3_optional doesn't create any semantic change,
* since non-repeated message fields always track presence. However it still
* indicates the semantic detail of whether the user wrote "optional" or not.
* This can be useful for round-tripping the .proto file. For consistency we
* give message fields a synthetic oneof also, even though it is not required
* to track presence. This is especially important because the parser can't
* tell if a field is a message or an enum, so it must always create a
* synthetic oneof.
* Proto2 optional fields do not set this flag, because they already indicate
* optional with `LABEL_OPTIONAL`.
*
* Generated from protobuf field <code>optional bool proto3_optional = 17;</code>
* @return bool
*/
public function getProto3Optional()
{
return isset($this->proto3_optional) ? $this->proto3_optional : false;
}
public function hasProto3Optional()
{
return isset($this->proto3_optional);
}
public function clearProto3Optional()
{
unset($this->proto3_optional);
}
/**
* If true, this is a proto3 "optional". When a proto3 field is optional, it
* tracks presence regardless of field type.
* When proto3_optional is true, this field must be belong to a oneof to
* signal to old proto3 clients that presence is tracked for this field. This
* oneof is known as a "synthetic" oneof, and this field must be its sole
* member (each proto3 optional field gets its own synthetic oneof). Synthetic
* oneofs exist in the descriptor only, and do not generate any API. Synthetic
* oneofs must be ordered after all "real" oneofs.
* For message fields, proto3_optional doesn't create any semantic change,
* since non-repeated message fields always track presence. However it still
* indicates the semantic detail of whether the user wrote "optional" or not.
* This can be useful for round-tripping the .proto file. For consistency we
* give message fields a synthetic oneof also, even though it is not required
* to track presence. This is especially important because the parser can't
* tell if a field is a message or an enum, so it must always create a
* synthetic oneof.
* Proto2 optional fields do not set this flag, because they already indicate
* optional with `LABEL_OPTIONAL`.
*
* Generated from protobuf field <code>optional bool proto3_optional = 17;</code>
* @param bool $var
* @return $this
*/
public function setProto3Optional($var)
{
GPBUtil::checkBool($var);
$this->proto3_optional = $var;
return $this;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
if (false) {
/**
* This class is deprecated. Use Google\Protobuf\Internal\GeneratedCodeInfo\Annotation instead.
* @deprecated
*/
class GeneratedCodeInfo_Annotation {}
}
class_exists(GeneratedCodeInfo\Annotation::class);
@trigger_error('Google\Protobuf\Internal\GeneratedCodeInfo_Annotation is deprecated and will be removed in the next major release. Use Google\Protobuf\Internal\GeneratedCodeInfo\Annotation instead', E_USER_DEPRECATED);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Describes a service.
*
* Generated from protobuf message <code>google.protobuf.ServiceDescriptorProto</code>
*/
class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message
{
/**
* Generated from protobuf field <code>optional string name = 1;</code>
*/
protected $name = null;
/**
* Generated from protobuf field <code>repeated .google.protobuf.MethodDescriptorProto method = 2;</code>
*/
private $method;
/**
* Generated from protobuf field <code>optional .google.protobuf.ServiceOptions options = 3;</code>
*/
protected $options = null;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type string $name
* @type array<\Google\Protobuf\Internal\MethodDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $method
* @type \Google\Protobuf\Internal\ServiceOptions $options
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Generated from protobuf field <code>optional string name = 1;</code>
* @return string
*/
public function getName()
{
return isset($this->name) ? $this->name : '';
}
public function hasName()
{
return isset($this->name);
}
public function clearName()
{
unset($this->name);
}
/**
* Generated from protobuf field <code>optional string name = 1;</code>
* @param string $var
* @return $this
*/
public function setName($var)
{
GPBUtil::checkString($var, True);
$this->name = $var;
return $this;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.MethodDescriptorProto method = 2;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getMethod()
{
return $this->method;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.MethodDescriptorProto method = 2;</code>
* @param array<\Google\Protobuf\Internal\MethodDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setMethod($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\MethodDescriptorProto::class);
$this->method = $arr;
return $this;
}
/**
* Generated from protobuf field <code>optional .google.protobuf.ServiceOptions options = 3;</code>
* @return \Google\Protobuf\Internal\ServiceOptions|null
*/
public function getOptions()
{
return $this->options;
}
public function hasOptions()
{
return isset($this->options);
}
public function clearOptions()
{
unset($this->options);
}
/**
* Generated from protobuf field <code>optional .google.protobuf.ServiceOptions options = 3;</code>
* @param \Google\Protobuf\Internal\ServiceOptions $var
* @return $this
*/
public function setOptions($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\ServiceOptions::class);
$this->options = $var;
return $this;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
class GPBJsonWire
{
public static function serializeFieldToStream(
$value,
$field,
&$output, $has_field_name = true)
{
if ($has_field_name) {
$output->writeRaw("\"", 1);
$field_name = GPBJsonWire::formatFieldName($field);
$output->writeRaw($field_name, strlen($field_name));
$output->writeRaw("\":", 2);
}
return static::serializeFieldValueToStream(
$value,
$field,
$output,
!$has_field_name);
}
public static function serializeFieldValueToStream(
$values,
$field,
&$output,
$is_well_known = false)
{
if ($field->isMap()) {
$output->writeRaw("{", 1);
$first = true;
$map_entry = $field->getMessageType();
$key_field = $map_entry->getFieldByNumber(1);
$value_field = $map_entry->getFieldByNumber(2);
switch ($key_field->getType()) {
case GPBType::STRING:
case GPBType::SFIXED64:
case GPBType::INT64:
case GPBType::SINT64:
case GPBType::FIXED64:
case GPBType::UINT64:
$additional_quote = false;
break;
default:
$additional_quote = true;
}
foreach ($values as $key => $value) {
if ($first) {
$first = false;
} else {
$output->writeRaw(",", 1);
}
if ($additional_quote) {
$output->writeRaw("\"", 1);
}
if (!static::serializeSingularFieldValueToStream(
$key,
$key_field,
$output,
$is_well_known)) {
return false;
}
if ($additional_quote) {
$output->writeRaw("\"", 1);
}
$output->writeRaw(":", 1);
if (!static::serializeSingularFieldValueToStream(
$value,
$value_field,
$output,
$is_well_known)) {
return false;
}
}
$output->writeRaw("}", 1);
return true;
} elseif ($field->isRepeated()) {
$output->writeRaw("[", 1);
$first = true;
foreach ($values as $value) {
if ($first) {
$first = false;
} else {
$output->writeRaw(",", 1);
}
if (!static::serializeSingularFieldValueToStream(
$value,
$field,
$output,
$is_well_known)) {
return false;
}
}
$output->writeRaw("]", 1);
return true;
} else {
return static::serializeSingularFieldValueToStream(
$values,
$field,
$output,
$is_well_known);
}
}
private static function serializeSingularFieldValueToStream(
$value,
$field,
&$output, $is_well_known = false)
{
switch ($field->getType()) {
case GPBType::SFIXED32:
case GPBType::SINT32:
case GPBType::INT32:
$str_value = strval($value);
$output->writeRaw($str_value, strlen($str_value));
break;
case GPBType::FIXED32:
case GPBType::UINT32:
if ($value < 0) {
$value = bcadd($value, "4294967296");
}
$str_value = strval($value);
$output->writeRaw($str_value, strlen($str_value));
break;
case GPBType::FIXED64:
case GPBType::UINT64:
if ($value < 0) {
$value = bcadd($value, "18446744073709551616");
}
// Intentional fall through.
case GPBType::SFIXED64:
case GPBType::INT64:
case GPBType::SINT64:
$output->writeRaw("\"", 1);
$str_value = strval($value);
$output->writeRaw($str_value, strlen($str_value));
$output->writeRaw("\"", 1);
break;
case GPBType::FLOAT:
if (is_nan($value)) {
$str_value = "\"NaN\"";
} elseif ($value === INF) {
$str_value = "\"Infinity\"";
} elseif ($value === -INF) {
$str_value = "\"-Infinity\"";
} else {
$str_value = sprintf("%.8g", $value);
}
$output->writeRaw($str_value, strlen($str_value));
break;
case GPBType::DOUBLE:
if (is_nan($value)) {
$str_value = "\"NaN\"";
} elseif ($value === INF) {
$str_value = "\"Infinity\"";
} elseif ($value === -INF) {
$str_value = "\"-Infinity\"";
} else {
$str_value = sprintf("%.17g", $value);
}
$output->writeRaw($str_value, strlen($str_value));
break;
case GPBType::ENUM:
$enum_desc = $field->getEnumType();
if ($enum_desc->getClass() === "Google\Protobuf\NullValue") {
$output->writeRaw("null", 4);
break;
}
$enum_value_desc = $enum_desc->getValueByNumber($value);
if (!is_null($enum_value_desc)) {
$str_value = $enum_value_desc->getName();
$output->writeRaw("\"", 1);
$output->writeRaw($str_value, strlen($str_value));
$output->writeRaw("\"", 1);
} else {
$str_value = strval($value);
$output->writeRaw($str_value, strlen($str_value));
}
break;
case GPBType::BOOL:
if ($value) {
$output->writeRaw("true", 4);
} else {
$output->writeRaw("false", 5);
}
break;
case GPBType::BYTES:
$bytes_value = base64_encode($value);
$output->writeRaw("\"", 1);
$output->writeRaw($bytes_value, strlen($bytes_value));
$output->writeRaw("\"", 1);
break;
case GPBType::STRING:
$value = json_encode($value, JSON_UNESCAPED_UNICODE);
$output->writeRaw($value, strlen($value));
break;
// case GPBType::GROUP:
// echo "GROUP\xA";
// trigger_error("Not implemented.", E_ERROR);
// break;
case GPBType::MESSAGE:
$value->serializeToJsonStream($output);
break;
default:
user_error("Unsupported type.");
return false;
}
return true;
}
private static function formatFieldName($field)
{
return $field->getJsonName();
}
// Used for escaping control chars in strings.
private static $k_control_char_limit = 0x20;
private static function jsonNiceEscape($c)
{
switch ($c) {
case '"': return "\\\"";
case '\\': return "\\\\";
case '/': return "\\/";
case '\b': return "\\b";
case '\f': return "\\f";
case '\n': return "\\n";
case '\r': return "\\r";
case '\t': return "\\t";
default: return NULL;
}
}
private static function isJsonEscaped($c)
{
// See RFC 4627.
return $c < chr($k_control_char_limit) || $c === "\"" || $c === "\\";
}
public static function escapedJson($value)
{
$escaped_value = "";
$unescaped_run = "";
for ($i = 0; $i < strlen($value); $i++) {
$c = $value[$i];
// Handle escaping.
if (static::isJsonEscaped($c)) {
// Use a "nice" escape, like \n, if one exists for this
// character.
$escape = static::jsonNiceEscape($c);
if (is_null($escape)) {
$escape = "\\u00" . bin2hex($c);
}
if ($unescaped_run !== "") {
$escaped_value .= $unescaped_run;
$unescaped_run = "";
}
$escaped_value .= $escape;
} else {
if ($unescaped_run === "") {
$unescaped_run .= $c;
}
}
}
$escaped_value .= $unescaped_run;
return $escaped_value;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2017 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
trait GetPublicDescriptorTrait
{
private function getPublicDescriptor($desc)
{
return is_null($desc) ? null : $desc->getPublicDescriptor();
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
class GPBWire
{
const TAG_TYPE_BITS = 3;
const WIRETYPE_VARINT = 0;
const WIRETYPE_FIXED64 = 1;
const WIRETYPE_LENGTH_DELIMITED = 2;
const WIRETYPE_START_GROUP = 3;
const WIRETYPE_END_GROUP = 4;
const WIRETYPE_FIXED32 = 5;
const UNKNOWN = 0;
const NORMAL_FORMAT = 1;
const PACKED_FORMAT = 2;
public static function getTagFieldNumber($tag)
{
// We have to mask because PHP has no arithmetic shift.
return ($tag >> self::TAG_TYPE_BITS) & 0x1fffffff;
}
public static function getTagWireType($tag)
{
return $tag & 0x7;
}
public static function getWireType($type)
{
switch ($type) {
case GPBType::FLOAT:
case GPBType::FIXED32:
case GPBType::SFIXED32:
return self::WIRETYPE_FIXED32;
case GPBType::DOUBLE:
case GPBType::FIXED64:
case GPBType::SFIXED64:
return self::WIRETYPE_FIXED64;
case GPBType::UINT32:
case GPBType::UINT64:
case GPBType::INT32:
case GPBType::INT64:
case GPBType::SINT32:
case GPBType::SINT64:
case GPBType::ENUM:
case GPBType::BOOL:
return self::WIRETYPE_VARINT;
case GPBType::STRING:
case GPBType::BYTES:
case GPBType::MESSAGE:
return self::WIRETYPE_LENGTH_DELIMITED;
case GPBType::GROUP:
user_error("Unsupported type.");
return 0;
default:
user_error("Unsupported type.");
return 0;
}
}
// ZigZag Transform: Encodes signed integers so that they can be effectively
// used with varint encoding.
//
// varint operates on unsigned integers, encoding smaller numbers into fewer
// bytes. If you try to use it on a signed integer, it will treat this
// number as a very large unsigned integer, which means that even small
// signed numbers like -1 will take the maximum number of bytes (10) to
// encode. zigZagEncode() maps signed integers to unsigned in such a way
// that those with a small absolute value will have smaller encoded values,
// making them appropriate for encoding using varint.
//
// int32 -> uint32
// -------------------------
// 0 -> 0
// -1 -> 1
// 1 -> 2
// -2 -> 3
// ... -> ...
// 2147483647 -> 4294967294
// -2147483648 -> 4294967295
//
// >> encode >>
// << decode <<
public static function zigZagEncode32($int32)
{
if (PHP_INT_SIZE == 8) {
$trim_int32 = $int32 & 0xFFFFFFFF;
return (($trim_int32 << 1) ^ ($int32 << 32 >> 63)) & 0xFFFFFFFF;
} else {
return ($int32 << 1) ^ ($int32 >> 31);
}
}
public static function zigZagDecode32($uint32)
{
// Fill high 32 bits.
if (PHP_INT_SIZE === 8) {
$uint32 |= ($uint32 & 0xFFFFFFFF);
}
$int32 = (($uint32 >> 1) & 0x7FFFFFFF) ^ (-($uint32 & 1));
return $int32;
}
public static function zigZagEncode64($int64)
{
if (PHP_INT_SIZE == 4) {
if (bccomp($int64, 0) >= 0) {
return bcmul($int64, 2);
} else {
return bcsub(bcmul(bcsub(0, $int64), 2), 1);
}
} else {
return ((int)$int64 << 1) ^ ((int)$int64 >> 63);
}
}
public static function zigZagDecode64($uint64)
{
if (PHP_INT_SIZE == 4) {
if (bcmod($uint64, 2) == 0) {
return bcdiv($uint64, 2, 0);
} else {
return bcsub(0, bcdiv(bcadd($uint64, 1), 2, 0));
}
} else {
return (($uint64 >> 1) & 0x7FFFFFFFFFFFFFFF) ^ (-($uint64 & 1));
}
}
public static function readInt32(&$input, &$value)
{
return $input->readVarint32($value);
}
public static function readInt64(&$input, &$value)
{
$success = $input->readVarint64($value);
if (PHP_INT_SIZE == 4 && bccomp($value, "9223372036854775807") > 0) {
$value = bcsub($value, "18446744073709551616");
}
return $success;
}
public static function readUint32(&$input, &$value)
{
return self::readInt32($input, $value);
}
public static function readUint64(&$input, &$value)
{
return self::readInt64($input, $value);
}
public static function readSint32(&$input, &$value)
{
if (!$input->readVarint32($value)) {
return false;
}
$value = GPBWire::zigZagDecode32($value);
return true;
}
public static function readSint64(&$input, &$value)
{
if (!$input->readVarint64($value)) {
return false;
}
$value = GPBWire::zigZagDecode64($value);
return true;
}
public static function readFixed32(&$input, &$value)
{
return $input->readLittleEndian32($value);
}
public static function readFixed64(&$input, &$value)
{
return $input->readLittleEndian64($value);
}
public static function readSfixed32(&$input, &$value)
{
if (!self::readFixed32($input, $value)) {
return false;
}
if (PHP_INT_SIZE === 8) {
$value |= (-($value >> 31) << 32);
}
return true;
}
public static function readSfixed64(&$input, &$value)
{
$success = $input->readLittleEndian64($value);
if (PHP_INT_SIZE == 4 && bccomp($value, "9223372036854775807") > 0) {
$value = bcsub($value, "18446744073709551616");
}
return $success;
}
public static function readFloat(&$input, &$value)
{
$data = null;
if (!$input->readRaw(4, $data)) {
return false;
}
$value = unpack('f', $data)[1];
return true;
}
public static function readDouble(&$input, &$value)
{
$data = null;
if (!$input->readRaw(8, $data)) {
return false;
}
$value = unpack('d', $data)[1];
return true;
}
public static function readBool(&$input, &$value)
{
if (!$input->readVarint64($value)) {
return false;
}
if ($value == 0) {
$value = false;
} else {
$value = true;
}
return true;
}
public static function readString(&$input, &$value)
{
$length = 0;
return $input->readVarintSizeAsInt($length) && $input->readRaw($length, $value);
}
public static function readMessage(&$input, &$message)
{
$length = 0;
if (!$input->readVarintSizeAsInt($length)) {
return false;
}
$old_limit = 0;
$recursion_limit = 0;
$input->incrementRecursionDepthAndPushLimit(
$length,
$old_limit,
$recursion_limit);
if ($recursion_limit < 0 || !$message->parseFromStream($input)) {
return false;
}
return $input->decrementRecursionDepthAndPopLimit($old_limit);
}
public static function writeTag(&$output, $tag)
{
return $output->writeTag($tag);
}
public static function writeInt32(&$output, $value)
{
return $output->writeVarint32($value, false);
}
public static function writeInt64(&$output, $value)
{
return $output->writeVarint64($value);
}
public static function writeUint32(&$output, $value)
{
return $output->writeVarint32($value, true);
}
public static function writeUint64(&$output, $value)
{
return $output->writeVarint64($value);
}
public static function writeSint32(&$output, $value)
{
$value = GPBWire::zigZagEncode32($value);
return $output->writeVarint32($value, true);
}
public static function writeSint64(&$output, $value)
{
$value = GPBWire::zigZagEncode64($value);
return $output->writeVarint64($value);
}
public static function writeFixed32(&$output, $value)
{
return $output->writeLittleEndian32($value);
}
public static function writeFixed64(&$output, $value)
{
return $output->writeLittleEndian64($value);
}
public static function writeSfixed32(&$output, $value)
{
return $output->writeLittleEndian32($value);
}
public static function writeSfixed64(&$output, $value)
{
return $output->writeLittleEndian64($value);
}
public static function writeBool(&$output, $value)
{
if ($value) {
return $output->writeVarint32(1, true);
} else {
return $output->writeVarint32(0, true);
}
}
public static function writeFloat(&$output, $value)
{
$data = pack("f", $value);
return $output->writeRaw($data, 4);
}
public static function writeDouble(&$output, $value)
{
$data = pack("d", $value);
return $output->writeRaw($data, 8);
}
public static function writeString(&$output, $value)
{
return self::writeBytes($output, $value);
}
public static function writeBytes(&$output, $value)
{
$size = strlen($value);
if (!$output->writeVarint32($size, true)) {
return false;
}
return $output->writeRaw($value, $size);
}
public static function writeMessage(&$output, $value)
{
$size = $value->byteSize();
if (!$output->writeVarint32($size, true)) {
return false;
}
return $value->serializeToStream($output);
}
public static function makeTag($number, $type)
{
return ($number << 3) | self::getWireType($type);
}
public static function tagSize($field)
{
$tag = self::makeTag($field->getNumber(), $field->getType());
return self::varint32Size($tag);
}
public static function varint32Size($value, $sign_extended = false)
{
if ($value < 0) {
if ($sign_extended) {
return 10;
} else {
return 5;
}
}
if ($value < (1 << 7)) {
return 1;
}
if ($value < (1 << 14)) {
return 2;
}
if ($value < (1 << 21)) {
return 3;
}
if ($value < (1 << 28)) {
return 4;
}
return 5;
}
public static function sint32Size($value)
{
$value = self::zigZagEncode32($value);
return self::varint32Size($value);
}
public static function sint64Size($value)
{
$value = self::zigZagEncode64($value);
return self::varint64Size($value);
}
public static function varint64Size($value)
{
if (PHP_INT_SIZE == 4) {
if (bccomp($value, 0) < 0 ||
bccomp($value, "9223372036854775807") > 0) {
return 10;
}
if (bccomp($value, 1 << 7) < 0) {
return 1;
}
if (bccomp($value, 1 << 14) < 0) {
return 2;
}
if (bccomp($value, 1 << 21) < 0) {
return 3;
}
if (bccomp($value, 1 << 28) < 0) {
return 4;
}
if (bccomp($value, '34359738368') < 0) {
return 5;
}
if (bccomp($value, '4398046511104') < 0) {
return 6;
}
if (bccomp($value, '562949953421312') < 0) {
return 7;
}
if (bccomp($value, '72057594037927936') < 0) {
return 8;
}
return 9;
} else {
if ($value < 0) {
return 10;
}
if ($value < (1 << 7)) {
return 1;
}
if ($value < (1 << 14)) {
return 2;
}
if ($value < (1 << 21)) {
return 3;
}
if ($value < (1 << 28)) {
return 4;
}
if ($value < (1 << 35)) {
return 5;
}
if ($value < (1 << 42)) {
return 6;
}
if ($value < (1 << 49)) {
return 7;
}
if ($value < (1 << 56)) {
return 8;
}
return 9;
}
}
public static function serializeFieldToStream(
$value,
$field,
$need_tag,
&$output)
{
if ($need_tag) {
if (!GPBWire::writeTag(
$output,
self::makeTag(
$field->getNumber(),
$field->getType()))) {
return false;
}
}
switch ($field->getType()) {
case GPBType::DOUBLE:
if (!GPBWire::writeDouble($output, $value)) {
return false;
}
break;
case GPBType::FLOAT:
if (!GPBWire::writeFloat($output, $value)) {
return false;
}
break;
case GPBType::INT64:
if (!GPBWire::writeInt64($output, $value)) {
return false;
}
break;
case GPBType::UINT64:
if (!GPBWire::writeUint64($output, $value)) {
return false;
}
break;
case GPBType::INT32:
if (!GPBWire::writeInt32($output, $value)) {
return false;
}
break;
case GPBType::FIXED32:
if (!GPBWire::writeFixed32($output, $value)) {
return false;
}
break;
case GPBType::FIXED64:
if (!GPBWire::writeFixed64($output, $value)) {
return false;
}
break;
case GPBType::BOOL:
if (!GPBWire::writeBool($output, $value)) {
return false;
}
break;
case GPBType::STRING:
if (!GPBWire::writeString($output, $value)) {
return false;
}
break;
// case GPBType::GROUP:
// echo "GROUP\xA";
// trigger_error("Not implemented.", E_ERROR);
// break;
case GPBType::MESSAGE:
if (!GPBWire::writeMessage($output, $value)) {
return false;
}
break;
case GPBType::BYTES:
if (!GPBWire::writeBytes($output, $value)) {
return false;
}
break;
case GPBType::UINT32:
if (PHP_INT_SIZE === 8 && $value < 0) {
$value += 4294967296;
}
if (!GPBWire::writeUint32($output, $value)) {
return false;
}
break;
case GPBType::ENUM:
if (!GPBWire::writeInt32($output, $value)) {
return false;
}
break;
case GPBType::SFIXED32:
if (!GPBWire::writeSfixed32($output, $value)) {
return false;
}
break;
case GPBType::SFIXED64:
if (!GPBWire::writeSfixed64($output, $value)) {
return false;
}
break;
case GPBType::SINT32:
if (!GPBWire::writeSint32($output, $value)) {
return false;
}
break;
case GPBType::SINT64:
if (!GPBWire::writeSint64($output, $value)) {
return false;
}
break;
default:
user_error("Unsupported type.");
return false;
}
return true;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/**
* Defines Message, the parent class extended by all protocol message classes.
*/
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\CodedInputStream;
use Google\Protobuf\Internal\CodedOutputStream;
use Google\Protobuf\Internal\DescriptorPool;
use Google\Protobuf\Internal\GPBLabel;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\MapEntry;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\ListValue;
use Google\Protobuf\Value;
use Google\Protobuf\Struct;
use Google\Protobuf\NullValue;
/**
* 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.
*/
class Message
{
/**
* @ignore
*/
private $desc;
private $unknown = "";
/**
* @ignore
*/
public function __construct($data = NULL)
{
// MapEntry message is shared by all types of map fields, whose
// descriptors are different from each other. Thus, we cannot find a
// specific descriptor from the descriptor pool.
if ($this instanceof MapEntry) {
$this->initWithDescriptor($data);
} else {
$this->initWithGeneratedPool();
if (is_array($data)) {
$this->mergeFromArray($data);
} else if (!empty($data)) {
throw new \InvalidArgumentException(
'Message constructor must be an array or null.'
);
}
}
}
/**
* @ignore
*/
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");
}
}
}
}
/**
* @ignore
*/
private function initWithDescriptor(Descriptor $desc)
{
$this->desc = $desc;
foreach ($desc->getField() as $field) {
$setter = $field->getSetter();
$defaultValue = $this->defaultValue($field);
$this->$setter($defaultValue);
}
}
protected function readWrapperValue($member)
{
$field = $this->desc->getFieldByName($member);
$oneof_index = $field->getOneofIndex();
if ($oneof_index === -1) {
$wrapper = $this->$member;
} else {
$wrapper = $this->readOneof($field->getNumber());
}
if (is_null($wrapper)) {
return NULL;
} else {
return $wrapper->getValue();
}
}
protected function writeWrapperValue($member, $value)
{
$field = $this->desc->getFieldByName($member);
$wrapped_value = $value;
if (!is_null($value)) {
$desc = $field->getMessageType();
$klass = $desc->getClass();
$wrapped_value = new $klass;
$wrapped_value->setValue($value);
}
$oneof_index = $field->getOneofIndex();
if ($oneof_index === -1) {
$this->$member = $wrapped_value;
} else {
$this->writeOneof($field->getNumber(), $wrapped_value);
}
}
protected function readOneof($number)
{
$field = $this->desc->getFieldByNumber($number);
$oneof = $this->desc->getOneofDecl()[$field->getOneofIndex()];
$oneof_name = $oneof->getName();
$oneof_field = $this->$oneof_name;
if ($number === $oneof_field->getNumber()) {
return $oneof_field->getValue();
} else {
return $this->defaultValue($field);
}
}
protected function hasOneof($number)
{
$field = $this->desc->getFieldByNumber($number);
$oneof = $this->desc->getOneofDecl()[$field->getOneofIndex()];
$oneof_name = $oneof->getName();
$oneof_field = $this->$oneof_name;
return $number === $oneof_field->getNumber();
}
protected function writeOneof($number, $value)
{
$field = $this->desc->getFieldByNumber($number);
$oneof = $this->desc->getOneofDecl()[$field->getOneofIndex()];
$oneof_name = $oneof->getName();
if ($value === null) {
$this->$oneof_name = new OneofField($oneof);
} else {
$oneof_field = $this->$oneof_name;
$oneof_field->setValue($value);
$oneof_field->setFieldName($field->getName());
$oneof_field->setNumber($number);
}
}
protected function whichOneof($oneof_name)
{
$oneof_field = $this->$oneof_name;
$number = $oneof_field->getNumber();
if ($number == 0) {
return "";
}
$field = $this->desc->getFieldByNumber($number);
return $field->getName();
}
/**
* @ignore
*/
private function defaultValue($field)
{
$value = null;
switch ($field->getType()) {
case GPBType::DOUBLE:
case GPBType::FLOAT:
return 0.0;
case GPBType::UINT32:
case GPBType::INT32:
case GPBType::FIXED32:
case GPBType::SFIXED32:
case GPBType::SINT32:
case GPBType::ENUM:
return 0;
case GPBType::INT64:
case GPBType::UINT64:
case GPBType::FIXED64:
case GPBType::SFIXED64:
case GPBType::SINT64:
if (PHP_INT_SIZE === 4) {
return '0';
} else {
return 0;
}
case GPBType::BOOL:
return false;
case GPBType::STRING:
case GPBType::BYTES:
return "";
case GPBType::GROUP:
case GPBType::MESSAGE:
return null;
default:
user_error("Unsupported type.");
return false;
}
}
/**
* @ignore
*/
private function skipField($input, $tag)
{
$number = GPBWire::getTagFieldNumber($tag);
if ($number === 0) {
throw new GPBDecodeException("Illegal field number zero.");
}
$start = $input->current();
switch (GPBWire::getTagWireType($tag)) {
case GPBWireType::VARINT:
$uint64 = 0;
if (!$input->readVarint64($uint64)) {
throw new GPBDecodeException(
"Unexpected EOF inside varint.");
}
break;
case GPBWireType::FIXED64:
$uint64 = 0;
if (!$input->readLittleEndian64($uint64)) {
throw new GPBDecodeException(
"Unexpected EOF inside fixed64.");
}
break;
case GPBWireType::FIXED32:
$uint32 = 0;
if (!$input->readLittleEndian32($uint32)) {
throw new GPBDecodeException(
"Unexpected EOF inside fixed32.");
}
break;
case GPBWireType::LENGTH_DELIMITED:
$length = 0;
if (!$input->readVarint32($length)) {
throw new GPBDecodeException(
"Unexpected EOF inside length.");
}
$data = NULL;
if (!$input->readRaw($length, $data)) {
throw new GPBDecodeException(
"Unexpected EOF inside length delimited data.");
}
break;
case GPBWireType::START_GROUP:
case GPBWireType::END_GROUP:
throw new GPBDecodeException("Unexpected wire type.");
default:
throw new GPBDecodeException("Unexpected wire type.");
}
$end = $input->current();
$bytes = str_repeat(chr(0), CodedOutputStream::MAX_VARINT64_BYTES);
$size = CodedOutputStream::writeVarintToArray($tag, $bytes, true);
$this->unknown .= substr($bytes, 0, $size) . $input->substr($start, $end);
}
/**
* @ignore
*/
private static function parseFieldFromStreamNoTag($input, $field, &$value)
{
switch ($field->getType()) {
case GPBType::DOUBLE:
if (!GPBWire::readDouble($input, $value)) {
throw new GPBDecodeException(
"Unexpected EOF inside double field.");
}
break;
case GPBType::FLOAT:
if (!GPBWire::readFloat($input, $value)) {
throw new GPBDecodeException(
"Unexpected EOF inside float field.");
}
break;
case GPBType::INT64:
if (!GPBWire::readInt64($input, $value)) {
throw new GPBDecodeException(
"Unexpected EOF inside int64 field.");
}
break;
case GPBType::UINT64:
if (!GPBWire::readUint64($input, $value)) {
throw new GPBDecodeException(
"Unexpected EOF inside uint64 field.");
}
break;
case GPBType::INT32:
if (!GPBWire::readInt32($input, $value)) {
throw new GPBDecodeException(
"Unexpected EOF inside int32 field.");
}
break;
case GPBType::FIXED64:
if (!GPBWire::readFixed64($input, $value)) {
throw new GPBDecodeException(
"Unexpected EOF inside fixed64 field.");
}
break;
case GPBType::FIXED32:
if (!GPBWire::readFixed32($input, $value)) {
throw new GPBDecodeException(
"Unexpected EOF inside fixed32 field.");
}
break;
case GPBType::BOOL:
if (!GPBWire::readBool($input, $value)) {
throw new GPBDecodeException(
"Unexpected EOF inside bool field.");
}
break;
case GPBType::STRING:
// TODO(teboring): Add utf-8 check.
if (!GPBWire::readString($input, $value)) {
throw new GPBDecodeException(
"Unexpected EOF inside string field.");
}
break;
case GPBType::GROUP:
trigger_error("Not implemented.", E_USER_ERROR);
break;
case GPBType::MESSAGE:
if ($field->isMap()) {
$value = new MapEntry($field->getMessageType());
} else {
$klass = $field->getMessageType()->getClass();
$value = new $klass;
}
if (!GPBWire::readMessage($input, $value)) {
throw new GPBDecodeException(
"Unexpected EOF inside message.");
}
break;
case GPBType::BYTES:
if (!GPBWire::readString($input, $value)) {
throw new GPBDecodeException(
"Unexpected EOF inside bytes field.");
}
break;
case GPBType::UINT32:
if (!GPBWire::readUint32($input, $value)) {
throw new GPBDecodeException(
"Unexpected EOF inside uint32 field.");
}
break;
case GPBType::ENUM:
// TODO(teboring): Check unknown enum value.
if (!GPBWire::readInt32($input, $value)) {
throw new GPBDecodeException(
"Unexpected EOF inside enum field.");
}
break;
case GPBType::SFIXED32:
if (!GPBWire::readSfixed32($input, $value)) {
throw new GPBDecodeException(
"Unexpected EOF inside sfixed32 field.");
}
break;
case GPBType::SFIXED64:
if (!GPBWire::readSfixed64($input, $value)) {
throw new GPBDecodeException(
"Unexpected EOF inside sfixed64 field.");
}
break;
case GPBType::SINT32:
if (!GPBWire::readSint32($input, $value)) {
throw new GPBDecodeException(
"Unexpected EOF inside sint32 field.");
}
break;
case GPBType::SINT64:
if (!GPBWire::readSint64($input, $value)) {
throw new GPBDecodeException(
"Unexpected EOF inside sint64 field.");
}
break;
default:
user_error("Unsupported type.");
return false;
}
return true;
}
/**
* @ignore
*/
private function parseFieldFromStream($tag, $input, $field)
{
$value = null;
if (is_null($field)) {
$value_format = GPBWire::UNKNOWN;
} elseif (GPBWire::getTagWireType($tag) ===
GPBWire::getWireType($field->getType())) {
$value_format = GPBWire::NORMAL_FORMAT;
} elseif ($field->isPackable() &&
GPBWire::getTagWireType($tag) ===
GPBWire::WIRETYPE_LENGTH_DELIMITED) {
$value_format = GPBWire::PACKED_FORMAT;
} else {
// the wire type doesn't match. Put it in our unknown field set.
$value_format = GPBWire::UNKNOWN;
}
if ($value_format === GPBWire::UNKNOWN) {
$this->skipField($input, $tag);
return;
} elseif ($value_format === GPBWire::NORMAL_FORMAT) {
self::parseFieldFromStreamNoTag($input, $field, $value);
} elseif ($value_format === GPBWire::PACKED_FORMAT) {
$length = 0;
if (!GPBWire::readInt32($input, $length)) {
throw new GPBDecodeException(
"Unexpected EOF inside packed length.");
}
$limit = $input->pushLimit($length);
$getter = $field->getGetter();
while ($input->bytesUntilLimit() > 0) {
self::parseFieldFromStreamNoTag($input, $field, $value);
$this->appendHelper($field, $value);
}
$input->popLimit($limit);
return;
} else {
return;
}
if ($field->isMap()) {
$this->kvUpdateHelper($field, $value->getKey(), $value->getValue());
} else if ($field->isRepeated()) {
$this->appendHelper($field, $value);
} else {
$setter = $field->getSetter();
$this->$setter($value);
}
}
/**
* Clear all containing fields.
* @return null.
*/
public function clear()
{
$this->unknown = "";
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) {
switch ($field->getType()) {
case GPBType::DOUBLE :
case GPBType::FLOAT :
$this->$setter(0.0);
break;
case GPBType::INT32 :
case GPBType::FIXED32 :
case GPBType::UINT32 :
case GPBType::SFIXED32 :
case GPBType::SINT32 :
case GPBType::ENUM :
$this->$setter(0);
break;
case GPBType::BOOL :
$this->$setter(false);
break;
case GPBType::STRING :
case GPBType::BYTES :
$this->$setter("");
break;
case GPBType::GROUP :
case GPBType::MESSAGE :
$null = null;
$this->$setter($null);
break;
}
if (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");
}
} else {
switch ($field->getType()) {
case GPBType::INT64:
case GPBType::UINT64:
case GPBType::FIXED64:
case GPBType::SFIXED64:
case GPBType::SINT64:
$this->$setter(0);
}
}
}
}
}
/**
* Clear all unknown fields previously parsed.
* @return null.
*/
public function discardUnknownFields()
{
$this->unknown = "";
foreach ($this->desc->getField() as $field) {
if ($field->getType() != GPBType::MESSAGE) {
continue;
}
if ($field->isMap()) {
$value_field = $field->getMessageType()->getFieldByNumber(2);
if ($value_field->getType() != GPBType::MESSAGE) {
continue;
}
$getter = $field->getGetter();
$map = $this->$getter();
foreach ($map as $key => $value) {
$value->discardUnknownFields();
}
} else if ($field->getLabel() === GPBLabel::REPEATED) {
$getter = $field->getGetter();
$arr = $this->$getter();
foreach ($arr as $sub) {
$sub->discardUnknownFields();
}
} else if ($field->getLabel() === GPBLabel::OPTIONAL) {
$getter = $field->getGetter();
$sub = $this->$getter();
if (!is_null($sub)) {
$sub->discardUnknownFields();
}
}
}
}
/**
* Merges the contents of the specified message into current message.
*
* This method merges the contents of the specified message into the
* current message. Singular fields that are set in the specified message
* overwrite the corresponding fields in the current message. Repeated
* fields are appended. Map fields key-value pairs are overwritten.
* Singular/Oneof sub-messages are recursively merged. All overwritten
* sub-messages are deep-copied.
*
* @param object $msg Protobuf message to be merged from.
* @return null.
*/
public function mergeFrom($msg)
{
if (get_class($this) !== get_class($msg)) {
user_error("Cannot merge messages with different class.");
return;
}
foreach ($this->desc->getField() as $field) {
$setter = $field->getSetter();
$getter = $field->getGetter();
if ($field->isMap()) {
if (count($msg->$getter()) != 0) {
$value_field = $field->getMessageType()->getFieldByNumber(2);
foreach ($msg->$getter() as $key => $value) {
if ($value_field->getType() == GPBType::MESSAGE) {
$klass = $value_field->getMessageType()->getClass();
$copy = new $klass;
$copy->mergeFrom($value);
$this->kvUpdateHelper($field, $key, $copy);
} else {
$this->kvUpdateHelper($field, $key, $value);
}
}
}
} else if ($field->getLabel() === GPBLabel::REPEATED) {
if (count($msg->$getter()) != 0) {
foreach ($msg->$getter() as $tmp) {
if ($field->getType() == GPBType::MESSAGE) {
$klass = $field->getMessageType()->getClass();
$copy = new $klass;
$copy->mergeFrom($tmp);
$this->appendHelper($field, $copy);
} else {
$this->appendHelper($field, $tmp);
}
}
}
} else if ($field->getLabel() === GPBLabel::OPTIONAL) {
if($msg->$getter() !== $this->defaultValue($field)) {
$tmp = $msg->$getter();
if ($field->getType() == GPBType::MESSAGE) {
if (is_null($this->$getter())) {
$klass = $field->getMessageType()->getClass();
$new_msg = new $klass;
$this->$setter($new_msg);
}
$this->$getter()->mergeFrom($tmp);
} else {
$this->$setter($tmp);
}
}
}
}
}
/**
* Parses a protocol buffer contained in a string.
*
* This function takes a string in the (non-human-readable) binary wire
* format, matching the encoding output by serializeToString().
* See mergeFrom() for merging behavior, if the field is already set in the
* specified message.
*
* @param string $data Binary protobuf data.
* @return null.
* @throws \Exception Invalid data.
*/
public function mergeFromString($data)
{
$input = new CodedInputStream($data);
$this->parseFromStream($input);
}
/**
* Parses a json string to protobuf message.
*
* This function takes a string in the json wire format, matching the
* encoding output by serializeToJsonString().
* See mergeFrom() for merging behavior, if the field is already set in the
* specified message.
*
* @param string $data Json protobuf data.
* @return null.
* @throws \Exception Invalid data.
*/
public function mergeFromJsonString($data, $ignore_unknown = false)
{
$input = new RawInputStream($data);
$this->parseFromJsonStream($input, $ignore_unknown);
}
/**
* @ignore
*/
public function parseFromStream($input)
{
while (true) {
$tag = $input->readTag();
// End of input. This is a valid place to end, so return true.
if ($tag === 0) {
return true;
}
$number = GPBWire::getTagFieldNumber($tag);
$field = $this->desc->getFieldByNumber($number);
$this->parseFieldFromStream($tag, $input, $field);
}
}
private function convertJsonValueToProtoValue(
$value,
$field,
$ignore_unknown,
$is_map_key = false)
{
switch ($field->getType()) {
case GPBType::MESSAGE:
$klass = $field->getMessageType()->getClass();
$submsg = new $klass;
if (is_a($submsg, "Google\Protobuf\Duration")) {
if (is_null($value)) {
return $this->defaultValue($field);
} else if (!is_string($value)) {
throw new GPBDecodeException("Expect string.");
}
return GPBUtil::parseDuration($value);
} else if ($field->isTimestamp()) {
if (is_null($value)) {
return $this->defaultValue($field);
} else if (!is_string($value)) {
throw new GPBDecodeException("Expect string.");
}
try {
$timestamp = GPBUtil::parseTimestamp($value);
} catch (\Exception $e) {
throw new GPBDecodeException(
"Invalid RFC 3339 timestamp: ".$e->getMessage());
}
$submsg->setSeconds($timestamp->getSeconds());
$submsg->setNanos($timestamp->getNanos());
} else if (is_a($submsg, "Google\Protobuf\FieldMask")) {
if (is_null($value)) {
return $this->defaultValue($field);
}
try {
return GPBUtil::parseFieldMask($value);
} catch (\Exception $e) {
throw new GPBDecodeException(
"Invalid FieldMask: ".$e->getMessage());
}
} else {
if (is_null($value) &&
!is_a($submsg, "Google\Protobuf\Value")) {
return $this->defaultValue($field);
}
if (GPBUtil::hasSpecialJsonMapping($submsg)) {
} elseif (!is_object($value) && !is_array($value)) {
throw new GPBDecodeException("Expect message.");
}
$submsg->mergeFromJsonArray($value, $ignore_unknown);
}
return $submsg;
case GPBType::ENUM:
if (is_null($value)) {
return $this->defaultValue($field);
}
if (is_integer($value)) {
return $value;
}
$enum_value = $field->getEnumType()->getValueByName($value);
if (!is_null($enum_value)) {
return $enum_value->getNumber();
} else if ($ignore_unknown) {
return $this->defaultValue($field);
} else {
throw new GPBDecodeException(
"Enum field only accepts integer or enum value name");
}
case GPBType::STRING:
if (is_null($value)) {
return $this->defaultValue($field);
}
if (is_numeric($value)) {
return strval($value);
}
if (!is_string($value)) {
throw new GPBDecodeException(
"String field only accepts string value");
}
return $value;
case GPBType::BYTES:
if (is_null($value)) {
return $this->defaultValue($field);
}
if (!is_string($value)) {
throw new GPBDecodeException(
"Byte field only accepts string value");
}
$proto_value = base64_decode($value, true);
if ($proto_value === false) {
throw new GPBDecodeException("Invalid base64 characters");
}
return $proto_value;
case GPBType::BOOL:
if (is_null($value)) {
return $this->defaultValue($field);
}
if ($is_map_key) {
if ($value === "true") {
return true;
}
if ($value === "false") {
return false;
}
throw new GPBDecodeException(
"Bool field only accepts bool value");
}
if (!is_bool($value)) {
throw new GPBDecodeException(
"Bool field only accepts bool value");
}
return $value;
case GPBType::FLOAT:
case GPBType::DOUBLE:
if (is_null($value)) {
return $this->defaultValue($field);
}
if ($value === "Infinity") {
return INF;
}
if ($value === "-Infinity") {
return -INF;
}
if ($value === "NaN") {
return NAN;
}
return $value;
case GPBType::INT32:
case GPBType::SINT32:
case GPBType::SFIXED32:
if (is_null($value)) {
return $this->defaultValue($field);
}
if (!is_numeric($value)) {
throw new GPBDecodeException(
"Invalid data type for int32 field");
}
if (is_string($value) && trim($value) !== $value) {
throw new GPBDecodeException(
"Invalid data type for int32 field");
}
if (bccomp($value, "2147483647") > 0) {
throw new GPBDecodeException(
"Int32 too large");
}
if (bccomp($value, "-2147483648") < 0) {
throw new GPBDecodeException(
"Int32 too small");
}
return $value;
case GPBType::UINT32:
case GPBType::FIXED32:
if (is_null($value)) {
return $this->defaultValue($field);
}
if (!is_numeric($value)) {
throw new GPBDecodeException(
"Invalid data type for uint32 field");
}
if (is_string($value) && trim($value) !== $value) {
throw new GPBDecodeException(
"Invalid data type for int32 field");
}
if (bccomp($value, 4294967295) > 0) {
throw new GPBDecodeException(
"Uint32 too large");
}
return $value;
case GPBType::INT64:
case GPBType::SINT64:
case GPBType::SFIXED64:
if (is_null($value)) {
return $this->defaultValue($field);
}
if (!is_numeric($value)) {
throw new GPBDecodeException(
"Invalid data type for int64 field");
}
if (is_string($value) && trim($value) !== $value) {
throw new GPBDecodeException(
"Invalid data type for int64 field");
}
if (bccomp($value, "9223372036854775807") > 0) {
throw new GPBDecodeException(
"Int64 too large");
}
if (bccomp($value, "-9223372036854775808") < 0) {
throw new GPBDecodeException(
"Int64 too small");
}
return $value;
case GPBType::UINT64:
case GPBType::FIXED64:
if (is_null($value)) {
return $this->defaultValue($field);
}
if (!is_numeric($value)) {
throw new GPBDecodeException(
"Invalid data type for int64 field");
}
if (is_string($value) && trim($value) !== $value) {
throw new GPBDecodeException(
"Invalid data type for int64 field");
}
if (bccomp($value, "18446744073709551615") > 0) {
throw new GPBDecodeException(
"Uint64 too large");
}
if (bccomp($value, "9223372036854775807") > 0) {
$value = bcsub($value, "18446744073709551616");
}
return $value;
default:
return $value;
}
}
/**
* Populates the message from a user-supplied PHP array. Array keys
* correspond to Message properties and nested message properties.
*
* Example:
* ```
* $message->mergeFromArray([
* 'name' => 'This is a message name',
* 'interval' => [
* 'startTime' => time() - 60,
* 'endTime' => time(),
* ]
* ]);
* ```
*
* This method will trigger an error if it is passed data that cannot
* be converted to the correct type. For example, a StringValue field
* must receive data that is either a string or a StringValue object.
*
* @param array $array An array containing message properties and values.
* @return null.
*/
protected function mergeFromArray(array $array)
{
// Just call the setters for the field names
foreach ($array as $key => $value) {
$field = $this->desc->getFieldByName($key);
if (is_null($field)) {
throw new \UnexpectedValueException(
'Invalid message property: ' . $key);
}
$setter = $field->getSetter();
if ($field->isMap()) {
$valueField = $field->getMessageType()->getFieldByName('value');
if (!is_null($valueField) && $valueField->isWrapperType()) {
self::normalizeArrayElementsToMessageType($value, $valueField->getMessageType()->getClass());
}
} elseif ($field->isWrapperType()) {
$class = $field->getMessageType()->getClass();
if ($field->isRepeated()) {
self::normalizeArrayElementsToMessageType($value, $class);
} else {
self::normalizeToMessageType($value, $class);
}
}
$this->$setter($value);
}
}
/**
* Tries to normalize the elements in $value into a provided protobuf
* wrapper type $class. If $value is any type other than array, we do
* not do any conversion, and instead rely on the existing protobuf
* type checking. If $value is an array, we process each element and
* try to convert it to an instance of $class.
*
* @param mixed $value The array of values to normalize.
* @param string $class The expected wrapper class name
*/
private static function normalizeArrayElementsToMessageType(&$value, $class)
{
if (!is_array($value)) {
// In the case that $value is not an array, we do not want to
// attempt any conversion. Note that this includes the cases
// when $value is a RepeatedField of MapField. In those cases,
// we do not need to convert the elements, as they should
// already be the correct types.
return;
} else {
// Normalize each element in the array.
foreach ($value as $key => &$elementValue) {
self::normalizeToMessageType($elementValue, $class);
}
}
}
/**
* Tries to normalize $value into a provided protobuf wrapper type $class.
* If $value is any type other than an object, we attempt to construct an
* instance of $class and assign $value to it using the setValue method
* shared by all wrapper types.
*
* This method will raise an error if it receives a type that cannot be
* assigned to the wrapper type via setValue.
*
* @param mixed $value The value to normalize.
* @param string $class The expected wrapper class name
*/
private static function normalizeToMessageType(&$value, $class)
{
if (is_null($value) || is_object($value)) {
// This handles the case that $value is an instance of $class. We
// choose not to do any more strict checking here, relying on the
// existing type checking done by GPBUtil.
return;
} else {
// Try to instantiate $class and set the value
try {
$msg = new $class;
$msg->setValue($value);
$value = $msg;
return;
} catch (\Exception $exception) {
trigger_error(
"Error normalizing value to type '$class': " . $exception->getMessage(),
E_USER_ERROR
);
}
}
}
protected function mergeFromJsonArray($array, $ignore_unknown)
{
if (is_a($this, "Google\Protobuf\Any")) {
$this->clear();
$this->setTypeUrl($array["@type"]);
$msg = $this->unpack();
if (GPBUtil::hasSpecialJsonMapping($msg)) {
$msg->mergeFromJsonArray($array["value"], $ignore_unknown);
} else {
unset($array["@type"]);
$msg->mergeFromJsonArray($array, $ignore_unknown);
}
$this->setValue($msg->serializeToString());
return;
}
if (is_a($this, "Google\Protobuf\DoubleValue") ||
is_a($this, "Google\Protobuf\FloatValue") ||
is_a($this, "Google\Protobuf\Int64Value") ||
is_a($this, "Google\Protobuf\UInt64Value") ||
is_a($this, "Google\Protobuf\Int32Value") ||
is_a($this, "Google\Protobuf\UInt32Value") ||
is_a($this, "Google\Protobuf\BoolValue") ||
is_a($this, "Google\Protobuf\StringValue")) {
$this->setValue($array);
return;
}
if (is_a($this, "Google\Protobuf\BytesValue")) {
$this->setValue(base64_decode($array));
return;
}
if (is_a($this, "Google\Protobuf\Duration")) {
$this->mergeFrom(GPBUtil::parseDuration($array));
return;
}
if (is_a($this, "Google\Protobuf\FieldMask")) {
$this->mergeFrom(GPBUtil::parseFieldMask($array));
return;
}
if (is_a($this, "Google\Protobuf\Timestamp")) {
$this->mergeFrom(GPBUtil::parseTimestamp($array));
return;
}
if (is_a($this, "Google\Protobuf\Struct")) {
$fields = $this->getFields();
foreach($array as $key => $value) {
$v = new Value();
$v->mergeFromJsonArray($value, $ignore_unknown);
$fields[$key] = $v;
}
return;
}
if (is_a($this, "Google\Protobuf\Value")) {
if (is_bool($array)) {
$this->setBoolValue($array);
} elseif (is_string($array)) {
$this->setStringValue($array);
} elseif (is_null($array)) {
$this->setNullValue(0);
} elseif (is_double($array) || is_integer($array)) {
$this->setNumberValue($array);
} elseif (is_array($array)) {
if (array_values($array) !== $array) {
// Associative array
$struct_value = $this->getStructValue();
if (is_null($struct_value)) {
$struct_value = new Struct();
$this->setStructValue($struct_value);
}
foreach ($array as $key => $v) {
$value = new Value();
$value->mergeFromJsonArray($v, $ignore_unknown);
$values = $struct_value->getFields();
$values[$key]= $value;
}
} else {
// Array
$list_value = $this->getListValue();
if (is_null($list_value)) {
$list_value = new ListValue();
$this->setListValue($list_value);
}
foreach ($array as $v) {
$value = new Value();
$value->mergeFromJsonArray($v, $ignore_unknown);
$values = $list_value->getValues();
$values[]= $value;
}
}
} else {
throw new GPBDecodeException("Invalid type for Value.");
}
return;
}
$this->mergeFromArrayJsonImpl($array, $ignore_unknown);
}
private function mergeFromArrayJsonImpl($array, $ignore_unknown)
{
foreach ($array as $key => $value) {
$field = $this->desc->getFieldByJsonName($key);
if (is_null($field)) {
$field = $this->desc->getFieldByName($key);
if (is_null($field)) {
if ($ignore_unknown) {
continue;
} else {
throw new GPBDecodeException(
$key . ' is unknown.'
);
}
}
}
if ($field->isMap()) {
if (is_null($value)) {
continue;
}
$key_field = $field->getMessageType()->getFieldByNumber(1);
$value_field = $field->getMessageType()->getFieldByNumber(2);
foreach ($value as $tmp_key => $tmp_value) {
if (is_null($tmp_value)) {
throw new \Exception(
"Map value field element cannot be null.");
}
$proto_key = $this->convertJsonValueToProtoValue(
$tmp_key,
$key_field,
$ignore_unknown,
true);
$proto_value = $this->convertJsonValueToProtoValue(
$tmp_value,
$value_field,
$ignore_unknown);
self::kvUpdateHelper($field, $proto_key, $proto_value);
}
} else if ($field->isRepeated()) {
if (is_null($value)) {
continue;
}
foreach ($value as $tmp) {
if (is_null($tmp)) {
throw new \Exception(
"Repeated field elements cannot be null.");
}
$proto_value = $this->convertJsonValueToProtoValue(
$tmp,
$field,
$ignore_unknown);
self::appendHelper($field, $proto_value);
}
} else {
$setter = $field->getSetter();
$proto_value = $this->convertJsonValueToProtoValue(
$value,
$field,
$ignore_unknown);
if ($field->getType() === GPBType::MESSAGE) {
if (is_null($proto_value)) {
continue;
}
$getter = $field->getGetter();
$submsg = $this->$getter();
if (!is_null($submsg)) {
$submsg->mergeFrom($proto_value);
continue;
}
}
$this->$setter($proto_value);
}
}
}
/**
* @ignore
*/
public function parseFromJsonStream($input, $ignore_unknown)
{
$array = json_decode($input->getData(), true, 512, JSON_BIGINT_AS_STRING);
if ($this instanceof \Google\Protobuf\ListValue) {
$array = ["values"=>$array];
}
if (is_null($array)) {
if ($this instanceof \Google\Protobuf\Value) {
$this->setNullValue(\Google\Protobuf\NullValue::NULL_VALUE);
return;
} else {
throw new GPBDecodeException(
"Cannot decode json string: " . $input->getData());
}
}
try {
$this->mergeFromJsonArray($array, $ignore_unknown);
} catch (\Exception $e) {
throw new GPBDecodeException($e->getMessage());
}
}
/**
* @ignore
*/
private function serializeSingularFieldToStream($field, &$output)
{
if (!$this->existField($field)) {
return true;
}
$getter = $field->getGetter();
$value = $this->$getter();
if (!GPBWire::serializeFieldToStream($value, $field, true, $output)) {
return false;
}
return true;
}
/**
* @ignore
*/
private function serializeRepeatedFieldToStream($field, &$output)
{
$getter = $field->getGetter();
$values = $this->$getter();
$count = count($values);
if ($count === 0) {
return true;
}
$packed = $field->getPacked();
if ($packed) {
if (!GPBWire::writeTag(
$output,
GPBWire::makeTag($field->getNumber(), GPBType::STRING))) {
return false;
}
$size = 0;
foreach ($values as $value) {
$size += $this->fieldDataOnlyByteSize($field, $value);
}
if (!$output->writeVarint32($size, true)) {
return false;
}
}
foreach ($values as $value) {
if (!GPBWire::serializeFieldToStream(
$value,
$field,
!$packed,
$output)) {
return false;
}
}
return true;
}
/**
* @ignore
*/
private function serializeMapFieldToStream($field, $output)
{
$getter = $field->getGetter();
$values = $this->$getter();
$count = count($values);
if ($count === 0) {
return true;
}
foreach ($values as $key => $value) {
$map_entry = new MapEntry($field->getMessageType());
$map_entry->setKey($key);
$map_entry->setValue($value);
if (!GPBWire::serializeFieldToStream(
$map_entry,
$field,
true,
$output)) {
return false;
}
}
return true;
}
/**
* @ignore
*/
private function serializeFieldToStream(&$output, $field)
{
if ($field->isMap()) {
return $this->serializeMapFieldToStream($field, $output);
} elseif ($field->isRepeated()) {
return $this->serializeRepeatedFieldToStream($field, $output);
} else {
return $this->serializeSingularFieldToStream($field, $output);
}
}
/**
* @ignore
*/
private function serializeFieldToJsonStream(&$output, $field)
{
$getter = $field->getGetter();
$values = $this->$getter();
return GPBJsonWire::serializeFieldToStream(
$values, $field, $output, !GPBUtil::hasSpecialJsonMapping($this));
}
/**
* @ignore
*/
public function serializeToStream(&$output)
{
$fields = $this->desc->getField();
foreach ($fields as $field) {
if (!$this->serializeFieldToStream($output, $field)) {
return false;
}
}
$output->writeRaw($this->unknown, strlen($this->unknown));
return true;
}
/**
* @ignore
*/
public function serializeToJsonStream(&$output)
{
if (is_a($this, 'Google\Protobuf\Any')) {
$output->writeRaw("{", 1);
$type_field = $this->desc->getFieldByNumber(1);
$value_msg = $this->unpack();
// Serialize type url.
$output->writeRaw("\"@type\":", 8);
$output->writeRaw("\"", 1);
$output->writeRaw($this->getTypeUrl(), strlen($this->getTypeUrl()));
$output->writeRaw("\"", 1);
// Serialize value
if (GPBUtil::hasSpecialJsonMapping($value_msg)) {
$output->writeRaw(",\"value\":", 9);
$value_msg->serializeToJsonStream($output);
} else {
$value_fields = $value_msg->desc->getField();
foreach ($value_fields as $field) {
if ($value_msg->existField($field)) {
$output->writeRaw(",", 1);
if (!$value_msg->serializeFieldToJsonStream($output, $field)) {
return false;
}
}
}
}
$output->writeRaw("}", 1);
} elseif (is_a($this, 'Google\Protobuf\FieldMask')) {
$field_mask = GPBUtil::formatFieldMask($this);
$output->writeRaw("\"", 1);
$output->writeRaw($field_mask, strlen($field_mask));
$output->writeRaw("\"", 1);
} elseif (is_a($this, 'Google\Protobuf\Duration')) {
$duration = GPBUtil::formatDuration($this) . "s";
$output->writeRaw("\"", 1);
$output->writeRaw($duration, strlen($duration));
$output->writeRaw("\"", 1);
} elseif (get_class($this) === 'Google\Protobuf\Timestamp') {
$timestamp = GPBUtil::formatTimestamp($this);
$timestamp = json_encode($timestamp);
$output->writeRaw($timestamp, strlen($timestamp));
} elseif (get_class($this) === 'Google\Protobuf\ListValue') {
$field = $this->desc->getField()[1];
if (!$this->existField($field)) {
$output->writeRaw("[]", 2);
} else {
if (!$this->serializeFieldToJsonStream($output, $field)) {
return false;
}
}
} elseif (get_class($this) === 'Google\Protobuf\Struct') {
$field = $this->desc->getField()[1];
if (!$this->existField($field)) {
$output->writeRaw("{}", 2);
} else {
if (!$this->serializeFieldToJsonStream($output, $field)) {
return false;
}
}
} else {
if (!GPBUtil::hasSpecialJsonMapping($this)) {
$output->writeRaw("{", 1);
}
$fields = $this->desc->getField();
$first = true;
foreach ($fields as $field) {
if ($this->existField($field) ||
GPBUtil::hasJsonValue($this)) {
if ($first) {
$first = false;
} else {
$output->writeRaw(",", 1);
}
if (!$this->serializeFieldToJsonStream($output, $field)) {
return false;
}
}
}
if (!GPBUtil::hasSpecialJsonMapping($this)) {
$output->writeRaw("}", 1);
}
}
return true;
}
/**
* Serialize the message to string.
* @return string Serialized binary protobuf data.
*/
public function serializeToString()
{
$output = new CodedOutputStream($this->byteSize());
$this->serializeToStream($output);
return $output->getData();
}
/**
* Serialize the message to json string.
* @return string Serialized json protobuf data.
*/
public function serializeToJsonString()
{
$output = new CodedOutputStream($this->jsonByteSize());
$this->serializeToJsonStream($output);
return $output->getData();
}
/**
* @ignore
*/
private function existField($field)
{
$getter = $field->getGetter();
$hazzer = "has" . substr($getter, 3);
if (method_exists($this, $hazzer)) {
return $this->$hazzer();
} else if ($field->getOneofIndex() !== -1) {
// For old generated code, which does not have hazzers for oneof
// fields.
$oneof = $this->desc->getOneofDecl()[$field->getOneofIndex()];
$oneof_name = $oneof->getName();
return $this->$oneof_name->getNumber() === $field->getNumber();
}
$values = $this->$getter();
if ($field->isMap()) {
return count($values) !== 0;
} elseif ($field->isRepeated()) {
return count($values) !== 0;
} else {
return $values !== $this->defaultValue($field);
}
}
/**
* @ignore
*/
private function repeatedFieldDataOnlyByteSize($field)
{
$size = 0;
$getter = $field->getGetter();
$values = $this->$getter();
$count = count($values);
if ($count !== 0) {
$size += $count * GPBWire::tagSize($field);
foreach ($values as $value) {
$size += $this->singularFieldDataOnlyByteSize($field);
}
}
}
/**
* @ignore
*/
private function fieldDataOnlyByteSize($field, $value)
{
$size = 0;
switch ($field->getType()) {
case GPBType::BOOL:
$size += 1;
break;
case GPBType::FLOAT:
case GPBType::FIXED32:
case GPBType::SFIXED32:
$size += 4;
break;
case GPBType::DOUBLE:
case GPBType::FIXED64:
case GPBType::SFIXED64:
$size += 8;
break;
case GPBType::INT32:
case GPBType::ENUM:
$size += GPBWire::varint32Size($value, true);
break;
case GPBType::UINT32:
$size += GPBWire::varint32Size($value);
break;
case GPBType::UINT64:
case GPBType::INT64:
$size += GPBWire::varint64Size($value);
break;
case GPBType::SINT32:
$size += GPBWire::sint32Size($value);
break;
case GPBType::SINT64:
$size += GPBWire::sint64Size($value);
break;
case GPBType::STRING:
case GPBType::BYTES:
$size += strlen($value);
$size += GPBWire::varint32Size($size);
break;
case GPBType::MESSAGE:
$size += $value->byteSize();
$size += GPBWire::varint32Size($size);
break;
case GPBType::GROUP:
// TODO(teboring): Add support.
user_error("Unsupported type.");
break;
default:
user_error("Unsupported type.");
return 0;
}
return $size;
}
/**
* @ignore
*/
private function fieldDataOnlyJsonByteSize($field, $value)
{
$size = 0;
switch ($field->getType()) {
case GPBType::SFIXED32:
case GPBType::SINT32:
case GPBType::INT32:
$size += strlen(strval($value));
break;
case GPBType::FIXED32:
case GPBType::UINT32:
if ($value < 0) {
$value = bcadd($value, "4294967296");
}
$size += strlen(strval($value));
break;
case GPBType::FIXED64:
case GPBType::UINT64:
if ($value < 0) {
$value = bcadd($value, "18446744073709551616");
}
// Intentional fall through.
case GPBType::SFIXED64:
case GPBType::INT64:
case GPBType::SINT64:
$size += 2; // size for ""
$size += strlen(strval($value));
break;
case GPBType::FLOAT:
if (is_nan($value)) {
$size += strlen("NaN") + 2;
} elseif ($value === INF) {
$size += strlen("Infinity") + 2;
} elseif ($value === -INF) {
$size += strlen("-Infinity") + 2;
} else {
$size += strlen(sprintf("%.8g", $value));
}
break;
case GPBType::DOUBLE:
if (is_nan($value)) {
$size += strlen("NaN") + 2;
} elseif ($value === INF) {
$size += strlen("Infinity") + 2;
} elseif ($value === -INF) {
$size += strlen("-Infinity") + 2;
} else {
$size += strlen(sprintf("%.17g", $value));
}
break;
case GPBType::ENUM:
$enum_desc = $field->getEnumType();
if ($enum_desc->getClass() === "Google\Protobuf\NullValue") {
$size += 4;
break;
}
$enum_value_desc = $enum_desc->getValueByNumber($value);
if (!is_null($enum_value_desc)) {
$size += 2; // size for ""
$size += strlen($enum_value_desc->getName());
} else {
$str_value = strval($value);
$size += strlen($str_value);
}
break;
case GPBType::BOOL:
if ($value) {
$size += 4;
} else {
$size += 5;
}
break;
case GPBType::STRING:
$value = json_encode($value, JSON_UNESCAPED_UNICODE);
$size += strlen($value);
break;
case GPBType::BYTES:
# if (is_a($this, "Google\Protobuf\BytesValue")) {
# $size += strlen(json_encode($value));
# } else {
# $size += strlen(base64_encode($value));
# $size += 2; // size for \"\"
# }
$size += strlen(base64_encode($value));
$size += 2; // size for \"\"
break;
case GPBType::MESSAGE:
$size += $value->jsonByteSize();
break;
# case GPBType::GROUP:
# // TODO(teboring): Add support.
# user_error("Unsupported type.");
# break;
default:
user_error("Unsupported type " . $field->getType());
return 0;
}
return $size;
}
/**
* @ignore
*/
private function fieldByteSize($field)
{
$size = 0;
if ($field->isMap()) {
$getter = $field->getGetter();
$values = $this->$getter();
$count = count($values);
if ($count !== 0) {
$size += $count * GPBWire::tagSize($field);
$message_type = $field->getMessageType();
$key_field = $message_type->getFieldByNumber(1);
$value_field = $message_type->getFieldByNumber(2);
foreach ($values as $key => $value) {
$data_size = 0;
if ($key != $this->defaultValue($key_field)) {
$data_size += $this->fieldDataOnlyByteSize(
$key_field,
$key);
$data_size += GPBWire::tagSize($key_field);
}
if ($value != $this->defaultValue($value_field)) {
$data_size += $this->fieldDataOnlyByteSize(
$value_field,
$value);
$data_size += GPBWire::tagSize($value_field);
}
$size += GPBWire::varint32Size($data_size) + $data_size;
}
}
} elseif ($field->isRepeated()) {
$getter = $field->getGetter();
$values = $this->$getter();
$count = count($values);
if ($count !== 0) {
if ($field->getPacked()) {
$data_size = 0;
foreach ($values as $value) {
$data_size += $this->fieldDataOnlyByteSize($field, $value);
}
$size += GPBWire::tagSize($field);
$size += GPBWire::varint32Size($data_size);
$size += $data_size;
} else {
$size += $count * GPBWire::tagSize($field);
foreach ($values as $value) {
$size += $this->fieldDataOnlyByteSize($field, $value);
}
}
}
} elseif ($this->existField($field)) {
$size += GPBWire::tagSize($field);
$getter = $field->getGetter();
$value = $this->$getter();
$size += $this->fieldDataOnlyByteSize($field, $value);
}
return $size;
}
/**
* @ignore
*/
private function fieldJsonByteSize($field)
{
$size = 0;
if ($field->isMap()) {
$getter = $field->getGetter();
$values = $this->$getter();
$count = count($values);
if ($count !== 0) {
if (!GPBUtil::hasSpecialJsonMapping($this)) {
$size += 3; // size for "\"\":".
$size += strlen($field->getJsonName()); // size for field name
}
$size += 2; // size for "{}".
$size += $count - 1; // size for commas
$getter = $field->getGetter();
$map_entry = $field->getMessageType();
$key_field = $map_entry->getFieldByNumber(1);
$value_field = $map_entry->getFieldByNumber(2);
switch ($key_field->getType()) {
case GPBType::STRING:
case GPBType::SFIXED64:
case GPBType::INT64:
case GPBType::SINT64:
case GPBType::FIXED64:
case GPBType::UINT64:
$additional_quote = false;
break;
default:
$additional_quote = true;
}
foreach ($values as $key => $value) {
if ($additional_quote) {
$size += 2; // size for ""
}
$size += $this->fieldDataOnlyJsonByteSize($key_field, $key);
$size += $this->fieldDataOnlyJsonByteSize($value_field, $value);
$size += 1; // size for :
}
}
} elseif ($field->isRepeated()) {
$getter = $field->getGetter();
$values = $this->$getter();
$count = count($values);
if ($count !== 0) {
if (!GPBUtil::hasSpecialJsonMapping($this)) {
$size += 3; // size for "\"\":".
$size += strlen($field->getJsonName()); // size for field name
}
$size += 2; // size for "[]".
$size += $count - 1; // size for commas
$getter = $field->getGetter();
foreach ($values as $value) {
$size += $this->fieldDataOnlyJsonByteSize($field, $value);
}
}
} elseif ($this->existField($field) || GPBUtil::hasJsonValue($this)) {
if (!GPBUtil::hasSpecialJsonMapping($this)) {
$size += 3; // size for "\"\":".
$size += strlen($field->getJsonName()); // size for field name
}
$getter = $field->getGetter();
$value = $this->$getter();
$size += $this->fieldDataOnlyJsonByteSize($field, $value);
}
return $size;
}
/**
* @ignore
*/
public function byteSize()
{
$size = 0;
$fields = $this->desc->getField();
foreach ($fields as $field) {
$size += $this->fieldByteSize($field);
}
$size += strlen($this->unknown);
return $size;
}
private function appendHelper($field, $append_value)
{
$getter = $field->getGetter();
$setter = $field->getSetter();
$field_arr_value = $this->$getter();
$field_arr_value[] = $append_value;
if (!is_object($field_arr_value)) {
$this->$setter($field_arr_value);
}
}
private function kvUpdateHelper($field, $update_key, $update_value)
{
$getter = $field->getGetter();
$setter = $field->getSetter();
$field_arr_value = $this->$getter();
$field_arr_value[$update_key] = $update_value;
if (!is_object($field_arr_value)) {
$this->$setter($field_arr_value);
}
}
/**
* @ignore
*/
public function jsonByteSize()
{
$size = 0;
if (is_a($this, 'Google\Protobuf\Any')) {
// Size for "{}".
$size += 2;
// Size for "\"@type\":".
$size += 8;
// Size for url. +2 for "" /.
$size += strlen($this->getTypeUrl()) + 2;
$value_msg = $this->unpack();
if (GPBUtil::hasSpecialJsonMapping($value_msg)) {
// Size for "\",value\":".
$size += 9;
$size += $value_msg->jsonByteSize();
} else {
// Size for value. +1 for comma, -2 for "{}".
$size += $value_msg->jsonByteSize() -1;
}
} elseif (get_class($this) === 'Google\Protobuf\FieldMask') {
$field_mask = GPBUtil::formatFieldMask($this);
$size += strlen($field_mask) + 2; // 2 for ""
} elseif (get_class($this) === 'Google\Protobuf\Duration') {
$duration = GPBUtil::formatDuration($this) . "s";
$size += strlen($duration) + 2; // 2 for ""
} elseif (get_class($this) === 'Google\Protobuf\Timestamp') {
$timestamp = GPBUtil::formatTimestamp($this);
$timestamp = json_encode($timestamp);
$size += strlen($timestamp);
} elseif (get_class($this) === 'Google\Protobuf\ListValue') {
$field = $this->desc->getField()[1];
if ($this->existField($field)) {
$field_size = $this->fieldJsonByteSize($field);
$size += $field_size;
} else {
// Size for "[]".
$size += 2;
}
} elseif (get_class($this) === 'Google\Protobuf\Struct') {
$field = $this->desc->getField()[1];
if ($this->existField($field)) {
$field_size = $this->fieldJsonByteSize($field);
$size += $field_size;
} else {
// Size for "{}".
$size += 2;
}
} else {
if (!GPBUtil::hasSpecialJsonMapping($this)) {
// Size for "{}".
$size += 2;
}
$fields = $this->desc->getField();
$count = 0;
foreach ($fields as $field) {
$field_size = $this->fieldJsonByteSize($field);
$size += $field_size;
if ($field_size != 0) {
$count++;
}
}
// size for comma
$size += $count > 0 ? ($count - 1) : 0;
}
return $size;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
trait HasPublicDescriptorTrait
{
private $public_desc;
public function getPublicDescriptor()
{
return $this->public_desc;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
if (false) {
/**
* This class is deprecated. Use Google\Protobuf\Internal\SourceCodeInfo\Location instead.
* @deprecated
*/
class SourceCodeInfo_Location {}
}
class_exists(SourceCodeInfo\Location::class);
@trigger_error('Google\Protobuf\Internal\SourceCodeInfo_Location is deprecated and will be removed in the next major release. Use Google\Protobuf\Internal\SourceCodeInfo\Location instead', E_USER_DEPRECATED);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Google\Protobuf\Internal;
use Google\Protobuf\EnumValueDescriptor;
class EnumDescriptor
{
use HasPublicDescriptorTrait;
private $klass;
private $legacy_klass;
private $full_name;
private $value;
private $name_to_value;
private $value_descriptor = [];
public function __construct()
{
$this->public_desc = new \Google\Protobuf\EnumDescriptor($this);
}
public function setFullName($full_name)
{
$this->full_name = $full_name;
}
public function getFullName()
{
return $this->full_name;
}
public function addValue($number, $value)
{
$this->value[$number] = $value;
$this->name_to_value[$value->getName()] = $value;
$this->value_descriptor[] = new EnumValueDescriptor($value->getName(), $number);
}
public function getValueByNumber($number)
{
if (isset($this->value[$number])) {
return $this->value[$number];
}
return null;
}
public function getValueByName($name)
{
if (isset($this->name_to_value[$name])) {
return $this->name_to_value[$name];
}
return null;
}
public function getValueDescriptorByIndex($index)
{
if (isset($this->value_descriptor[$index])) {
return $this->value_descriptor[$index];
}
return null;
}
public function getValueCount()
{
return count($this->value);
}
public function setClass($klass)
{
$this->klass = $klass;
}
public function getClass()
{
return $this->klass;
}
public function setLegacyClass($klass)
{
$this->legacy_klass = $klass;
}
public function getLegacyClass()
{
return $this->legacy_klass;
}
public static function buildFromProto($proto, $file_proto, $containing)
{
$desc = new EnumDescriptor();
$enum_name_without_package = "";
$classname = "";
$legacy_classname = "";
$fullname = "";
GPBUtil::getFullClassName(
$proto,
$containing,
$file_proto,
$enum_name_without_package,
$classname,
$legacy_classname,
$fullname,
$unused_previous_classname);
$desc->setFullName($fullname);
$desc->setClass($classname);
$desc->setLegacyClass($legacy_classname);
$values = $proto->getValue();
foreach ($values as $value) {
$desc->addValue($value->getNumber(), $value);
}
return $desc;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Describes a value within an enum.
*
* Generated from protobuf message <code>google.protobuf.EnumValueDescriptorProto</code>
*/
class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message
{
/**
* Generated from protobuf field <code>optional string name = 1;</code>
*/
protected $name = null;
/**
* Generated from protobuf field <code>optional int32 number = 2;</code>
*/
protected $number = null;
/**
* Generated from protobuf field <code>optional .google.protobuf.EnumValueOptions options = 3;</code>
*/
protected $options = null;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type string $name
* @type int $number
* @type \Google\Protobuf\Internal\EnumValueOptions $options
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Generated from protobuf field <code>optional string name = 1;</code>
* @return string
*/
public function getName()
{
return isset($this->name) ? $this->name : '';
}
public function hasName()
{
return isset($this->name);
}
public function clearName()
{
unset($this->name);
}
/**
* Generated from protobuf field <code>optional string name = 1;</code>
* @param string $var
* @return $this
*/
public function setName($var)
{
GPBUtil::checkString($var, True);
$this->name = $var;
return $this;
}
/**
* Generated from protobuf field <code>optional int32 number = 2;</code>
* @return int
*/
public function getNumber()
{
return isset($this->number) ? $this->number : 0;
}
public function hasNumber()
{
return isset($this->number);
}
public function clearNumber()
{
unset($this->number);
}
/**
* Generated from protobuf field <code>optional int32 number = 2;</code>
* @param int $var
* @return $this
*/
public function setNumber($var)
{
GPBUtil::checkInt32($var);
$this->number = $var;
return $this;
}
/**
* Generated from protobuf field <code>optional .google.protobuf.EnumValueOptions options = 3;</code>
* @return \Google\Protobuf\Internal\EnumValueOptions|null
*/
public function getOptions()
{
return $this->options;
}
public function hasOptions()
{
return isset($this->options);
}
public function clearOptions()
{
unset($this->options);
}
/**
* Generated from protobuf field <code>optional .google.protobuf.EnumValueOptions options = 3;</code>
* @param \Google\Protobuf\Internal\EnumValueOptions $var
* @return $this
*/
public function setOptions($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumValueOptions::class);
$this->options = $var;
return $this;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>google.protobuf.EnumValueOptions</code>
*/
class EnumValueOptions extends \Google\Protobuf\Internal\Message
{
/**
* Is this enum value deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum value, or it will be completely ignored; in the very least,
* this is a formalization for deprecating enum values.
*
* Generated from protobuf field <code>optional bool deprecated = 1 [default = false];</code>
*/
protected $deprecated = null;
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
*/
private $uninterpreted_option;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type bool $deprecated
* Is this enum value deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum value, or it will be completely ignored; in the very least,
* this is a formalization for deprecating enum values.
* @type array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $uninterpreted_option
* The parser stores options it doesn't recognize here. See above.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Is this enum value deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum value, or it will be completely ignored; in the very least,
* this is a formalization for deprecating enum values.
*
* Generated from protobuf field <code>optional bool deprecated = 1 [default = false];</code>
* @return bool
*/
public function getDeprecated()
{
return isset($this->deprecated) ? $this->deprecated : false;
}
public function hasDeprecated()
{
return isset($this->deprecated);
}
public function clearDeprecated()
{
unset($this->deprecated);
}
/**
* Is this enum value deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum value, or it will be completely ignored; in the very least,
* this is a formalization for deprecating enum values.
*
* Generated from protobuf field <code>optional bool deprecated = 1 [default = false];</code>
* @param bool $var
* @return $this
*/
public function setDeprecated($var)
{
GPBUtil::checkBool($var);
$this->deprecated = $var;
return $this;
}
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getUninterpretedOption()
{
return $this->uninterpreted_option;
}
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @param array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setUninterpretedOption($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $arr;
return $this;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
class OneofField
{
private $desc;
private $field_name;
private $number = 0;
private $value;
public function __construct($desc)
{
$this->desc = $desc;
}
public function setValue($value)
{
$this->value = $value;
}
public function getValue()
{
return $this->value;
}
public function setFieldName($field_name)
{
$this->field_name = $field_name;
}
public function getFieldName()
{
return $this->field_name;
}
public function setNumber($number)
{
$this->number = $number;
}
public function getNumber()
{
return $this->number;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>google.protobuf.ServiceOptions</code>
*/
class ServiceOptions extends \Google\Protobuf\Internal\Message
{
/**
* Is this service deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the service, or it will be completely ignored; in the very least,
* this is a formalization for deprecating services.
*
* Generated from protobuf field <code>optional bool deprecated = 33 [default = false];</code>
*/
protected $deprecated = null;
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
*/
private $uninterpreted_option;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type bool $deprecated
* Is this service deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the service, or it will be completely ignored; in the very least,
* this is a formalization for deprecating services.
* @type array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $uninterpreted_option
* The parser stores options it doesn't recognize here. See above.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Is this service deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the service, or it will be completely ignored; in the very least,
* this is a formalization for deprecating services.
*
* Generated from protobuf field <code>optional bool deprecated = 33 [default = false];</code>
* @return bool
*/
public function getDeprecated()
{
return isset($this->deprecated) ? $this->deprecated : false;
}
public function hasDeprecated()
{
return isset($this->deprecated);
}
public function clearDeprecated()
{
unset($this->deprecated);
}
/**
* Is this service deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the service, or it will be completely ignored; in the very least,
* this is a formalization for deprecating services.
*
* Generated from protobuf field <code>optional bool deprecated = 33 [default = false];</code>
* @param bool $var
* @return $this
*/
public function setDeprecated($var)
{
GPBUtil::checkBool($var);
$this->deprecated = $var;
return $this;
}
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getUninterpretedOption()
{
return $this->uninterpreted_option;
}
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @param array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setUninterpretedOption($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $arr;
return $this;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>google.protobuf.FieldOptions</code>
*/
class FieldOptions extends \Google\Protobuf\Internal\Message
{
/**
* The ctype option instructs the C++ code generator to use a different
* representation of the field than it normally would. See the specific
* options below. This option is not yet implemented in the open source
* release -- sorry, we'll try to include it in a future version!
*
* Generated from protobuf field <code>optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];</code>
*/
protected $ctype = null;
/**
* The packed option can be enabled for repeated primitive fields to enable
* a more efficient representation on the wire. Rather than repeatedly
* writing the tag and type for each element, the entire array is encoded as
* a single length-delimited blob. In proto3, only explicit setting it to
* false will avoid using packed encoding.
*
* Generated from protobuf field <code>optional bool packed = 2;</code>
*/
protected $packed = null;
/**
* The jstype option determines the JavaScript type used for values of the
* field. The option is permitted only for 64 bit integral and fixed types
* (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING
* is represented as JavaScript string, which avoids loss of precision that
* can happen when a large value is converted to a floating point JavaScript.
* Specifying JS_NUMBER for the jstype causes the generated JavaScript code to
* use the JavaScript "number" type. The behavior of the default option
* JS_NORMAL is implementation dependent.
* This option is an enum to permit additional types to be added, e.g.
* goog.math.Integer.
*
* Generated from protobuf field <code>optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];</code>
*/
protected $jstype = null;
/**
* Should this field be parsed lazily? Lazy applies only to message-type
* fields. It means that when the outer message is initially parsed, the
* inner message's contents will not be parsed but instead stored in encoded
* form. The inner message will actually be parsed when it is first accessed.
* This is only a hint. Implementations are free to choose whether to use
* eager or lazy parsing regardless of the value of this option. However,
* setting this option true suggests that the protocol author believes that
* using lazy parsing on this field is worth the additional bookkeeping
* overhead typically needed to implement it.
* This option does not affect the public interface of any generated code;
* all method signatures remain the same. Furthermore, thread-safety of the
* interface is not affected by this option; const methods remain safe to
* call from multiple threads concurrently, while non-const methods continue
* to require exclusive access.
* Note that implementations may choose not to check required fields within
* a lazy sub-message. That is, calling IsInitialized() on the outer message
* may return true even if the inner message has missing required fields.
* This is necessary because otherwise the inner message would have to be
* parsed in order to perform the check, defeating the purpose of lazy
* parsing. An implementation which chooses not to check required fields
* must be consistent about it. That is, for any particular sub-message, the
* implementation must either *always* check its required fields, or *never*
* check its required fields, regardless of whether or not the message has
* been parsed.
* As of 2021, lazy does no correctness checks on the byte stream during
* parsing. This may lead to crashes if and when an invalid byte stream is
* finally parsed upon access.
* TODO(b/211906113): Enable validation on lazy fields.
*
* Generated from protobuf field <code>optional bool lazy = 5 [default = false];</code>
*/
protected $lazy = null;
/**
* unverified_lazy does no correctness checks on the byte stream. This should
* only be used where lazy with verification is prohibitive for performance
* reasons.
*
* Generated from protobuf field <code>optional bool unverified_lazy = 15 [default = false];</code>
*/
protected $unverified_lazy = null;
/**
* Is this field deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for accessors, or it will be completely ignored; in the very least, this
* is a formalization for deprecating fields.
*
* Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code>
*/
protected $deprecated = null;
/**
* For Google-internal migration only. Do not use.
*
* Generated from protobuf field <code>optional bool weak = 10 [default = false];</code>
*/
protected $weak = null;
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
*/
private $uninterpreted_option;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type int $ctype
* The ctype option instructs the C++ code generator to use a different
* representation of the field than it normally would. See the specific
* options below. This option is not yet implemented in the open source
* release -- sorry, we'll try to include it in a future version!
* @type bool $packed
* The packed option can be enabled for repeated primitive fields to enable
* a more efficient representation on the wire. Rather than repeatedly
* writing the tag and type for each element, the entire array is encoded as
* a single length-delimited blob. In proto3, only explicit setting it to
* false will avoid using packed encoding.
* @type int $jstype
* The jstype option determines the JavaScript type used for values of the
* field. The option is permitted only for 64 bit integral and fixed types
* (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING
* is represented as JavaScript string, which avoids loss of precision that
* can happen when a large value is converted to a floating point JavaScript.
* Specifying JS_NUMBER for the jstype causes the generated JavaScript code to
* use the JavaScript "number" type. The behavior of the default option
* JS_NORMAL is implementation dependent.
* This option is an enum to permit additional types to be added, e.g.
* goog.math.Integer.
* @type bool $lazy
* Should this field be parsed lazily? Lazy applies only to message-type
* fields. It means that when the outer message is initially parsed, the
* inner message's contents will not be parsed but instead stored in encoded
* form. The inner message will actually be parsed when it is first accessed.
* This is only a hint. Implementations are free to choose whether to use
* eager or lazy parsing regardless of the value of this option. However,
* setting this option true suggests that the protocol author believes that
* using lazy parsing on this field is worth the additional bookkeeping
* overhead typically needed to implement it.
* This option does not affect the public interface of any generated code;
* all method signatures remain the same. Furthermore, thread-safety of the
* interface is not affected by this option; const methods remain safe to
* call from multiple threads concurrently, while non-const methods continue
* to require exclusive access.
* Note that implementations may choose not to check required fields within
* a lazy sub-message. That is, calling IsInitialized() on the outer message
* may return true even if the inner message has missing required fields.
* This is necessary because otherwise the inner message would have to be
* parsed in order to perform the check, defeating the purpose of lazy
* parsing. An implementation which chooses not to check required fields
* must be consistent about it. That is, for any particular sub-message, the
* implementation must either *always* check its required fields, or *never*
* check its required fields, regardless of whether or not the message has
* been parsed.
* As of 2021, lazy does no correctness checks on the byte stream during
* parsing. This may lead to crashes if and when an invalid byte stream is
* finally parsed upon access.
* TODO(b/211906113): Enable validation on lazy fields.
* @type bool $unverified_lazy
* unverified_lazy does no correctness checks on the byte stream. This should
* only be used where lazy with verification is prohibitive for performance
* reasons.
* @type bool $deprecated
* Is this field deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for accessors, or it will be completely ignored; in the very least, this
* is a formalization for deprecating fields.
* @type bool $weak
* For Google-internal migration only. Do not use.
* @type array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $uninterpreted_option
* The parser stores options it doesn't recognize here. See above.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* The ctype option instructs the C++ code generator to use a different
* representation of the field than it normally would. See the specific
* options below. This option is not yet implemented in the open source
* release -- sorry, we'll try to include it in a future version!
*
* Generated from protobuf field <code>optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];</code>
* @return int
*/
public function getCtype()
{
return isset($this->ctype) ? $this->ctype : 0;
}
public function hasCtype()
{
return isset($this->ctype);
}
public function clearCtype()
{
unset($this->ctype);
}
/**
* The ctype option instructs the C++ code generator to use a different
* representation of the field than it normally would. See the specific
* options below. This option is not yet implemented in the open source
* release -- sorry, we'll try to include it in a future version!
*
* Generated from protobuf field <code>optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];</code>
* @param int $var
* @return $this
*/
public function setCtype($var)
{
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldOptions\CType::class);
$this->ctype = $var;
return $this;
}
/**
* The packed option can be enabled for repeated primitive fields to enable
* a more efficient representation on the wire. Rather than repeatedly
* writing the tag and type for each element, the entire array is encoded as
* a single length-delimited blob. In proto3, only explicit setting it to
* false will avoid using packed encoding.
*
* Generated from protobuf field <code>optional bool packed = 2;</code>
* @return bool
*/
public function getPacked()
{
return isset($this->packed) ? $this->packed : false;
}
public function hasPacked()
{
return isset($this->packed);
}
public function clearPacked()
{
unset($this->packed);
}
/**
* The packed option can be enabled for repeated primitive fields to enable
* a more efficient representation on the wire. Rather than repeatedly
* writing the tag and type for each element, the entire array is encoded as
* a single length-delimited blob. In proto3, only explicit setting it to
* false will avoid using packed encoding.
*
* Generated from protobuf field <code>optional bool packed = 2;</code>
* @param bool $var
* @return $this
*/
public function setPacked($var)
{
GPBUtil::checkBool($var);
$this->packed = $var;
return $this;
}
/**
* The jstype option determines the JavaScript type used for values of the
* field. The option is permitted only for 64 bit integral and fixed types
* (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING
* is represented as JavaScript string, which avoids loss of precision that
* can happen when a large value is converted to a floating point JavaScript.
* Specifying JS_NUMBER for the jstype causes the generated JavaScript code to
* use the JavaScript "number" type. The behavior of the default option
* JS_NORMAL is implementation dependent.
* This option is an enum to permit additional types to be added, e.g.
* goog.math.Integer.
*
* Generated from protobuf field <code>optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];</code>
* @return int
*/
public function getJstype()
{
return isset($this->jstype) ? $this->jstype : 0;
}
public function hasJstype()
{
return isset($this->jstype);
}
public function clearJstype()
{
unset($this->jstype);
}
/**
* The jstype option determines the JavaScript type used for values of the
* field. The option is permitted only for 64 bit integral and fixed types
* (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING
* is represented as JavaScript string, which avoids loss of precision that
* can happen when a large value is converted to a floating point JavaScript.
* Specifying JS_NUMBER for the jstype causes the generated JavaScript code to
* use the JavaScript "number" type. The behavior of the default option
* JS_NORMAL is implementation dependent.
* This option is an enum to permit additional types to be added, e.g.
* goog.math.Integer.
*
* Generated from protobuf field <code>optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];</code>
* @param int $var
* @return $this
*/
public function setJstype($var)
{
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldOptions\JSType::class);
$this->jstype = $var;
return $this;
}
/**
* Should this field be parsed lazily? Lazy applies only to message-type
* fields. It means that when the outer message is initially parsed, the
* inner message's contents will not be parsed but instead stored in encoded
* form. The inner message will actually be parsed when it is first accessed.
* This is only a hint. Implementations are free to choose whether to use
* eager or lazy parsing regardless of the value of this option. However,
* setting this option true suggests that the protocol author believes that
* using lazy parsing on this field is worth the additional bookkeeping
* overhead typically needed to implement it.
* This option does not affect the public interface of any generated code;
* all method signatures remain the same. Furthermore, thread-safety of the
* interface is not affected by this option; const methods remain safe to
* call from multiple threads concurrently, while non-const methods continue
* to require exclusive access.
* Note that implementations may choose not to check required fields within
* a lazy sub-message. That is, calling IsInitialized() on the outer message
* may return true even if the inner message has missing required fields.
* This is necessary because otherwise the inner message would have to be
* parsed in order to perform the check, defeating the purpose of lazy
* parsing. An implementation which chooses not to check required fields
* must be consistent about it. That is, for any particular sub-message, the
* implementation must either *always* check its required fields, or *never*
* check its required fields, regardless of whether or not the message has
* been parsed.
* As of 2021, lazy does no correctness checks on the byte stream during
* parsing. This may lead to crashes if and when an invalid byte stream is
* finally parsed upon access.
* TODO(b/211906113): Enable validation on lazy fields.
*
* Generated from protobuf field <code>optional bool lazy = 5 [default = false];</code>
* @return bool
*/
public function getLazy()
{
return isset($this->lazy) ? $this->lazy : false;
}
public function hasLazy()
{
return isset($this->lazy);
}
public function clearLazy()
{
unset($this->lazy);
}
/**
* Should this field be parsed lazily? Lazy applies only to message-type
* fields. It means that when the outer message is initially parsed, the
* inner message's contents will not be parsed but instead stored in encoded
* form. The inner message will actually be parsed when it is first accessed.
* This is only a hint. Implementations are free to choose whether to use
* eager or lazy parsing regardless of the value of this option. However,
* setting this option true suggests that the protocol author believes that
* using lazy parsing on this field is worth the additional bookkeeping
* overhead typically needed to implement it.
* This option does not affect the public interface of any generated code;
* all method signatures remain the same. Furthermore, thread-safety of the
* interface is not affected by this option; const methods remain safe to
* call from multiple threads concurrently, while non-const methods continue
* to require exclusive access.
* Note that implementations may choose not to check required fields within
* a lazy sub-message. That is, calling IsInitialized() on the outer message
* may return true even if the inner message has missing required fields.
* This is necessary because otherwise the inner message would have to be
* parsed in order to perform the check, defeating the purpose of lazy
* parsing. An implementation which chooses not to check required fields
* must be consistent about it. That is, for any particular sub-message, the
* implementation must either *always* check its required fields, or *never*
* check its required fields, regardless of whether or not the message has
* been parsed.
* As of 2021, lazy does no correctness checks on the byte stream during
* parsing. This may lead to crashes if and when an invalid byte stream is
* finally parsed upon access.
* TODO(b/211906113): Enable validation on lazy fields.
*
* Generated from protobuf field <code>optional bool lazy = 5 [default = false];</code>
* @param bool $var
* @return $this
*/
public function setLazy($var)
{
GPBUtil::checkBool($var);
$this->lazy = $var;
return $this;
}
/**
* unverified_lazy does no correctness checks on the byte stream. This should
* only be used where lazy with verification is prohibitive for performance
* reasons.
*
* Generated from protobuf field <code>optional bool unverified_lazy = 15 [default = false];</code>
* @return bool
*/
public function getUnverifiedLazy()
{
return isset($this->unverified_lazy) ? $this->unverified_lazy : false;
}
public function hasUnverifiedLazy()
{
return isset($this->unverified_lazy);
}
public function clearUnverifiedLazy()
{
unset($this->unverified_lazy);
}
/**
* unverified_lazy does no correctness checks on the byte stream. This should
* only be used where lazy with verification is prohibitive for performance
* reasons.
*
* Generated from protobuf field <code>optional bool unverified_lazy = 15 [default = false];</code>
* @param bool $var
* @return $this
*/
public function setUnverifiedLazy($var)
{
GPBUtil::checkBool($var);
$this->unverified_lazy = $var;
return $this;
}
/**
* Is this field deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for accessors, or it will be completely ignored; in the very least, this
* is a formalization for deprecating fields.
*
* Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code>
* @return bool
*/
public function getDeprecated()
{
return isset($this->deprecated) ? $this->deprecated : false;
}
public function hasDeprecated()
{
return isset($this->deprecated);
}
public function clearDeprecated()
{
unset($this->deprecated);
}
/**
* Is this field deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for accessors, or it will be completely ignored; in the very least, this
* is a formalization for deprecating fields.
*
* Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code>
* @param bool $var
* @return $this
*/
public function setDeprecated($var)
{
GPBUtil::checkBool($var);
$this->deprecated = $var;
return $this;
}
/**
* For Google-internal migration only. Do not use.
*
* Generated from protobuf field <code>optional bool weak = 10 [default = false];</code>
* @return bool
*/
public function getWeak()
{
return isset($this->weak) ? $this->weak : false;
}
public function hasWeak()
{
return isset($this->weak);
}
public function clearWeak()
{
unset($this->weak);
}
/**
* For Google-internal migration only. Do not use.
*
* Generated from protobuf field <code>optional bool weak = 10 [default = false];</code>
* @param bool $var
* @return $this
*/
public function setWeak($var)
{
GPBUtil::checkBool($var);
$this->weak = $var;
return $this;
}
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getUninterpretedOption()
{
return $this->uninterpreted_option;
}
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @param array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setUninterpretedOption($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $arr;
return $this;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
class FileDescriptor
{
private $package;
private $message_type = [];
private $enum_type = [];
public function setPackage($package)
{
$this->package = $package;
}
public function getPackage()
{
return $this->package;
}
public function getMessageType()
{
return $this->message_type;
}
public function addMessageType($desc)
{
$this->message_type[] = $desc;
}
public function getEnumType()
{
return $this->enum_type;
}
public function addEnumType($desc)
{
$this->enum_type[]= $desc;
}
public static function buildFromProto($proto)
{
$file = new FileDescriptor();
$file->setPackage($proto->getPackage());
foreach ($proto->getMessageType() as $message_proto) {
$file->addMessageType(Descriptor::buildFromProto(
$message_proto, $proto, ""));
}
foreach ($proto->getEnumType() as $enum_proto) {
$file->addEnumType(
EnumDescriptor::buildFromProto(
$enum_proto,
$proto,
""));
}
return $file;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\FieldOptions;
use UnexpectedValueException;
/**
* Protobuf type <code>google.protobuf.FieldOptions.CType</code>
*/
class CType
{
/**
* Default mode.
*
* Generated from protobuf enum <code>STRING = 0;</code>
*/
const STRING = 0;
/**
* Generated from protobuf enum <code>CORD = 1;</code>
*/
const CORD = 1;
/**
* Generated from protobuf enum <code>STRING_PIECE = 2;</code>
*/
const STRING_PIECE = 2;
private static $valueToName = [
self::STRING => 'STRING',
self::CORD => 'CORD',
self::STRING_PIECE => 'STRING_PIECE',
];
public static function name($value)
{
if (!isset(self::$valueToName[$value])) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no name defined for value %s', __CLASS__, $value));
}
return self::$valueToName[$value];
}
public static function value($name)
{
$const = __CLASS__ . '::' . strtoupper($name);
if (!defined($const)) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no value defined for name %s', __CLASS__, $name));
}
return constant($const);
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(CType::class, \Google\Protobuf\Internal\FieldOptions_CType::class);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\FieldOptions;
use UnexpectedValueException;
/**
* Protobuf type <code>google.protobuf.FieldOptions.JSType</code>
*/
class JSType
{
/**
* Use the default type.
*
* Generated from protobuf enum <code>JS_NORMAL = 0;</code>
*/
const JS_NORMAL = 0;
/**
* Use JavaScript strings.
*
* Generated from protobuf enum <code>JS_STRING = 1;</code>
*/
const JS_STRING = 1;
/**
* Use JavaScript numbers.
*
* Generated from protobuf enum <code>JS_NUMBER = 2;</code>
*/
const JS_NUMBER = 2;
private static $valueToName = [
self::JS_NORMAL => 'JS_NORMAL',
self::JS_STRING => 'JS_STRING',
self::JS_NUMBER => 'JS_NUMBER',
];
public static function name($value)
{
if (!isset(self::$valueToName[$value])) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no name defined for value %s', __CLASS__, $value));
}
return self::$valueToName[$value];
}
public static function value($name)
{
$const = __CLASS__ . '::' . strtoupper($name);
if (!defined($const)) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no value defined for name %s', __CLASS__, $name));
}
return constant($const);
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(JSType::class, \Google\Protobuf\Internal\FieldOptions_JSType::class);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\FileOptions;
use UnexpectedValueException;
/**
* Generated classes can be optimized for speed or code size.
*
* Protobuf type <code>google.protobuf.FileOptions.OptimizeMode</code>
*/
class OptimizeMode
{
/**
* Generate complete code for parsing, serialization,
*
* Generated from protobuf enum <code>SPEED = 1;</code>
*/
const SPEED = 1;
/**
* etc.
*
* Generated from protobuf enum <code>CODE_SIZE = 2;</code>
*/
const CODE_SIZE = 2;
/**
* Generate code using MessageLite and the lite runtime.
*
* Generated from protobuf enum <code>LITE_RUNTIME = 3;</code>
*/
const LITE_RUNTIME = 3;
private static $valueToName = [
self::SPEED => 'SPEED',
self::CODE_SIZE => 'CODE_SIZE',
self::LITE_RUNTIME => 'LITE_RUNTIME',
];
public static function name($value)
{
if (!isset(self::$valueToName[$value])) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no name defined for value %s', __CLASS__, $value));
}
return self::$valueToName[$value];
}
public static function value($name)
{
$const = __CLASS__ . '::' . strtoupper($name);
if (!defined($const)) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no value defined for name %s', __CLASS__, $name));
}
return constant($const);
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(OptimizeMode::class, \Google\Protobuf\Internal\FileOptions_OptimizeMode::class);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\UninterpretedOption;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* The name of the uninterpreted option. Each string represents a segment in
* a dot-separated name. is_extension is true iff a segment represents an
* extension (denoted with parentheses in options specs in .proto files).
* E.g.,{ ["foo", false], ["bar.baz", true], ["moo", false] } represents
* "foo.(bar.baz).moo".
*
* Generated from protobuf message <code>google.protobuf.UninterpretedOption.NamePart</code>
*/
class NamePart extends \Google\Protobuf\Internal\Message
{
/**
* Generated from protobuf field <code>required string name_part = 1;</code>
*/
protected $name_part = null;
/**
* Generated from protobuf field <code>required bool is_extension = 2;</code>
*/
protected $is_extension = null;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type string $name_part
* @type bool $is_extension
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Generated from protobuf field <code>required string name_part = 1;</code>
* @return string
*/
public function getNamePart()
{
return isset($this->name_part) ? $this->name_part : '';
}
public function hasNamePart()
{
return isset($this->name_part);
}
public function clearNamePart()
{
unset($this->name_part);
}
/**
* Generated from protobuf field <code>required string name_part = 1;</code>
* @param string $var
* @return $this
*/
public function setNamePart($var)
{
GPBUtil::checkString($var, True);
$this->name_part = $var;
return $this;
}
/**
* Generated from protobuf field <code>required bool is_extension = 2;</code>
* @return bool
*/
public function getIsExtension()
{
return isset($this->is_extension) ? $this->is_extension : false;
}
public function hasIsExtension()
{
return isset($this->is_extension);
}
public function clearIsExtension()
{
unset($this->is_extension);
}
/**
* Generated from protobuf field <code>required bool is_extension = 2;</code>
* @param bool $var
* @return $this
*/
public function setIsExtension($var)
{
GPBUtil::checkBool($var);
$this->is_extension = $var;
return $this;
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(NamePart::class, \Google\Protobuf\Internal\UninterpretedOption_NamePart::class);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\GeneratedCodeInfo;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>google.protobuf.GeneratedCodeInfo.Annotation</code>
*/
class Annotation extends \Google\Protobuf\Internal\Message
{
/**
* Identifies the element in the original source .proto file. This field
* is formatted the same as SourceCodeInfo.Location.path.
*
* Generated from protobuf field <code>repeated int32 path = 1 [packed = true];</code>
*/
private $path;
/**
* Identifies the filesystem path to the original source .proto.
*
* Generated from protobuf field <code>optional string source_file = 2;</code>
*/
protected $source_file = null;
/**
* Identifies the starting offset in bytes in the generated code
* that relates to the identified object.
*
* Generated from protobuf field <code>optional int32 begin = 3;</code>
*/
protected $begin = null;
/**
* Identifies the ending offset in bytes in the generated code that
* relates to the identified offset. The end offset should be one past
* the last relevant byte (so the length of the text = end - begin).
*
* Generated from protobuf field <code>optional int32 end = 4;</code>
*/
protected $end = null;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type array<int>|\Google\Protobuf\Internal\RepeatedField $path
* Identifies the element in the original source .proto file. This field
* is formatted the same as SourceCodeInfo.Location.path.
* @type string $source_file
* Identifies the filesystem path to the original source .proto.
* @type int $begin
* Identifies the starting offset in bytes in the generated code
* that relates to the identified object.
* @type int $end
* Identifies the ending offset in bytes in the generated code that
* relates to the identified offset. The end offset should be one past
* the last relevant byte (so the length of the text = end - begin).
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Identifies the element in the original source .proto file. This field
* is formatted the same as SourceCodeInfo.Location.path.
*
* Generated from protobuf field <code>repeated int32 path = 1 [packed = true];</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getPath()
{
return $this->path;
}
/**
* Identifies the element in the original source .proto file. This field
* is formatted the same as SourceCodeInfo.Location.path.
*
* Generated from protobuf field <code>repeated int32 path = 1 [packed = true];</code>
* @param array<int>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setPath($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
$this->path = $arr;
return $this;
}
/**
* Identifies the filesystem path to the original source .proto.
*
* Generated from protobuf field <code>optional string source_file = 2;</code>
* @return string
*/
public function getSourceFile()
{
return isset($this->source_file) ? $this->source_file : '';
}
public function hasSourceFile()
{
return isset($this->source_file);
}
public function clearSourceFile()
{
unset($this->source_file);
}
/**
* Identifies the filesystem path to the original source .proto.
*
* Generated from protobuf field <code>optional string source_file = 2;</code>
* @param string $var
* @return $this
*/
public function setSourceFile($var)
{
GPBUtil::checkString($var, True);
$this->source_file = $var;
return $this;
}
/**
* Identifies the starting offset in bytes in the generated code
* that relates to the identified object.
*
* Generated from protobuf field <code>optional int32 begin = 3;</code>
* @return int
*/
public function getBegin()
{
return isset($this->begin) ? $this->begin : 0;
}
public function hasBegin()
{
return isset($this->begin);
}
public function clearBegin()
{
unset($this->begin);
}
/**
* Identifies the starting offset in bytes in the generated code
* that relates to the identified object.
*
* Generated from protobuf field <code>optional int32 begin = 3;</code>
* @param int $var
* @return $this
*/
public function setBegin($var)
{
GPBUtil::checkInt32($var);
$this->begin = $var;
return $this;
}
/**
* Identifies the ending offset in bytes in the generated code that
* relates to the identified offset. The end offset should be one past
* the last relevant byte (so the length of the text = end - begin).
*
* Generated from protobuf field <code>optional int32 end = 4;</code>
* @return int
*/
public function getEnd()
{
return isset($this->end) ? $this->end : 0;
}
public function hasEnd()
{
return isset($this->end);
}
public function clearEnd()
{
unset($this->end);
}
/**
* Identifies the ending offset in bytes in the generated code that
* relates to the identified offset. The end offset should be one past
* the last relevant byte (so the length of the text = end - begin).
*
* Generated from protobuf field <code>optional int32 end = 4;</code>
* @param int $var
* @return $this
*/
public function setEnd($var)
{
GPBUtil::checkInt32($var);
$this->end = $var;
return $this;
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(Annotation::class, \Google\Protobuf\Internal\GeneratedCodeInfo_Annotation::class);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\FieldDescriptorProto;
use UnexpectedValueException;
/**
* Protobuf type <code>google.protobuf.FieldDescriptorProto.Label</code>
*/
class Label
{
/**
* 0 is reserved for errors
*
* Generated from protobuf enum <code>LABEL_OPTIONAL = 1;</code>
*/
const LABEL_OPTIONAL = 1;
/**
* Generated from protobuf enum <code>LABEL_REQUIRED = 2;</code>
*/
const LABEL_REQUIRED = 2;
/**
* Generated from protobuf enum <code>LABEL_REPEATED = 3;</code>
*/
const LABEL_REPEATED = 3;
private static $valueToName = [
self::LABEL_OPTIONAL => 'LABEL_OPTIONAL',
self::LABEL_REQUIRED => 'LABEL_REQUIRED',
self::LABEL_REPEATED => 'LABEL_REPEATED',
];
public static function name($value)
{
if (!isset(self::$valueToName[$value])) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no name defined for value %s', __CLASS__, $value));
}
return self::$valueToName[$value];
}
public static function value($name)
{
$const = __CLASS__ . '::' . strtoupper($name);
if (!defined($const)) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no value defined for name %s', __CLASS__, $name));
}
return constant($const);
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(Label::class, \Google\Protobuf\Internal\FieldDescriptorProto_Label::class);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\FieldDescriptorProto;
use UnexpectedValueException;
/**
* Protobuf type <code>google.protobuf.FieldDescriptorProto.Type</code>
*/
class Type
{
/**
* 0 is reserved for errors.
* Order is weird for historical reasons.
*
* Generated from protobuf enum <code>TYPE_DOUBLE = 1;</code>
*/
const TYPE_DOUBLE = 1;
/**
* Generated from protobuf enum <code>TYPE_FLOAT = 2;</code>
*/
const TYPE_FLOAT = 2;
/**
* Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
* negative values are likely.
*
* Generated from protobuf enum <code>TYPE_INT64 = 3;</code>
*/
const TYPE_INT64 = 3;
/**
* Generated from protobuf enum <code>TYPE_UINT64 = 4;</code>
*/
const TYPE_UINT64 = 4;
/**
* Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
* negative values are likely.
*
* Generated from protobuf enum <code>TYPE_INT32 = 5;</code>
*/
const TYPE_INT32 = 5;
/**
* Generated from protobuf enum <code>TYPE_FIXED64 = 6;</code>
*/
const TYPE_FIXED64 = 6;
/**
* Generated from protobuf enum <code>TYPE_FIXED32 = 7;</code>
*/
const TYPE_FIXED32 = 7;
/**
* Generated from protobuf enum <code>TYPE_BOOL = 8;</code>
*/
const TYPE_BOOL = 8;
/**
* Generated from protobuf enum <code>TYPE_STRING = 9;</code>
*/
const TYPE_STRING = 9;
/**
* Tag-delimited aggregate.
* Group type is deprecated and not supported in proto3. However, Proto3
* implementations should still be able to parse the group wire format and
* treat group fields as unknown fields.
*
* Generated from protobuf enum <code>TYPE_GROUP = 10;</code>
*/
const TYPE_GROUP = 10;
/**
* Length-delimited aggregate.
*
* Generated from protobuf enum <code>TYPE_MESSAGE = 11;</code>
*/
const TYPE_MESSAGE = 11;
/**
* New in version 2.
*
* Generated from protobuf enum <code>TYPE_BYTES = 12;</code>
*/
const TYPE_BYTES = 12;
/**
* Generated from protobuf enum <code>TYPE_UINT32 = 13;</code>
*/
const TYPE_UINT32 = 13;
/**
* Generated from protobuf enum <code>TYPE_ENUM = 14;</code>
*/
const TYPE_ENUM = 14;
/**
* Generated from protobuf enum <code>TYPE_SFIXED32 = 15;</code>
*/
const TYPE_SFIXED32 = 15;
/**
* Generated from protobuf enum <code>TYPE_SFIXED64 = 16;</code>
*/
const TYPE_SFIXED64 = 16;
/**
* Uses ZigZag encoding.
*
* Generated from protobuf enum <code>TYPE_SINT32 = 17;</code>
*/
const TYPE_SINT32 = 17;
/**
* Uses ZigZag encoding.
*
* Generated from protobuf enum <code>TYPE_SINT64 = 18;</code>
*/
const TYPE_SINT64 = 18;
private static $valueToName = [
self::TYPE_DOUBLE => 'TYPE_DOUBLE',
self::TYPE_FLOAT => 'TYPE_FLOAT',
self::TYPE_INT64 => 'TYPE_INT64',
self::TYPE_UINT64 => 'TYPE_UINT64',
self::TYPE_INT32 => 'TYPE_INT32',
self::TYPE_FIXED64 => 'TYPE_FIXED64',
self::TYPE_FIXED32 => 'TYPE_FIXED32',
self::TYPE_BOOL => 'TYPE_BOOL',
self::TYPE_STRING => 'TYPE_STRING',
self::TYPE_GROUP => 'TYPE_GROUP',
self::TYPE_MESSAGE => 'TYPE_MESSAGE',
self::TYPE_BYTES => 'TYPE_BYTES',
self::TYPE_UINT32 => 'TYPE_UINT32',
self::TYPE_ENUM => 'TYPE_ENUM',
self::TYPE_SFIXED32 => 'TYPE_SFIXED32',
self::TYPE_SFIXED64 => 'TYPE_SFIXED64',
self::TYPE_SINT32 => 'TYPE_SINT32',
self::TYPE_SINT64 => 'TYPE_SINT64',
];
public static function name($value)
{
if (!isset(self::$valueToName[$value])) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no name defined for value %s', __CLASS__, $value));
}
return self::$valueToName[$value];
}
public static function value($name)
{
$const = __CLASS__ . '::' . strtoupper($name);
if (!defined($const)) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no value defined for name %s', __CLASS__, $name));
}
return constant($const);
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(Type::class, \Google\Protobuf\Internal\FieldDescriptorProto_Type::class);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\DescriptorProto;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>google.protobuf.DescriptorProto.ExtensionRange</code>
*/
class ExtensionRange extends \Google\Protobuf\Internal\Message
{
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 start = 1;</code>
*/
protected $start = null;
/**
* Exclusive.
*
* Generated from protobuf field <code>optional int32 end = 2;</code>
*/
protected $end = null;
/**
* Generated from protobuf field <code>optional .google.protobuf.ExtensionRangeOptions options = 3;</code>
*/
protected $options = null;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type int $start
* Inclusive.
* @type int $end
* Exclusive.
* @type \Google\Protobuf\Internal\ExtensionRangeOptions $options
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 start = 1;</code>
* @return int
*/
public function getStart()
{
return isset($this->start) ? $this->start : 0;
}
public function hasStart()
{
return isset($this->start);
}
public function clearStart()
{
unset($this->start);
}
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 start = 1;</code>
* @param int $var
* @return $this
*/
public function setStart($var)
{
GPBUtil::checkInt32($var);
$this->start = $var;
return $this;
}
/**
* Exclusive.
*
* Generated from protobuf field <code>optional int32 end = 2;</code>
* @return int
*/
public function getEnd()
{
return isset($this->end) ? $this->end : 0;
}
public function hasEnd()
{
return isset($this->end);
}
public function clearEnd()
{
unset($this->end);
}
/**
* Exclusive.
*
* Generated from protobuf field <code>optional int32 end = 2;</code>
* @param int $var
* @return $this
*/
public function setEnd($var)
{
GPBUtil::checkInt32($var);
$this->end = $var;
return $this;
}
/**
* Generated from protobuf field <code>optional .google.protobuf.ExtensionRangeOptions options = 3;</code>
* @return \Google\Protobuf\Internal\ExtensionRangeOptions|null
*/
public function getOptions()
{
return $this->options;
}
public function hasOptions()
{
return isset($this->options);
}
public function clearOptions()
{
unset($this->options);
}
/**
* Generated from protobuf field <code>optional .google.protobuf.ExtensionRangeOptions options = 3;</code>
* @param \Google\Protobuf\Internal\ExtensionRangeOptions $var
* @return $this
*/
public function setOptions($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\ExtensionRangeOptions::class);
$this->options = $var;
return $this;
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(ExtensionRange::class, \Google\Protobuf\Internal\DescriptorProto_ExtensionRange::class);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\DescriptorProto;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Range of reserved tag numbers. Reserved tag numbers may not be used by
* fields or extension ranges in the same message. Reserved ranges may
* not overlap.
*
* Generated from protobuf message <code>google.protobuf.DescriptorProto.ReservedRange</code>
*/
class ReservedRange extends \Google\Protobuf\Internal\Message
{
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 start = 1;</code>
*/
protected $start = null;
/**
* Exclusive.
*
* Generated from protobuf field <code>optional int32 end = 2;</code>
*/
protected $end = null;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type int $start
* Inclusive.
* @type int $end
* Exclusive.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 start = 1;</code>
* @return int
*/
public function getStart()
{
return isset($this->start) ? $this->start : 0;
}
public function hasStart()
{
return isset($this->start);
}
public function clearStart()
{
unset($this->start);
}
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 start = 1;</code>
* @param int $var
* @return $this
*/
public function setStart($var)
{
GPBUtil::checkInt32($var);
$this->start = $var;
return $this;
}
/**
* Exclusive.
*
* Generated from protobuf field <code>optional int32 end = 2;</code>
* @return int
*/
public function getEnd()
{
return isset($this->end) ? $this->end : 0;
}
public function hasEnd()
{
return isset($this->end);
}
public function clearEnd()
{
unset($this->end);
}
/**
* Exclusive.
*
* Generated from protobuf field <code>optional int32 end = 2;</code>
* @param int $var
* @return $this
*/
public function setEnd($var)
{
GPBUtil::checkInt32($var);
$this->end = $var;
return $this;
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(ReservedRange::class, \Google\Protobuf\Internal\DescriptorProto_ReservedRange::class);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\MethodOptions;
use UnexpectedValueException;
/**
* Is this method side-effect-free (or safe in HTTP parlance), or idempotent,
* or neither? HTTP based RPC implementation may choose GET verb for safe
* methods, and PUT verb for idempotent methods instead of the default POST.
*
* Protobuf type <code>google.protobuf.MethodOptions.IdempotencyLevel</code>
*/
class IdempotencyLevel
{
/**
* Generated from protobuf enum <code>IDEMPOTENCY_UNKNOWN = 0;</code>
*/
const IDEMPOTENCY_UNKNOWN = 0;
/**
* implies idempotent
*
* Generated from protobuf enum <code>NO_SIDE_EFFECTS = 1;</code>
*/
const NO_SIDE_EFFECTS = 1;
/**
* idempotent, but may have side effects
*
* Generated from protobuf enum <code>IDEMPOTENT = 2;</code>
*/
const IDEMPOTENT = 2;
private static $valueToName = [
self::IDEMPOTENCY_UNKNOWN => 'IDEMPOTENCY_UNKNOWN',
self::NO_SIDE_EFFECTS => 'NO_SIDE_EFFECTS',
self::IDEMPOTENT => 'IDEMPOTENT',
];
public static function name($value)
{
if (!isset(self::$valueToName[$value])) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no name defined for value %s', __CLASS__, $value));
}
return self::$valueToName[$value];
}
public static function value($name)
{
$const = __CLASS__ . '::' . strtoupper($name);
if (!defined($const)) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no value defined for name %s', __CLASS__, $name));
}
return constant($const);
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(IdempotencyLevel::class, \Google\Protobuf\Internal\MethodOptions_IdempotencyLevel::class);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\SourceCodeInfo;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>google.protobuf.SourceCodeInfo.Location</code>
*/
class Location extends \Google\Protobuf\Internal\Message
{
/**
* Identifies which part of the FileDescriptorProto was defined at this
* location.
* Each element is a field number or an index. They form a path from
* the root FileDescriptorProto to the place where the definition occurs.
* For example, this path:
* [ 4, 3, 2, 7, 1 ]
* refers to:
* file.message_type(3) // 4, 3
* .field(7) // 2, 7
* .name() // 1
* This is because FileDescriptorProto.message_type has field number 4:
* repeated DescriptorProto message_type = 4;
* and DescriptorProto.field has field number 2:
* repeated FieldDescriptorProto field = 2;
* and FieldDescriptorProto.name has field number 1:
* optional string name = 1;
* Thus, the above path gives the location of a field name. If we removed
* the last element:
* [ 4, 3, 2, 7 ]
* this path refers to the whole field declaration (from the beginning
* of the label to the terminating semicolon).
*
* Generated from protobuf field <code>repeated int32 path = 1 [packed = true];</code>
*/
private $path;
/**
* Always has exactly three or four elements: start line, start column,
* end line (optional, otherwise assumed same as start line), end column.
* These are packed into a single field for efficiency. Note that line
* and column numbers are zero-based -- typically you will want to add
* 1 to each before displaying to a user.
*
* Generated from protobuf field <code>repeated int32 span = 2 [packed = true];</code>
*/
private $span;
/**
* If this SourceCodeInfo represents a complete declaration, these are any
* comments appearing before and after the declaration which appear to be
* attached to the declaration.
* A series of line comments appearing on consecutive lines, with no other
* tokens appearing on those lines, will be treated as a single comment.
* leading_detached_comments will keep paragraphs of comments that appear
* before (but not connected to) the current element. Each paragraph,
* separated by empty lines, will be one comment element in the repeated
* field.
* Only the comment content is provided; comment markers (e.g. //) are
* stripped out. For block comments, leading whitespace and an asterisk
* will be stripped from the beginning of each line other than the first.
* Newlines are included in the output.
* Examples:
* optional int32 foo = 1; // Comment attached to foo.
* // Comment attached to bar.
* optional int32 bar = 2;
* optional string baz = 3;
* // Comment attached to baz.
* // Another line attached to baz.
* // Comment attached to moo.
* //
* // Another line attached to moo.
* optional double moo = 4;
* // Detached comment for corge. This is not leading or trailing comments
* // to moo or corge because there are blank lines separating it from
* // both.
* // Detached comment for corge paragraph 2.
* optional string corge = 5;
* /* Block comment attached
* * to corge. Leading asterisks
* * will be removed. */
* /* Block comment attached to
* * grault. */
* optional int32 grault = 6;
* // ignored detached comments.
*
* Generated from protobuf field <code>optional string leading_comments = 3;</code>
*/
protected $leading_comments = null;
/**
* Generated from protobuf field <code>optional string trailing_comments = 4;</code>
*/
protected $trailing_comments = null;
/**
* Generated from protobuf field <code>repeated string leading_detached_comments = 6;</code>
*/
private $leading_detached_comments;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type array<int>|\Google\Protobuf\Internal\RepeatedField $path
* Identifies which part of the FileDescriptorProto was defined at this
* location.
* Each element is a field number or an index. They form a path from
* the root FileDescriptorProto to the place where the definition occurs.
* For example, this path:
* [ 4, 3, 2, 7, 1 ]
* refers to:
* file.message_type(3) // 4, 3
* .field(7) // 2, 7
* .name() // 1
* This is because FileDescriptorProto.message_type has field number 4:
* repeated DescriptorProto message_type = 4;
* and DescriptorProto.field has field number 2:
* repeated FieldDescriptorProto field = 2;
* and FieldDescriptorProto.name has field number 1:
* optional string name = 1;
* Thus, the above path gives the location of a field name. If we removed
* the last element:
* [ 4, 3, 2, 7 ]
* this path refers to the whole field declaration (from the beginning
* of the label to the terminating semicolon).
* @type array<int>|\Google\Protobuf\Internal\RepeatedField $span
* Always has exactly three or four elements: start line, start column,
* end line (optional, otherwise assumed same as start line), end column.
* These are packed into a single field for efficiency. Note that line
* and column numbers are zero-based -- typically you will want to add
* 1 to each before displaying to a user.
* @type string $leading_comments
* If this SourceCodeInfo represents a complete declaration, these are any
* comments appearing before and after the declaration which appear to be
* attached to the declaration.
* A series of line comments appearing on consecutive lines, with no other
* tokens appearing on those lines, will be treated as a single comment.
* leading_detached_comments will keep paragraphs of comments that appear
* before (but not connected to) the current element. Each paragraph,
* separated by empty lines, will be one comment element in the repeated
* field.
* Only the comment content is provided; comment markers (e.g. //) are
* stripped out. For block comments, leading whitespace and an asterisk
* will be stripped from the beginning of each line other than the first.
* Newlines are included in the output.
* Examples:
* optional int32 foo = 1; // Comment attached to foo.
* // Comment attached to bar.
* optional int32 bar = 2;
* optional string baz = 3;
* // Comment attached to baz.
* // Another line attached to baz.
* // Comment attached to moo.
* //
* // Another line attached to moo.
* optional double moo = 4;
* // Detached comment for corge. This is not leading or trailing comments
* // to moo or corge because there are blank lines separating it from
* // both.
* // Detached comment for corge paragraph 2.
* optional string corge = 5;
* /* Block comment attached
* * to corge. Leading asterisks
* * will be removed. */
* /* Block comment attached to
* * grault. */
* optional int32 grault = 6;
* // ignored detached comments.
* @type string $trailing_comments
* @type array<string>|\Google\Protobuf\Internal\RepeatedField $leading_detached_comments
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Identifies which part of the FileDescriptorProto was defined at this
* location.
* Each element is a field number or an index. They form a path from
* the root FileDescriptorProto to the place where the definition occurs.
* For example, this path:
* [ 4, 3, 2, 7, 1 ]
* refers to:
* file.message_type(3) // 4, 3
* .field(7) // 2, 7
* .name() // 1
* This is because FileDescriptorProto.message_type has field number 4:
* repeated DescriptorProto message_type = 4;
* and DescriptorProto.field has field number 2:
* repeated FieldDescriptorProto field = 2;
* and FieldDescriptorProto.name has field number 1:
* optional string name = 1;
* Thus, the above path gives the location of a field name. If we removed
* the last element:
* [ 4, 3, 2, 7 ]
* this path refers to the whole field declaration (from the beginning
* of the label to the terminating semicolon).
*
* Generated from protobuf field <code>repeated int32 path = 1 [packed = true];</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getPath()
{
return $this->path;
}
/**
* Identifies which part of the FileDescriptorProto was defined at this
* location.
* Each element is a field number or an index. They form a path from
* the root FileDescriptorProto to the place where the definition occurs.
* For example, this path:
* [ 4, 3, 2, 7, 1 ]
* refers to:
* file.message_type(3) // 4, 3
* .field(7) // 2, 7
* .name() // 1
* This is because FileDescriptorProto.message_type has field number 4:
* repeated DescriptorProto message_type = 4;
* and DescriptorProto.field has field number 2:
* repeated FieldDescriptorProto field = 2;
* and FieldDescriptorProto.name has field number 1:
* optional string name = 1;
* Thus, the above path gives the location of a field name. If we removed
* the last element:
* [ 4, 3, 2, 7 ]
* this path refers to the whole field declaration (from the beginning
* of the label to the terminating semicolon).
*
* Generated from protobuf field <code>repeated int32 path = 1 [packed = true];</code>
* @param array<int>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setPath($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
$this->path = $arr;
return $this;
}
/**
* Always has exactly three or four elements: start line, start column,
* end line (optional, otherwise assumed same as start line), end column.
* These are packed into a single field for efficiency. Note that line
* and column numbers are zero-based -- typically you will want to add
* 1 to each before displaying to a user.
*
* Generated from protobuf field <code>repeated int32 span = 2 [packed = true];</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getSpan()
{
return $this->span;
}
/**
* Always has exactly three or four elements: start line, start column,
* end line (optional, otherwise assumed same as start line), end column.
* These are packed into a single field for efficiency. Note that line
* and column numbers are zero-based -- typically you will want to add
* 1 to each before displaying to a user.
*
* Generated from protobuf field <code>repeated int32 span = 2 [packed = true];</code>
* @param array<int>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setSpan($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
$this->span = $arr;
return $this;
}
/**
* If this SourceCodeInfo represents a complete declaration, these are any
* comments appearing before and after the declaration which appear to be
* attached to the declaration.
* A series of line comments appearing on consecutive lines, with no other
* tokens appearing on those lines, will be treated as a single comment.
* leading_detached_comments will keep paragraphs of comments that appear
* before (but not connected to) the current element. Each paragraph,
* separated by empty lines, will be one comment element in the repeated
* field.
* Only the comment content is provided; comment markers (e.g. //) are
* stripped out. For block comments, leading whitespace and an asterisk
* will be stripped from the beginning of each line other than the first.
* Newlines are included in the output.
* Examples:
* optional int32 foo = 1; // Comment attached to foo.
* // Comment attached to bar.
* optional int32 bar = 2;
* optional string baz = 3;
* // Comment attached to baz.
* // Another line attached to baz.
* // Comment attached to moo.
* //
* // Another line attached to moo.
* optional double moo = 4;
* // Detached comment for corge. This is not leading or trailing comments
* // to moo or corge because there are blank lines separating it from
* // both.
* // Detached comment for corge paragraph 2.
* optional string corge = 5;
* /* Block comment attached
* * to corge. Leading asterisks
* * will be removed. */
* /* Block comment attached to
* * grault. */
* optional int32 grault = 6;
* // ignored detached comments.
*
* Generated from protobuf field <code>optional string leading_comments = 3;</code>
* @return string
*/
public function getLeadingComments()
{
return isset($this->leading_comments) ? $this->leading_comments : '';
}
public function hasLeadingComments()
{
return isset($this->leading_comments);
}
public function clearLeadingComments()
{
unset($this->leading_comments);
}
/**
* If this SourceCodeInfo represents a complete declaration, these are any
* comments appearing before and after the declaration which appear to be
* attached to the declaration.
* A series of line comments appearing on consecutive lines, with no other
* tokens appearing on those lines, will be treated as a single comment.
* leading_detached_comments will keep paragraphs of comments that appear
* before (but not connected to) the current element. Each paragraph,
* separated by empty lines, will be one comment element in the repeated
* field.
* Only the comment content is provided; comment markers (e.g. //) are
* stripped out. For block comments, leading whitespace and an asterisk
* will be stripped from the beginning of each line other than the first.
* Newlines are included in the output.
* Examples:
* optional int32 foo = 1; // Comment attached to foo.
* // Comment attached to bar.
* optional int32 bar = 2;
* optional string baz = 3;
* // Comment attached to baz.
* // Another line attached to baz.
* // Comment attached to moo.
* //
* // Another line attached to moo.
* optional double moo = 4;
* // Detached comment for corge. This is not leading or trailing comments
* // to moo or corge because there are blank lines separating it from
* // both.
* // Detached comment for corge paragraph 2.
* optional string corge = 5;
* /* Block comment attached
* * to corge. Leading asterisks
* * will be removed. */
* /* Block comment attached to
* * grault. */
* optional int32 grault = 6;
* // ignored detached comments.
*
* Generated from protobuf field <code>optional string leading_comments = 3;</code>
* @param string $var
* @return $this
*/
public function setLeadingComments($var)
{
GPBUtil::checkString($var, True);
$this->leading_comments = $var;
return $this;
}
/**
* Generated from protobuf field <code>optional string trailing_comments = 4;</code>
* @return string
*/
public function getTrailingComments()
{
return isset($this->trailing_comments) ? $this->trailing_comments : '';
}
public function hasTrailingComments()
{
return isset($this->trailing_comments);
}
public function clearTrailingComments()
{
unset($this->trailing_comments);
}
/**
* Generated from protobuf field <code>optional string trailing_comments = 4;</code>
* @param string $var
* @return $this
*/
public function setTrailingComments($var)
{
GPBUtil::checkString($var, True);
$this->trailing_comments = $var;
return $this;
}
/**
* Generated from protobuf field <code>repeated string leading_detached_comments = 6;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getLeadingDetachedComments()
{
return $this->leading_detached_comments;
}
/**
* Generated from protobuf field <code>repeated string leading_detached_comments = 6;</code>
* @param array<string>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setLeadingDetachedComments($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING);
$this->leading_detached_comments = $arr;
return $this;
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(Location::class, \Google\Protobuf\Internal\SourceCodeInfo_Location::class);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\EnumDescriptorProto;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Range of reserved numeric values. Reserved values may not be used by
* entries in the same enum. Reserved ranges may not overlap.
* Note that this is distinct from DescriptorProto.ReservedRange in that it
* is inclusive such that it can appropriately represent the entire int32
* domain.
*
* Generated from protobuf message <code>google.protobuf.EnumDescriptorProto.EnumReservedRange</code>
*/
class EnumReservedRange extends \Google\Protobuf\Internal\Message
{
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 start = 1;</code>
*/
protected $start = null;
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 end = 2;</code>
*/
protected $end = null;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type int $start
* Inclusive.
* @type int $end
* Inclusive.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 start = 1;</code>
* @return int
*/
public function getStart()
{
return isset($this->start) ? $this->start : 0;
}
public function hasStart()
{
return isset($this->start);
}
public function clearStart()
{
unset($this->start);
}
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 start = 1;</code>
* @param int $var
* @return $this
*/
public function setStart($var)
{
GPBUtil::checkInt32($var);
$this->start = $var;
return $this;
}
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 end = 2;</code>
* @return int
*/
public function getEnd()
{
return isset($this->end) ? $this->end : 0;
}
public function hasEnd()
{
return isset($this->end);
}
public function clearEnd()
{
unset($this->end);
}
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 end = 2;</code>
* @param int $var
* @return $this
*/
public function setEnd($var)
{
GPBUtil::checkInt32($var);
$this->end = $var;
return $this;
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(EnumReservedRange::class, \Google\Protobuf\Internal\EnumDescriptorProto_EnumReservedRange::class);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/type.proto
namespace Google\Protobuf\Field;
use UnexpectedValueException;
/**
* Whether a field is optional, required, or repeated.
*
* Protobuf type <code>google.protobuf.Field.Cardinality</code>
*/
class Cardinality
{
/**
* For fields with unknown cardinality.
*
* Generated from protobuf enum <code>CARDINALITY_UNKNOWN = 0;</code>
*/
const CARDINALITY_UNKNOWN = 0;
/**
* For optional fields.
*
* Generated from protobuf enum <code>CARDINALITY_OPTIONAL = 1;</code>
*/
const CARDINALITY_OPTIONAL = 1;
/**
* For required fields. Proto2 syntax only.
*
* Generated from protobuf enum <code>CARDINALITY_REQUIRED = 2;</code>
*/
const CARDINALITY_REQUIRED = 2;
/**
* For repeated fields.
*
* Generated from protobuf enum <code>CARDINALITY_REPEATED = 3;</code>
*/
const CARDINALITY_REPEATED = 3;
private static $valueToName = [
self::CARDINALITY_UNKNOWN => 'CARDINALITY_UNKNOWN',
self::CARDINALITY_OPTIONAL => 'CARDINALITY_OPTIONAL',
self::CARDINALITY_REQUIRED => 'CARDINALITY_REQUIRED',
self::CARDINALITY_REPEATED => 'CARDINALITY_REPEATED',
];
public static function name($value)
{
if (!isset(self::$valueToName[$value])) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no name defined for value %s', __CLASS__, $value));
}
return self::$valueToName[$value];
}
public static function value($name)
{
$const = __CLASS__ . '::' . strtoupper($name);
if (!defined($const)) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no value defined for name %s', __CLASS__, $name));
}
return constant($const);
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(Cardinality::class, \Google\Protobuf\Field_Cardinality::class);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/type.proto
namespace Google\Protobuf\Field;
use UnexpectedValueException;
/**
* Basic field types.
*
* Protobuf type <code>google.protobuf.Field.Kind</code>
*/
class Kind
{
/**
* Field type unknown.
*
* Generated from protobuf enum <code>TYPE_UNKNOWN = 0;</code>
*/
const TYPE_UNKNOWN = 0;
/**
* Field type double.
*
* Generated from protobuf enum <code>TYPE_DOUBLE = 1;</code>
*/
const TYPE_DOUBLE = 1;
/**
* Field type float.
*
* Generated from protobuf enum <code>TYPE_FLOAT = 2;</code>
*/
const TYPE_FLOAT = 2;
/**
* Field type int64.
*
* Generated from protobuf enum <code>TYPE_INT64 = 3;</code>
*/
const TYPE_INT64 = 3;
/**
* Field type uint64.
*
* Generated from protobuf enum <code>TYPE_UINT64 = 4;</code>
*/
const TYPE_UINT64 = 4;
/**
* Field type int32.
*
* Generated from protobuf enum <code>TYPE_INT32 = 5;</code>
*/
const TYPE_INT32 = 5;
/**
* Field type fixed64.
*
* Generated from protobuf enum <code>TYPE_FIXED64 = 6;</code>
*/
const TYPE_FIXED64 = 6;
/**
* Field type fixed32.
*
* Generated from protobuf enum <code>TYPE_FIXED32 = 7;</code>
*/
const TYPE_FIXED32 = 7;
/**
* Field type bool.
*
* Generated from protobuf enum <code>TYPE_BOOL = 8;</code>
*/
const TYPE_BOOL = 8;
/**
* Field type string.
*
* Generated from protobuf enum <code>TYPE_STRING = 9;</code>
*/
const TYPE_STRING = 9;
/**
* Field type group. Proto2 syntax only, and deprecated.
*
* Generated from protobuf enum <code>TYPE_GROUP = 10;</code>
*/
const TYPE_GROUP = 10;
/**
* Field type message.
*
* Generated from protobuf enum <code>TYPE_MESSAGE = 11;</code>
*/
const TYPE_MESSAGE = 11;
/**
* Field type bytes.
*
* Generated from protobuf enum <code>TYPE_BYTES = 12;</code>
*/
const TYPE_BYTES = 12;
/**
* Field type uint32.
*
* Generated from protobuf enum <code>TYPE_UINT32 = 13;</code>
*/
const TYPE_UINT32 = 13;
/**
* Field type enum.
*
* Generated from protobuf enum <code>TYPE_ENUM = 14;</code>
*/
const TYPE_ENUM = 14;
/**
* Field type sfixed32.
*
* Generated from protobuf enum <code>TYPE_SFIXED32 = 15;</code>
*/
const TYPE_SFIXED32 = 15;
/**
* Field type sfixed64.
*
* Generated from protobuf enum <code>TYPE_SFIXED64 = 16;</code>
*/
const TYPE_SFIXED64 = 16;
/**
* Field type sint32.
*
* Generated from protobuf enum <code>TYPE_SINT32 = 17;</code>
*/
const TYPE_SINT32 = 17;
/**
* Field type sint64.
*
* Generated from protobuf enum <code>TYPE_SINT64 = 18;</code>
*/
const TYPE_SINT64 = 18;
private static $valueToName = [
self::TYPE_UNKNOWN => 'TYPE_UNKNOWN',
self::TYPE_DOUBLE => 'TYPE_DOUBLE',
self::TYPE_FLOAT => 'TYPE_FLOAT',
self::TYPE_INT64 => 'TYPE_INT64',
self::TYPE_UINT64 => 'TYPE_UINT64',
self::TYPE_INT32 => 'TYPE_INT32',
self::TYPE_FIXED64 => 'TYPE_FIXED64',
self::TYPE_FIXED32 => 'TYPE_FIXED32',
self::TYPE_BOOL => 'TYPE_BOOL',
self::TYPE_STRING => 'TYPE_STRING',
self::TYPE_GROUP => 'TYPE_GROUP',
self::TYPE_MESSAGE => 'TYPE_MESSAGE',
self::TYPE_BYTES => 'TYPE_BYTES',
self::TYPE_UINT32 => 'TYPE_UINT32',
self::TYPE_ENUM => 'TYPE_ENUM',
self::TYPE_SFIXED32 => 'TYPE_SFIXED32',
self::TYPE_SFIXED64 => 'TYPE_SFIXED64',
self::TYPE_SINT32 => 'TYPE_SINT32',
self::TYPE_SINT64 => 'TYPE_SINT64',
];
public static function name($value)
{
if (!isset(self::$valueToName[$value])) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no name defined for value %s', __CLASS__, $value));
}
return self::$valueToName[$value];
}
public static function value($name)
{
$const = __CLASS__ . '::' . strtoupper($name);
if (!defined($const)) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no value defined for name %s', __CLASS__, $name));
}
return constant($const);
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(Kind::class, \Google\Protobuf\Field_Kind::class);
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike;
use ArrayAccess, ArrayIterator, IteratorAggregate;
use ReturnTypeWillChange; // PHP 8.1+
/**
* Implements a general data array object that can be
* accessed both an array and an object.
*
* This is currently implemented as read-only.
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class DataArray implements ArrayAccess, IteratorAggregate
{
/**
* Bound array that stores definitions.
*
* @var array
*/
private $boundArray = [];
public function __construct(&$baseArray)
{
$this->boundArray = &$baseArray;
}
public function __get($var)
{
$lowercaseName = strtolower($var);
// Converted from camelCase to hyphen-case
$hyphenCaseName = strtolower(
preg_replace("/(?<!^)[A-Z]/", "-$0", $var)
);
$snake_case_name = str_replace("_", "-", $var);
// Check if the raw name is accessible in the object
if (isset($this->boundArray[$lowercaseName]))
{
return $this->boundArray[$lowercaseName];
}
// Otherwise, check if the camelCase name is accessible
// in the object.
else if (isset($this->boundArray[$hyphenCaseName]))
{
return $this->boundArray[$hyphenCaseName];
}
// And if that's not the case, check if it's snake_case
else if (isset($this->boundArray[$snake_case_name]))
{
return $this->boundArray[$snake_case_name];
}
// And finally, if none of those are set, return null
else
{
return null;
}
}
public function __isset($var)
{
return null != $this->__get($var);
}
public function __set($a, $b)
{
$this->offsetSet(null, null); // inherit warning
}
/*
* Array access functions
*
* In order to maintain compatibility with both PHP 7.x and
* PHP 8.1, the ReturnTypeWillChange attribute is required on all
* methods.
*
* This is to avoid a conflict where PHP 8.1 requires strict type
* signatures on methods and PHP 7.x doesn't even support them at
* all.
*/
#[ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->boundArray[$offset]);
}
#[ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
trigger_error("RequestMetadata->headers is read only.", E_USER_WARNING);
}
#[ReturnTypeWillChange]
public function offsetUnset($offset)
{
$this->offsetSet(null, null); // inherit warning
}
#[ReturnTypeWillChange]
public function offsetGet($offset)
{
return isset($this->boundArray[$offset])
? $this->boundArray[$offset]
: null
;
}
#[ReturnTypeWillChange]
public function &getIterator()
{
return new ArrayIterator($this->boundArray);
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike;
use \Rehike\Exception\FileSystem\FsFileDoesNotExistException;
use \Rehike\Exception\FileSystem\FsMkdirException;
use \Rehike\Exception\FileSystem\FsWriteFileException;
use \Rehike\Exception\FileSystem\FsFileReadFailureException;
/**
* Implements common file system helpers.
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class FileSystem
{
/**
* Get the extension of a filename.
*
* This returns everything past the first dot in the filename, so
* formats like .tar.gz are supported.
*
* @param string $filename
* @return string
*/
public static function getExtension($filename)
{
// Ignore the first . (i.e. in ./)
if ("." == $filename[0])
{
$filename = substr($filename, 1);
}
// Split the filename by "."
$ext = explode(".", $filename);
// Remove the first item (everything before the first .)
array_splice($ext, 0, 1);
// Rejoin the extension by "."
$ext = implode(".", $ext);
return $ext;
}
/**
* Get the containing folder of a file path.
*
* @param string $path
* @return string
*/
public static function getFolder($path)
{
// Convert the path to account for Windows separation.
$path = self::unwindows($path);
// Split the path by the separator
$root = explode("/", $path);
// Remove the last item (the filename)
array_splice($root, count($root) - 1, 1);
// Rejoin
$root = implode("/", $root);
return $root;
}
/**
* Un-Windows a path (convert \ to /)
*
* @param string $path
* @return string
*/
public static function unwindows($path)
{
return str_replace("\\", "/", $path);
}
/**
* Get a "rehike://" URL which anonymises the path the user stored their
* Rehike installation. This is useful for logging purposes.
*/
public static function getRehikeRelativePath(string $path): string
{
$path = self::unwindows($path);
return str_replace($_SERVER["DOCUMENT_ROOT"] . "/", "rehike://", $path);
}
/**
* Write a file.
*
* @param $path of the file to write to.
* @param $contents to write.
* @param $recursive (create folders leading to the filename if they don't exist)
* @param $append to the file instead of erasing it
* @return void
*/
public static function writeFile($path, $contents, $recursive = true, $append = false)
{
// Make sure all folders leading to the path exist if the
// recursive option is enabled.
if ($recursive)
{
$folder = self::getFolder($path);
if (!is_dir($folder))
{
self::mkdir($folder, 0777, true);
}
}
// Determine fopen mode from append value
$fopenMode = $append ? "a" : "w";
// Use fopen to write the file
$fh = @\fopen($path, $fopenMode);
$status = @\fwrite($fh, $contents);
// Validate
if (false == $fh || false == $status)
{
throw new FsWriteFileException("Failed to write file \"$path\"");
}
\fclose($fh);
}
//
// Alias operations
//
public static function getFileContents($filename, $useIncludePath = true, $context = null, $offset = null, $length = null)
{
/*
* PATCH (kirasicecreamm): The file_get_contents API vaguely differs between
* PHP versions.
*
* This has been a source of odd crashing on what we could only just
* trace to PHP 7.x, which we intend to continue supporting for the near
* future.
*/
$fgcArgs = [
$filename,
$useIncludePath,
$context
];
if (\PHP_VERSION_ID < 80000)
{
$offset = 0;
}
$fgcArgs[] = $offset;
if (null != $length) $fgcArgs[] = $length;
$status = @\file_get_contents(...$fgcArgs);
if (false == $status)
{
if (\file_exists($filename))
{
throw new FsFileReadFailureException(
"Failed to read file \"$filename\". Double check if PHP has " .
"permission to access the file and try again."
);
}
else
{
throw new FsFileDoesNotExistException(
"Attempted to read nonexistent file \"$filename\""
);
}
}
else
{
return $status;
}
}
public static function fileExists($filename)
{
return \file_exists($filename) ||
\file_exists($_SERVER["DOCUMENT_ROOT"] . "/" . $filename)
;
}
public static function mkdir($dirname, $mode = 0777, $recursive = false)
{
$status = @\mkdir($dirname, $mode, $recursive);
if (false == $status)
{
throw new FsMkdirException(
"Failed to create directory \"$dirname\""
);
}
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike;
use Rehike\Util\Base64Url;
/**
* Generates a valid InnerTube client context required
* for requesting the API.
*
* TODO: Deprecate?
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class InnertubeContext
{
/**
* Convert an integer to a ULEB128 binary for use in
* synthesising protobuf.
*
* This should be deprecated in the future.
*
* @param int $int to convert
* @return string uleb128 binary
*/
public static function int2uleb128($int)
{
// this is awful
// i hate the person who wrot ethis
if ($int < 128) return chr($int);
$out = decbin($int);
while (0 != strlen($out) % 7)
{
$out = '0' . $out;
}
$out = str_split($out, 7);
for ($i = 0; $i < count($out); $i++)
{
if (0 != $i)
{
$out[$i] = '1' . $out[$i];
}
else
{
$out[$i] = '0' . $out[$i];
}
}
$out = array_reverse($out);
$out = implode('', $out);
$out = str_split($out, 8);
$out2 = "";
for ($i = 0; $i < count($out); $i++)
{
$out2 .= chr( bindec($out[$i]) );
}
return $out2;
}
/**
* Generate an encoded YouTube visitor data string.
*
* @param string $visitor
* @return string encoded visitor data
*/
public static function genVisitorData($visitor)
{
// Generate visitorData string
if (is_null($visitor)) return "";
$date = time();
return Base64Url::encode(
chr(0x0a) . self::int2uleb128( strlen($visitor) ) . $visitor . chr(0x28) . self::int2uleb128($date)
);
}
/**
* Generate an InnerTube context template.
*
* @param string|int $cname (client name) enum or index
* @param string $cver (client version) number
* @param string|null $visitorData
* @param string $hl (host language)
* @param string $gl (global location)
*
* @return object InnerTube context
*/
public static function generate($cname, $cver, $visitorData = null, $hl = 'en', $gl = 'US')
{
if (is_null($visitorData)) $visitorData = ContextManager::$visitorData;
return (object) [
'context' => (object) [
'client' => (object) [
'hl' => $hl,
'gl' => $gl,
'visitorData' => self::genVisitorData($visitorData),
'clientName' => $cname,
'clientVersion' => $cver,
'userAgent' => $_SERVER['HTTP_USER_AGENT'] ?? ""
],
'user' => (object) [
'lockedSafetyMode' => false
],
'request' => (object) [
'useSsl' => true,
'internalExperimentFlags' => [],
'consistencyTokenJars' => []
]
]
];
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike;
use Twig\TwigFunction, Twig\TwigFilter;
use Rehike\ControllerV2\Core as ControllerV2;
/**
* Implements the template manager.
*
* This manages Twig and provides an API for interacting with its
* bound instance.
*
* It generally exists just to get the Twig instance away from the global
* scope for code safety.
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class TemplateManager
{
// Must be an reference to the global Twig instance.
/** @var \Twig\Environment */
public static $twig;
/** @var string */
public static $template = "";
// Must be a reference to the global context variable.
public static $yt;
public static function __initStatic()
{
$viewsDir = Constants\VIEWS_DIR;
self::$twig = new \Twig\Environment(
new \Twig\Loader\FilesystemLoader(
$_SERVER["DOCUMENT_ROOT"] . "/" . $viewsDir
)
);
ControllerV2::registerTemplateVariable(self::$template);
}
/**
* Register the global state variable ($yt)
*
* @param object $yt (reference)
* @return void
*/
public static function registerGlobalState(&$yt)
{
self::$yt = &$yt;
self::addGlobal("yt", $yt);
}
/**
* Render the template.
*
* @param array $vars to additionally pass
*/
public static function render($vars = [], $template = "")
{
if (!is_array($vars) && !is_null($vars)) throw new \Exception("\$vars must be an array.");
$passedVars = [self::$yt] + $vars;
if ("" == $template) $template = self::$template;
return self::$twig->render("$template.twig", $passedVars);
}
/**
* Add a global variable to the templater.
*
* @param string $name
* @param mixed $value
*/
public static function addGlobal($name, &$value)
{
return self::$twig->addGlobal($name, $value);
}
/**
* Add a function to the templater.
*
* @param string|TwigFunction $name
* @param callback|null $callback
*/
public static function addFunction($name, $callback = null)
{
// $name here is a TwigFunction instance, this ordinarily
// allows creating TwigFunctions on the fly instead.
if ($name instanceof TwigFunction)
{
return self::$twig->addFunction($name);
}
return self::$twig->addFunction(
new TwigFunction($name, $callback)
);
}
/**
* Add a filter to the templater.
*
* @param string|TwigFilter $name
* @param callback|null $callback
*/
public static function addFilter($name, $callback = null)
{
// $name here is a TwigFilter instance, ditto above
if ($name instanceof TwigFilter)
{
return self::$twig->addFilter($name);
}
return self::$twig->addFilter(
new TwigFilter($name, $callback)
);
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike;
use Rehike\ConfigManager\ConfigManager;
use YukisCoffee\PropertyAtPath;
/**
* Implements the Rehike-specific portions of the
* config manager system.
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class RehikeConfigManager extends ConfigManager
{
public static $defaultConfig =
[
"appearance" => [
"modernLogo" => true,
"uploadButtonType" => "MENU",
"largeSearchResults" => true,
"showVersionInFooter" => true,
"usernamePrepends" => false,
"useRyd" => true,
"noViewsText" => false,
"movingThumbnails" => true,
"cssFixes" => true,
"watchSidebarDates" => false,
"watchSidebarVerification" => false,
"oldBestOfYouTubeIcons" => false,
"allCommentsLink" => false
],
"experiments" => [
"useSignInV2" => false
],
"advanced" => [
"enableDebugger" => false
],
"hidden" => [
"securityIgnoreWindowsServerRunningAsSystem" => false
]
];
public static $types =
[
"appearance" => [
"modernLogo" => "bool",
"uploadButtonType" => "enum",
"largeSearchResults" => "bool",
"showVersionInFooter" => "bool",
"usernamePrepends" => "bool",
"useRyd" => "bool",
"noViewsText" => "bool",
"movingThumbnails" => "bool",
"cssFixes" => "bool",
"watchSidebarDates" => "bool",
"watchSidebarVerification" => "bool",
"oldBestOfYouTubeIcons" => "bool",
"allCommentsLink" => "bool"
],
"experiments" => [
"useSignInV2" => "bool"
],
"advanced" => [
"enableDebugger" => "bool"
],
"hidden" => [
"securityIgnoreWindowsServerRunningAsSystem" => "bool"
]
];
// Old config compatibility map
// These are PropertyAtPath (JS-style) paths
public static $compatibilityMap = [
"useRingoBranding" => "appearance.modernLogo",
"uploadMenuType" => "appearance.uploadButtonType",
"versionInFooter" => "appearance.showVersionInFooter",
"useReturnYouTubeDislike" => "appearance.useRyd",
"enableRehikeDebugger" => "advanced.enableDebugger",
"largeSearchThumbs" => "appearance.largeSearchResults",
"byTextOnByline" => "appearance.usernamePrepends",
"noViewsText" => "appearance.noViewsText",
"movingThumbnails" => "appearance.movingThumbnails",
"hhCSSFixes" => "appearance.cssFixes",
"watchSidebarDates" => "appearance.watchSidebarDates",
"teaserReplies" => "appearance.teaserReplies",
"oldBestOfYouTubeIcons" => "appearance.oldBestOfYouTubeIcons",
"guideOnWatchPage" => "REMOVE",
"useWebV2HomeEndpoint" => "REMOVE",
"useGridHomeStyle" => "REMOVE",
"accountPickerYtStudio" => "REMOVE",
"general.teaserReplies" => "REMOVE"
];
/**
* If configuration doesn't exist upon
* attempt to load it, save it
*
* @return object
*/
public static function loadConfig()
{
if (!file_exists( self::$file ))
{
static::dumpDefaultConfig();
}
parent::loadConfig();
$redump = false;
// Make sure new defaults get added to the config file.
// json_encode wrapped in json_decode as an quick 'n easy
// way to cast all associative arrays to objects
foreach (json_decode(json_encode(self::$defaultConfig)) as $key => $value)
{
if (!isset(self::$config->{$key}))
{
self::$config->{$key} = $value;
$redump = true;
}
else
foreach (self::$defaultConfig[$key] as $option => $val)
{
if (!isset(self::$config->{$key}->{$option}))
{
self::$config->{$key}->{$option} = $val;
$redump = true;
}
}
}
foreach (self::$compatibilityMap as $key => $value) {
try {
if ($value == "REMOVE") {
PropertyAtPath::unset(self::$config, $key);
} else {
$oldCfg = PropertyAtPath::get(self::$config, $key);
if ($oldCfg !== null) {
PropertyAtPath::set(self::$config, $value, $oldCfg);
PropertyAtPath::unset(self::$config, $key);
}
}
$redump = true;
} catch (\YukisCoffee\PropertyAtPathException $e) {}
}
if ($redump) self::dumpConfig();
return self::$config;
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike;
/**
* Used for storing information about the current session.
*
* Because Rehike has limited internationalisation support at the moment,
* this class remains relatively unused.
*
* @author The Rehike Maintainers
*/
class ContextManager
{
/**
* Visitor data from InnerTube.
*
* The server uses this information to synchronise user data between
* sessions if the user is logged out.
*
* @var string
*/
public static $visitorData;
/**
* Host language.
*
* When implemented, this can be synchronised with the "hl" parameter of
* the PREF cookie or retrieved from an initial response. As such, we don't
* need to be mindful of legal values.
*
* @var string
*/
public static $hl = "en";
/**
* Global location.
*
* Synchronised with the "gl" parameter of the PREF cookie.
*
* @var string
*/
public static $gl = "US";
public static function setVisitorData(string $visitor): void
{
self::$visitorData = $visitor;
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike;
use \Rehike\Exception\i18n\I18nUnsupportedFileException;
/**
* Implements the base Rehike internationalisation system.
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class i18n
{
/**
* Declare the default language to be loaded in the case there is no
* fallback.
*
* @var string
*/
protected static $defaultLanguage = "en";
/**
* Declare the global language to be used as a default for all instances.
*
* @var string
*/
protected static $globalLanguage = "en";
/**
* Store all namespaces (instances) so that they may be accessed globally.
*
* @var i18n[]
*/
protected static $namespaces = [];
/**
* Declare an array that will contain all language strings.
*
* @var string[]
*/
protected $strings = [];
/**
* The current language of the instance.
*
* @var string
*/
protected $language = "";
public function __construct()
{
$this->setLanguage(self::$globalLanguage);
}
/**
* Create an instance and store it so that it may be accessed
* globally. This is convenient for most of Rehike's structure.
*
* As this returns a reference, you must use:
*
* $variable = &newNamespace($name)
*
* or you will encounter much confusion.
*
* @see __construct
*/
public static function &newNamespace($name)
{
$i = new static();
self::$namespaces[$name] = &$i;
return $i;
}
/**
* Return a reference to the requested namespace.
*
* As this returns a reference, you must use:
*
* $variable = &getNamespace($name)
*
* or you will encounter much confusion.
*
* @param string $name
* @return i18n
*/
public static function &getNamespace($name)
{
if (!isset(self::$namespaces[$name]))
trigger_error("Namespace $name does not exist", E_USER_WARNING);
return self::$namespaces[$name];
}
/**
* Get the internal strings stored.
*
* @return string[]
*/
public function getStrings() {
return $this->strings;
}
/**
* Determine if a namespace exists.
*
* @return bool
*/
public static function namespaceExists($name)
{
return isset(self::$namespaces[$name]);
}
/**
* Register language definitions from a file.
*
* This supports loading from a JSON list or PHP list.
*
* The PHP type should be used sparingly. It allows for advanced
* use, such as registering functions, but it can cause more
* problems than it solves. It should always return an associative
* array.
*
* @param string $languageName
* @param string $filename
* @return i18n
*/
public function registerFromFile($languageName, $filename)
{
$supportedFileTypes = [
"json",
"php"
];
$fileType = FileSystem::getExtension($filename);
if (in_array($fileType, $supportedFileTypes))
{
if ("json" == $fileType)
{
$rawFile = FileSystem::getFileContents($filename);
$json = json_decode($rawFile, true);
self::registerFromArray($languageName, $json);
}
else if ("php" == $fileType)
{
// PHP format should be well formed and return an array.
// This is presumed. Don't fuck up.
$result = include $filename;
if (is_array($result))
{
self::registerFromArray($languageName, $result);
}
else
{
throw new I18nUnsupportedFileException(
"Unsupported language file $filename. PHP type files must return an associative array."
);
}
}
}
else
{
throw new I18nUnsupportedFileException(
"Unsupported file type $fileType in file $filename."
);
}
return $this;
}
/**
* Register language definitions, per language, from a folder.
*
* As this relies on the above function, it inherits the same
* general functionality from it.
*
* @param string $folderName
* @return i18n
*/
public function registerFromFolder($folderName)
{
foreach (glob("$folderName/*") as $file)
{
// Isolate the file name itself.
$languageName = explode("/", $file);
$languageName = $languageName[count($languageName) - 1];
$languageName = explode(".", $languageName)[0];
// Register from a file this path.
self::registerFromFile($languageName, $file);
}
return $this;
}
/**
* Register a language array
*
* @param string $name
* @param string[] $array of language strings
* @return i18n
*/
public function registerFromArray($name, $array)
{
$this->strings += [$name => &$array];
return $this;
}
/**
* Legacy alias for registerFromArray.
*
* @deprecated
* @see registerFromArray
*/
public function register($name, $array)
{
trigger_error("i18n::register is deprecated. Use i18n::registerFromArray instead.", E_USER_DEPRECATED);
return self::registerFromArray($name, $array);
}
/**
* Get a string definition by its ID.
*
* @param string $id of the string
* @return string
*/
protected function getStringId($id)
{
// Try the instance's registered definitions, then fallback to the
// global default, and finally return null if nothing worked out.
return @$this->strings[$this->language][$id]
?? @$this->strings[self::$defaultLanguage][$id]
?? null
;
}
/**
* Get a string's contents.
*
* @param string $id of the string
* @param mixed[] $params
*/
public function get($id, ...$params)
{
$string = self::getStringId($id);
if (is_string($string))
{
return sprintf($string, ...$params);
}
else
{
return $string;
}
}
public function __get($id)
{
// Convert a magic instance getter to an ID (without further arguments)
return $this->get($id);
}
public function __call($id, $args)
{
// Convert a magic instance call to an ID (with arguments!)
return $this->get($id, ...$args);
}
/**
* Set the active language of an instance.
*
* @param string $value
* @return void
*/
public function setLanguage($value)
{
$this->language = $value;
}
/**
* Get the active language of an instance.
*
* @return string
*/
public function getLanguage() {
return $this->language;
}
/**
* Set the global language used by the system.
*
* @param string $value
* @return void
*/
public static function setGlobalLanguage($value)
{
self::$globalLanguage = $value;
}
/**
* Set the default (fallback) language of the system.
*
* @param string $value
* @return void
*/
public static function setDefaultLanguage($value)
{
self::$defaultLanguage = $value;
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike;
/**
* Implement the template function container.
*
* This was created primarily to move away from the
* previous solution, which polluted the global scope with
* reference variables to the template functions (which are sometimes
* used within PHP for convenience, think a shared function).
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class TemplateFunctions
{
/**
* Registry of template functions
*
* @var callback[]
*/
protected static $registry = [];
public static function __callStatic($name, $args)
{
if ($function = @self::$registry[$name])
{
return $function(...$args);
}
else
{
throw new \BadMethodCallException("Method does not exist.");
}
}
/**
* Register a template function.
*
* @param string $name of the function
* @param callback $function
*/
public static function register($name, $function)
{
self::$registry += [$name => $function];
TemplateManager::addFunction($name, $function);
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike;
use Rehike\Exception\Network\InnertubeFailedRequestException;
use Rehike\Signin\AuthManager;
use YukisCoffee\CoffeeRequest\CoffeeRequest;
use YukisCoffee\CoffeeRequest\Promise;
use YukisCoffee\CoffeeRequest\Network\Request;
use YukisCoffee\CoffeeRequest\Network\Response;
/**
* Implements a network manager for Rehike.
*
* @version 2.0
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class Network
{
protected const INNERTUBE_API_HOST = "https://www.youtube.com";
protected const INNERTUBE_API_KEY = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8";
protected const V3_API_HOST = "https://www.googleapis.com";
protected const V3_API_KEY = "AIzaSyAa8yy0GdcGPHdtD083HiGGx_S0vMPScDM";
protected const DNS_OVERRIDE_HOST = "1.1.1.1";
/**
* Contains headers meant to be sent only to InnerTube requests.
*
* For example, authentication headers.
*
* @var string[]
*/
protected static array $innertubeHeaders = [];
// Disable instances
private function __construct() {}
/**
* Make a generic URL request.
*
* @return Promise<Response>
*/
public static function urlRequest(string $url, array $opts = []): Promise/*<Response>*/
{
return CoffeeRequest::request($url, $opts);
}
/**
* Make a first-party (youtube.com) URL request.
*
* Unlike the standard function, this will forward the user's YouTube authentication data.
* Do not use this function for foreign requests.
*
* This is used occassionally for non-InnerTube APIs that still need access to the user's
* account, i.e. /getAccountSwitcherEndpoint.
*
* @return Promise<Response>
*/
public static function urlRequestFirstParty(string $url, array $opts = []): Promise/*<Response>*/
{
if (isset($opts["headers"]))
{
$opts["headers"] += self::$innertubeHeaders;
}
else
{
$opts["headers"] = self::$innertubeHeaders;
}
return self::urlRequest($url, $opts);
}
/**
* Make a InnerTube request.
*
* @return Promise<Response>
*/
public static function innertubeRequest(
string $action,
array $body = [],
string $clientName = "WEB",
string $clientVersion = "2.20230331.00.00",
bool $ignoreErrors = false
): Promise/*<Response>*/
{
$host = self::INNERTUBE_API_HOST;
$key = self::INNERTUBE_API_KEY;
// Fucking cursed
$body = (object)($body + (array)InnertubeContext::generate(
$clientName, $clientVersion
));
return new Promise(function ($resolve, $reject)
use ($action,
$body,
$clientName,
$clientVersion,
$host,
$key,
$ignoreErrors)
{
CoffeeRequest::request(
"{$host}/youtubei/v1/{$action}?key={$key}",
[
"headers" => ([
"Content-Type" => "application/json",
"X-Goog-Visitor-Id" => InnertubeContext::genVisitorData(ContextManager::$visitorData)
] + self::$innertubeHeaders),
"method" => "POST",
"body" => json_encode($body),
"onError" => "ignore",
"dnsOverride" => self::DNS_OVERRIDE_HOST
]
)->then(function ($response) use ($resolve, $reject, $ignoreErrors) {
if ( (200 == $response->status) || (true == $ignoreErrors) )
{
$resolve($response);
}
else
{
$reject(new InnertubeFailedRequestException(
$response
));
}
});
});
}
/**
* Request the public YouTube Data API v3.
*
* This uses a unique key, and as such, doesn't have any limitations.
*
* @author Aubrey Pankow <[email protected]>
* @return Promise<Response>
*/
public static function dataApiRequest(
string $action,
array $params,
bool $post = false
): Promise/*<Response>*/
{
$host = self::V3_API_HOST;
$key = self::V3_API_KEY;
$urlParams = "";
if (!$post) {
foreach($params as $name => $value) {
$urlParams .= "&{$name}={$value}";
}
}
$headers = [
"X-Origin" => "https://explorer.apis.google.com",
"X-Referer" => "https://explorer.apis.google.com",
"X-Requested-With" => "XMLHttpRequest",
"X-Client-Data" => "CKe1yQEIkrbJAQiktskBCKmdygEIoO/KAQiSocsBCIWgzQEI+LHNAQjatM0BCNy9zQEIu77NAQj+v80BCOfBzQEIssPNAQjuxM0BCI3FzQEIwcXNARiNp80B",
"X-Clientdetails" => "appVersion=5.0%20(Windows%20NT%2010.0%3B%20Win64%3B%20x64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F115.0.0.0%20Safari%2F537.36&platform=Win32&userAgent=Mozilla%2F5.0%20(Windows%20NT%2010.0%3B%20Win64%3B%20x64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F115.0.0.0%20Safari%2F537.36",
"X-Javascript-User-Agent" => "apix/3.0.0 google-api-javascript-client/1.1.0",
"Referer" => "https://content-youtube.googleapis.com/static/proxy.html?usegapi=1&jsh=m%3B%2F_%2Fscs%2Fabc-static%2F_%2Fjs%2Fk%3Dgapi.lb.en.5o5-TAFr18s.O%2Fd%3D1%2Frs%3DAHpOoo_qgszOsFrBH7bZ1Rmfwa9Mc03wLQ%2Fm%3D__features__",
"Accept" => "application/json",
"User-Agent" => $_SERVER["HTTP_USER_AGENT"]
?? "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0"
];
if ($post) {
$headers += [
"Content-Type" => "application/json"
];
}
$body = [
"headers" => $headers
];
if ($post) {
$body += [
"body" => $params,
"method" => "POST"
];
} else {
$body += [
"method" => "GET"
];
}
return CoffeeRequest::request(
"{$host}/youtube/v3/{$action}?key={$key}{$urlParams}",
$body
);
}
/**
* Get the default options for any non-InnerTube YouTube request.
*
* These are merged with other user options to provide a desired
* outcome.
*/
public static function getDefaultYoutubeOpts(): array
{
return [
"dnsOverride" => self::DNS_OVERRIDE_HOST,
"headers" => [
"Cookie" => self::getCurrentRequestCookie()
]
];
}
/**
* Run all requests made.
*/
public static function run(): void
{
CoffeeRequest::run();
}
/**
* Called by the auth service in order to request the network
* manager use it.
*
* @internal
*/
public static function useAuthService(): void
{
if (AuthManager::shouldAuth())
{
self::$innertubeHeaders += [
"Authorization" => AuthManager::getAuthHeader(),
"Origin" => "https://www.youtube.com",
"Host" => "www.youtube.com",
"Cookie" => self::getCurrentRequestCookie()
];
}
}
/**
* Called by the auth service requesting the network manager to use
* its GAIA ID.
*
* @internal
*/
public static function useAuthGaiaId(): void
{
$gaiaId = AuthManager::getGaiaId();
/*
* No GAIA ID is reported for channels associated with the Google
* account itself. Only brand accounts must account for the distinction.
*/
if ("" != $gaiaId)
{
self::$innertubeHeaders += [
/*
* TODO(dcooper): Invalid AuthUser use.
*
* AuthUser is used to switch between Google accounts (i.e.
* Gmail addresses themselves) and should not be hardcoded as
* zero as this will result in the wrong account being used by
* Rehike.
*/
"X-Goog-AuthUser" => "0",
"X-Goog-PageId" => $gaiaId
];
}
}
/**
* Convert the PHP cookie array to a HTTP header string.
*/
protected static function getCurrentRequestCookie(): string
{
if (empty($_COOKIE)) return "";
$cookies = "";
// Stringify cookies into HTTP format.
foreach ($_COOKIE as $cookie => $value)
{
$cookies .= $cookie . '=' . $value . '; ';
}
return $cookies;
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike;
use YukisCoffee\CoffeeRequest\CoffeeRequest;
use YukisCoffee\CoffeeRequest\Promise;
use YukisCoffee\CoffeeRequest\Network\Request;
use YukisCoffee\CoffeeRequest\Network\Response;
use YukisCoffee\CoffeeRequest\Network\ResponseHeaders;
/**
* A simple tool to funnel requests from a certain domain, while ignoring any
* proxies active
*
* @author Aubrey Pankow <[email protected]>
* @author Taniko Yamamoto <[email protected]>
*/
class SimpleFunnel
{
/**
* Hostname for funnelCurrentPage.
*
* @var string
*/
private static $hostname = "www.youtube.com";
/**
* Remove these request headers.
* LOWERCASE ONLY
*
* @var string[]
*/
public static $illegalRequestHeaders = [
"accept",
"accept-encoding",
"host",
"origin",
"referer"
];
/**
* Remove these response headers.
* LOWERCASE ONLY
*
* @internal
* @var string[]
*/
public static $illegalResponseHeaders = [
"content-encoding",
"content-length"
];
/**
* Funnel a response through.
*
* @param array $opts Options such as headers and request method
* @return Promise<SimpleFunnelResponse>
*/
public static function funnel(array $opts): Promise/*<SimpleFunnelResponse>*/
{
// Required fields
if (!isset($opts["host"]))
self::error("No hostname specified");
if (!isset($opts["uri"]))
self::error("No URI specified");
// Default options
$opts += [
"method" => "GET",
"useragent" => "SimpleFunnel/1.0",
"body" => "",
"headers" => []
];
$headers = [];
foreach ($opts["headers"] as $key => $val) {
if (!in_array(strtolower($key), self::$illegalRequestHeaders)) {
$headers[$key] = $val;
}
}
$headers["Host"] = $opts["host"];
$headers["Origin"] = "https://" . $opts["host"];
$headers["Referer"] = "https://" . $opts["host"] . $opts["uri"];
// Set up cURL and perform the request
$url = "https://" . $opts["host"] . $opts["uri"];
// Set up the request.
$params = [
"method" => $opts["method"],
"headers" => $headers,
"redirect" => "manual",
];
if ("POST" == $params["method"])
{
$params["body"] = $opts["body"];
}
$wrappedResponse = new Promise/*<Response>*/;
$request = CoffeeRequest::request($url, $params);
$request->then(function($response) use ($wrappedResponse) {
$wrappedResponse->resolve(SimpleFunnelResponse::fromResponse($response));
});
CoffeeRequest::run();
return $wrappedResponse;
}
/**
* Output an error.
*/
private static function error(string $message): void
{
http_response_code(500);
echo("
<title>SimpleFunnel Error</title>
<style>body>*{margin:8px 0}</style>
<h2>An error has occured in SimpleFunnel</h2>
<p><b>Error</b>: " . $message . "</p>
<small><i>Please report this to the GitHub.</i></small>
");
return;
}
/**
* Funnel a page with the current data.
*
* @return Promise<SimpleFunnelResponse>
*/
public static function funnelCurrentPage(): Promise/*<SimpleFunnelResponse>*/
{
return self::funnel([
"method" => $_SERVER["REQUEST_METHOD"],
"host" => self::$hostname,
"uri" => $_SERVER["REQUEST_URI"],
"useragent" => $_SERVER["HTTP_USER_AGENT"],
"body" => file_get_contents("php://input"),
"headers" => getallheaders()
]);
}
}
/**
* A custom class that represents a SimpleFunnel response.
*
* @author Taniko Yamamoto <[email protected]>
*/
class SimpleFunnelResponse extends Response
{
public static function fromResponse(Response $response): self
{
return new self(
source: $response->sourceRequest,
status: $response->status,
content: $response->getText(),
headers: self::processResponseHeaders($response->headers)
);
}
/**
* Output the response of the page.
*/
public function output(): void
{
http_response_code($this->status);
foreach($this->headers as $name => $value)
{
header("$name: $value");
}
echo($this->getText());
exit();
}
/**
* Process the response headers and remove illegal headers.
*/
private static function processResponseHeaders(ResponseHeaders $headers): array
{
$result = [];
foreach ($headers as $name => $value)
{
if (!in_array(strtolower($name), SimpleFunnel::$illegalResponseHeaders))
{
$result[$name] = $value;
}
}
return $result;
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike;
/**
* Manages security checks.
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class SecurityChecker
{
private static bool $isSecure = true;
private static int $securityFactor = 0;
public static function __initStatic()
{
$securityFactor = 0;
if ("windows nt" == strtolower(php_uname('s')))
{
$securityFactor |= 2 * (int)self::windowsNtIsRunningAsSystem();
}
self::$securityFactor = $securityFactor;
self::$isSecure = $securityFactor == 0;
}
public static function isSecure(): bool
{
return self::$isSecure;
}
public static function windowsNtIsRunningAsSystem($dontLie = false): bool
{
$disabled = $dontLie || (RehikeConfigManager::getConfigProp(
"hidden.securityIgnoreWindowsServerRunningAsSystem"
) == true);
if (!$disabled)
{
$currentUser = @get_current_user();
if ("SYSTEM" == trim($currentUser))
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike;
use stdClass;
use Rehike\Model\{
Appbar\MAppbar,
Masthead\MMasthead,
Footer\MFooter
};
use Rehike\Player\PlayerInfo;
/**
* Defines the global state for the Rehike application.
*
* This is used as the primary information sent to the templater, and thus
* contains all information needed to generate a valid YouTube page. It is
* also a huge mess.
*
* A bit of history: this is an evolution of a project-long global object
* named $yt. Before a codebase cleanup over a year after the project started,
* this object was just an (object)[] (i.e. an stdClass).
*
* As a result, this class is going to be a little messy. Moving to a proper
* class still allows us to benefit from type safety and IDE static analysis.
*
* @author Aubrey Pankow <[email protected]>
* @author Taniko Yamamoto <[email protected]>
* @author Daylin Cooper <[email protected]>
* @author The Rehike Maintainers
*/
class YtApp extends stdClass
{
private static YtApp $instance;
public function __construct()
{
self::$instance = $this;
}
public static function getInstance(): YtApp
{
return self::$instance;
}
/**
* Stores the contents of the page.
*
* This can be literally anything, so long as it is a valid object. Each
* page has different content specifications, after all.
*
* TODO (kirasicecreamm): Deprecate support for associative array page
* types (i.e. comment service ajax).
*/
public object|array $page;
/**
* Stores data for the masthead of the page.
*
* This includes the entire top of the page with the search bar, guide
* button, etc.
*/
public MMasthead $masthead;
/**
* Stores data for the footer of the page.
*
* The footer is displayed at the bottom of the page and contains links
* to informational parts of YouTube (i.e. TOS), as well as contains user-
* customisation buttons.
*/
public MFooter $footer;
/**
* Data for the "appbar" navigation bar.
*
* This is displayed under the masthead on the home page and channels,
* and contains vertical tabs that follow the user.
*/
public MAppbar $appbar;
/**
* Determines if the current session should allow further SPF navigations.
*
* This is set by page-specific controllers.
*/
public bool $spfEnabled = false;
/**
* Determines if the current session currently uses SPF navigation.
*
* This is set to true before rendering by the SPF controller.
*/
public bool $spf = false;
/**
* Determines if the current page should use the revamped module system
* used by YouTube since 2014.
*
* This is set by page-specific controllers.
*/
public bool $useModularCore = false;
/**
* Stores a set of modules to request the use of.
*
* This is only applicable if $useModularCore is true, otherwise all
* contents of this variable are ignored.
*/
public array $modularCoreModules = [];
/**
* Stores information about the player configuration.
*
* This is used for player bootstrapping on the client-side.
*/
public PlayerInfo $playerConfig;
/**
* Client-side preferences of the user.
*/
public object $PREF;
/**
* Stores common i18n message strings.
*/
public array $msgs = [];
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\Util;
use function base64_encode;
use function base64_decode;
/**
* Provides common base64 utilities.
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class Base64
{
public static function encode(string $data): string
{
return base64_encode($data);
}
public static function decode(string $data): string
{
return base64_decode($data);
}
public static function urlEncode(string $data): string
{
return Base64Url::encode($data);
}
public static function urlDecode(string $data): string
{
return Base64Url::decode($data);
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\Util;
use Rehike\Misc\ResourceConstantsStore;
use Rehike\Util\Exception\ResourceUtils\BadResourceException;
/**
* Provides helper functions for getting resource locations.
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class ResourceUtils
{
/**
* Get the CSS path of a resource from its name.
*/
public static function cssPath(string $name): string
{
$constants = ResourceConstantsStore::get();
$css2x = false;
// TODO: add css 2x check
if (isset($constants->css->{$name}))
{
return $constants->css->{$name};
}
else
{
throw new BadResourceException(
"Unknown CSS resource name \"$name\""
);
}
}
/**
* Get the JS path of a resource from its name.
*/
public static function jsPath(string $name): string
{
$constants = ResourceConstantsStore::get();
if (isset($constants->js->{$name}))
{
return $constants->js->{$name};
}
else
{
throw new BadResourceException(
"Unknown JS resource name \"$name\""
);
}
}
/**
* Get the path of a static image resource from its name.
*/
public static function imgPath(string $name): string
{
$constants = ResourceConstantsStore::get();
if (isset($constants->img->{$name}))
{
return $constants->img->{$name};
}
else
{
throw new BadResourceException(
"Unknown image resource name \"$name\""
);
}
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\Util;
/**
* Provides common string case conversion utilities.
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class CasingUtils
{
/**
* Convert a CONSTANT_CASE string to a hyphen-case string.
*
* This may be useful in a number of areas, but it's particularly
* useful for HTML IDs, i.e in the guide.
*/
public static function constantToHyphen(string $constCase): string
{
return strtolower(
str_replace("_", "-", $constCase)
);
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\Util;
use \Rehike\Util\Base64Url;
use \Com\Google\Protos\Youtube\Api\Innertube\BrowseContinuation;
use \Com\Google\Protos\Youtube\Api\Innertube\BrowseContinuationAppendAction;
use \Com\Google\Protos\Youtube\Api\Innertube\BrowseContinuationWrapper;
use \Com\Google\Protos\Youtube\Api\Innertube\ContinuationTypeWrapper;
use \Com\Google\Protos\Youtube\Api\Innertube\ContinuationWrapper;
/**
* Used to request shelves homepage using the WEB v2 InnerTube client.
*
* @author Aubrey Pankow <[email protected]>
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class WebV2Shelves {
/**
* Convert a shelves client continuation to a WEB-compatible one.
*
* The code is quite disgusting for this, however it's a quite simple modification. This digs
* into the inner layers of this code to change two variables to convert the type, then returns
* a new valid continuation.
*
* @param string $continuation A continuation from a client with shelves, i.e. ANDROID, IOS, TVHTML5.
* @return string A web continuation.
*/
public static function continuationToWeb(string $continuation): string {
$decoded = Base64Url::decode($continuation);
$contWrapper = new ContinuationWrapper();
$contTypeWrapper = new ContinuationTypeWrapper();
$browseCont = new BrowseContinuation();
// Unwrap in order to modify the class.
$contWrapper->mergeFromString($decoded);
$innerWrapper = $contWrapper->getBrowseContinuation();
$rawTypeWrapper = Base64Url::decode($innerWrapper->getEncodedAction());
$contTypeWrapper->mergeFromString($rawTypeWrapper);
$rawBrowseContinuation = Base64Url::decode($contTypeWrapper->getReloadContinuation());
$browseCont->mergeFromString($rawBrowseContinuation);
// Now work in reverse to form a new continuation token.
$browseCont->clearReloadAction();
$browseCont->setAppendAction(new BrowseContinuationAppendAction(["a" => 0]));
$newBrowseContinuation = Base64Url::encode($browseCont->serializeToString());
$ctwBuilder = new ContinuationTypeWrapper();
$ctwBuilder->setAppendContinuation($newBrowseContinuation);
$newTypeWrapper = Base64Url::encode($ctwBuilder->serializeToString());
$bcwBuilder = new BrowseContinuationWrapper();
$bcwBuilder->setBrowseId("FEwhat_to_watch");
$bcwBuilder->setEncodedAction($newTypeWrapper);
$bcwBuilder->setTargetId("browse-feedFEwhat_to_watch");
$newInnerWrapper = $bcwBuilder->serializeToString();
$cwBuilder = new ContinuationWrapper();
$cwBuilder->setBrowseContinuation($bcwBuilder);
$newOuterWrapper = Base64Url::encode($cwBuilder->serializeToString());
return $newOuterWrapper;
}
}
| {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\Util;
use function count;
use function array_key_last;
use function preg_replace;
/**
* Provides common InnerTube parsing utilities for Rehike.
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class ParsingUtils
{
/**
* Get the text content of an InnerTube API response field.
*/
public static function getText(mixed $source): ?string
{
// Determine the source type and act accordingly.
if (is_object($source))
{
/*
* InnerTube has two main text types:
*
* - runs: Fragments of formatted text separated into an
* array for further parsing. Runs should typically
* be parsed contextually or with a different method
* during templating, rather than by this function.
*
* - simpleText: Unformatted raw strings.
*
* Rarely, these are even used interchangeably. It just helps
* to have a single function that can handle both cases and
* return a single, unformatted string.
*/
if (isset($source->runs))
{
$response = "";
foreach ($source->runs as $run)
{
$response .= $run->text;
}
return $response;
}
else if (isset($source->simpleText))
{
return $source->simpleText;
}
}
else if (is_string($source))
{
return $source;
}
// If no text is found, return null so that further code can
// handle error cases.
return null;
}
public static function getUrl(mixed $source): ?string
{
return @$source->navigationEndpoint->commandMetadata->webCommandMetadata->url
?? @$source->navigationEndpoint->confirmDialogEndpoint->content->confirmDialogRenderer->confirmButton->buttonRenderer->command->urlEndpoint->url
?? @$source->commandMetadata->webCommandMetadata->url
?? null;
}
/**
* Get the thumbnail of an InnerTube API response field.
*
* This will work on anything from video renderers to avatar images
* for users.
*/
public static function getThumb(object $container, int $height = 0): ?string
{
// We no longer support other access methods.
if (!isset($container->thumbnails)) return null;
$thumbs = &$container->thumbnails;
$thumb = null;
foreach ($thumbs as $ithumb)
{
if (isset($ithumb->height) && $ithumb->height >= $height)
{
$thumb = $ithumb;
}
}
if (is_null($thumb))
{
// If there's no height specified, then use the largest one.
$thumb = $thumbs[array_key_last($thumbs)];
}
// We need to check that the width and height are above 0, because
// sometimes InnerTube thumbnails have the height set to 0 (for
// instance, live stream thumbnails in the notifications menu), and
// that will cause a division by zero error.
if (
isset($thumb->width) &&
isset($thumb->height) &&
$thumb->width > 0 &&
$thumb->height > 0
)
{
$ratio = $thumb->width / $thumb->height;
// 16:9 is 1.777 repeating. The imprecise equation here is done
// for some edge cases like 1366:768, which is only approximately
// 16:9 but would still be regarded as such.
//
// There is also an isOriginalAspectRatio variable that indicates
// if the thumbnail is not 16:9 and that the URL is a link to the
// image in its original aspect ratio (would be stretched).
$isShort = !($ratio >= 1.7 && $ratio < 1.8) || @$container->isOriginalAspectRatio;
// If the video is a Short, we want to remove the sqp param to
// remove any cropping. We also want to switch the oar2 thumb
// type for hqdefault, since oar2 contains cropping by default.
// With an ideal i.ytimg.com server, we could use maxresdefault.
// However, not every thumbnail has a maxresdefault/hq720 variant.
if ($isShort)
{
$url = preg_replace("/\?sqp=.*/", "", $thumb->url);
return str_replace("oar2", "hqdefault", $url);
}
else
{
return $thumb->url;
}
}
// If the width or height is 0, just return the URL. It is very likely
// that the thumbnail is already in the correct format.
else
{
return $thumb->url;
}
return null;
}
/**
* Helper function for finding thumbnail overlays.
*
* This iterates the overlays array and searches for the
* provided identifier.
*
* This is meant to be used as a helper function for Twig.
*
* @author Taniko Yamamoto <[email protected]>
*
* @param object $array of the thumbnail overlays
* @param string $name of the overlay identifier
*
* @return ?object
*/
public static function getThumbnailOverlay(object $array, string $name): ?object
{
if (!isset($array->thumbnailOverlays)) return null;
// Iterate the array and figure out the thumbnail overlay
foreach ($array->thumbnailOverlays as $index => $contents)
{
// InnerTube API formats thumbnail overlays as
// keys within an object. Fortunately, this is pretty
// easy to check within PHP.
if (isset($contents->$name)) return $contents->$name;
}
// Return null if the index doesn't exist.
return null;
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\Util;
use Rehike\i18n;
/**
* General string handler/substring extraction utilities for Rehike.
*
* @author Aubrey Pankow <[email protected]>
* @author The Rehike Maintainers
*/
class ExtractUtils {
/**
* Isolate any count with a set input by replacing other parts of a
* substring with an empty string.
*
* @param $input Base string.
* @param $substrRegex Substrings to replace
*/
public static function isolateCount(?string $input, string $substrRegex): string {
if (!$input) return '';
return preg_replace(
$substrRegex,
'',
$input
);
}
/**
* Isolate a watch page's like count from the accessibility string.
*
* @param $likeCount Base string to modify.
*/
public static function isolateLikeCnt(?string $likeCount): string {
$i18n = i18n::getNamespace("main/regex");
$a = self::isolateCount($likeCount, $i18n->get("likeCountIsolator"));
if ($a != $i18n->get("likeTextDisabled")) {
return $a;
} else {
return '';
}
}
/**
* Isolate a channel's subscriber count from the subscriber count text.
*
* Ordinarily, counts are returned in a format like "1.23K subscribers".
*
* @param $subCount Base string to modify.
*/
public static function isolateSubCnt(?string $subCount): string {
$i18n = i18n::getNamespace("main/regex");
$a = self::isolateCount($subCount, $i18n->get("subscriberCountIsolator"));
if ($a != $i18n->get("countZero")) {
return $a;
} else {
return '0';
}
}
/**
* Isolate a videos view count from the common view count text.
*
* "120,000 views" => "120,000"
* "No views" => "0"
*
* BUG(dcooper): This function will only work in English, as although the
* isolator string is obtained from i18n, the "No" substring is still
* hardcoded in English only.
*
* @param $viewCount Base string to modify.
*/
public static function isolateViewCnt(?string $viewCount): string {
$i18n = i18n::getNamespace("main/regex");
$a = self::isolateCount($viewCount, $i18n->get("viewCountIsolator"));
if ($a != $i18n->get("countZero")) {
return $a;
} else {
return '0';
}
}
/**
* Resolve the date string to use within a video's secondary info renderer
* above the description on the watch page.
*
* @param string $date Original date.
* @param string $isPrivate Is the video not publicly available?
*
* @return string
*/
public static function resolveDate($date, $isPrivate = false) {
$i18n = i18n::getNamespace("main/regex");
$misc = i18n::getNamespace("main/misc");
if (is_object($date)) $date = $date->simpleText;
if (!preg_match($i18n->get("nonPublishCheck"), $date)) {
$string = $isPrivate ? "dateTextPrivate" : "dateTextPublic";
return $misc->get($string, $date);
} else {
return $date;
}
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\Util;
/**
* A set of utilities for parsing YouTube's PREF cookie.
*
* @author Aubrey Pankow <[email protected]>
* @author The Rehike Maintainers
*/
class PrefUtils {
/**
* Parse the PREF cookie.
*
* @var string $pref PREF cookie.
* @return object
*/
public static function parse($pref) {
$response = (object) [];
$temp = explode("&", $pref);
foreach ($temp as $value) {
$temp2 = explode("=", $value);
$response->{$temp2[0]} = $temp2[1];
}
return $response;
}
/**
* Is autoplay enabled?
*
* @var object $pref Parsed PREF value.
* @return bool
*/
public static function autoplayEnabled($pref) {
if (isset($pref->f5) && substr($pref->f5, 0, 1) == "3") {
return false;
}
return true;
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\Util;
use Rehike\Exception\Network\InnertubeFailedRequestException;
use Rehike\Network;
use YukisCoffee\CoffeeRequest\Promise;
use Rehike\Signin\API as SignIn;
use YukisCoffee\CoffeeRequest\Exception\GeneralException;
use function Rehike\Async\async;
/**
* General utilties for channels.
*
* @author Aubrey Pankow <[email protected]>
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class ChannelUtils
{
/**
* Get a channel's UCID from an internal request URL.
*
* @return Promise<?string>
*/
public static function getUcid($request): Promise/*<?string>*/
{
return async(function() use (&$request) {
if (in_array($request->path[0], ["channel", "user", "c"]))
{
switch($request->path[0])
{
case "channel":
$ucid = $request->path[1] ?? "";
if (substr($ucid, 0, 2) == "UC")
{
return $ucid;
}
else
{
return "";
}
break;
case "user":
case "c":
return yield self::getUcidFromUrl(explode("?", $_SERVER["REQUEST_URI"])[0]);
break;
}
}
return yield self::getUcidFromUrl(explode("?", $_SERVER["REQUEST_URI"])[0]);
});
}
// If user is signed in and channel owner, get data for the
// secondary channel header.
public static function getOwnerData(string $ucid): ?object
{
return async(function() use ($ucid) {
$ownerData = null;
if (SignIn::isSignedIn())
{
$info = SignIn::getInfo();
if (@$info["ucid"] == $ucid)
{
$analytics = yield Network::innertubeRequest(
action: "analytics_data/get_screen",
body: [
"desktopState" => [
"tabId" => "ANALYTICS_TAB_ID_OVERVIEW"
],
"fetchingType" => "FETCHING_TYPE_FOREGROUND",
"screenConfig" => [
"currency" => "USD", // Irrelevant, don't change this
"entity" => [
"channelId" => $ucid
],
"timePeriod" => [
"timePeriodType" => "ANALYTICS_TIME_PERIOD_TYPE_LIFETIME"
],
"timeZoneOffsetSecs" => -18000 // This shouldn't matter, so again, don't change
]
],
ignoreErrors: true
);
try
{
$adata = $analytics->getJson();
}
catch (GeneralException $e)
{
return null;
}
if (isset($adata->cards))
{
$ownerData = (object) [];
foreach ($adata->cards as $card)
{
// Views
if ($a = @$card->keyMetricCardData->keyMetricTabs)
foreach ($a as $tabA)
{
if ($b = @$tabA->primaryContent)
if ($b->metric == "VIEWS")
{
$ownerData->views = $b->total;
}
}
elseif ($a = @$card->latestActivityCardData->lifetimeSubsData->metricColumns[0]->counts->values[0])
{
$ownerData->subscribers = $a;
}
}
}
}
}
return $ownerData;
});
}
/**
* Get a channel's UCID from a URL.
*
* @return Promise<?string>
*/
private static function getUcidFromUrl(string $url): Promise/*<?string>*/
{
return async(function() use (&$url) {
$response = (yield Network::innertubeRequest(
action: "navigation/resolve_url",
body: [ "url" => "https://www.youtube.com" . $url ],
ignoreErrors: true // Required for the 404 page instead of uncaught exception.
))->getJson();
if (isset($response->endpoint->browseEndpoint->browseId))
{
return $response->endpoint->browseEndpoint->browseId;
}
// For some handles, resolve_url returns a classic channel
// URL (e.g. https://www.youtube.com/jawed). For every case
// that this happens, you can just make another resolve_url
// request, and it will actually give you the UCID of the
// channel.
else if (isset($response->endpoint->urlEndpoint->url))
{
$response2 = (yield Network::innertubeRequest(
action: "navigation/resolve_url",
body: [ "url" => $response->endpoint->urlEndpoint->url ],
ignoreErrors: true
))->getJson();
return $response2->endpoint->browseEndpoint->browseId ?? null;
}
return null;
});
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\Util;
/**
* Utilities for yt3.ggpht.com and i.ytimg.com
* image URLs
*
* @author Aubrey Pankow <[email protected]>
* @author Daylin Cooper <[email protected]>
*/
class ImageUtils
{
/**
* Change the size attribute of a yt3.ggpht.com image URL
*/
public static function changeSize(string $url, int $size): string
{
return preg_replace("/=s\d+-/", "=s" . (string) $size . "-", $url);
}
/**
* Change the width attribute of a yt3.ggpht.com image URL
*/
public static function changeWidth(string $url, int $width): string
{
return preg_replace("/-w\d+-/", "-w" . (string) $width . "-", $url);
}
/**
* Change the height attribute of a yt3.ggpht.com image URL
*/
public static function changeHeight(string $url, int $height): string
{
return preg_replace("/-h\d+-/", "-h" . (string) $height . "-", $url);
}
/**
* Change the width and height of a yt3.ggpht.com image URL
*/
public static function changeDimensions(string $url, int $width, int $height): string
{
return self::changeHeight(self::changeWidth($url, $width), $height);
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\Util;
/**
* Utilities for generating URL format base64.
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class Base64Url
{
/**
* Encode a string into URL-formatted base64.
*
* @param string $data
* @return string
*/
public static function encode(
mixed $data,
bool $encodePadding = false
): string
{
return str_replace(
["+", "/", "="],
["-", "_", $encodePadding ? "%3D" : ""],
base64_encode($data)
);
}
/**
* Decode a string from URL-formatted base64.
*
* @param string $data
* @return string
*/
public static function decode(mixed $data): string
{
return base64_decode(
str_replace(
["-", "_", "%3D"],
["+", "/", ""],
$data
)
);
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\Util;
/**
* General utilities for converting richShelfRenderers from InnerTube into
* standard shelf renderers.
*
* @author Aubrey Pankow <[email protected]>
* @author The Rehike Maintainers
*/
class RichShelfUtils {
/**
* Reformat a base response.
*/
public static function reformatResponse($response) {
if (!isset($response->onResponseReceivedActions)) return $response;
$contents = [];
foreach ($response->onResponseReceivedActions as $action)
if (isset($action->appendContinuationItemsAction->continuationItems))
foreach ($action->appendContinuationItemsAction->continuationItems as $item)
if (isset($item->richSectionRenderer->content->richShelfRenderer)) {
$contents[] = self::reformatShelf($item);
}
else
{
$contents[] = $item;
}
return (object) [
"sectionListRenderer" => (object) [
"contents" => $contents
]
];
}
/**
* Convert a richShelfRenderer into a standard shelfRenderer (as well as
* any outer wrappers).
*
* @param object $shelf The iteration of shelf to use.=
* @param bool $list Format in list form?
* @return object Modified shelf.
*/
public static function reformatShelf($shelf, $list = false) {
if (!isset($shelf->richSectionRenderer->content->richShelfRenderer)) return $shelf;
$richShelf = $shelf->richSectionRenderer->content->richShelfRenderer;
$response = (object) [];
$response->title = $richShelf->title ?? null;
$response->titleAnnotation = $richShelf->subtitle ?? null;
$response->thumbnail = $richShelf->thumbnail ?? null;
$response->endpoint = $richShelf->endpoint ?? null;
$response->menu = $richShelf->menu ?? null;
$contents = [];
foreach($richShelf->contents as $item)
$contents[] = self::reformatShelfItem($item, $list);
$response->content = (object) [
"horizontalListRenderer" => (object) [
"items" => $contents
]
];
return (object) [
"itemSectionRenderer" => (object) [
"contents" => [
(object) [
"shelfRenderer" => $response
]
]
]
];
return $shelf;
}
/**
* Used to extract richItemRenderers used within rich shelves.
*
* @param object $item richItemRenderer
* @param bool $list Format in list form?
* @return object $richItemRenderer->content
*/
public static function reformatShelfItem($item, $list = false) {
if (isset($item->richItemRenderer->content)) {
foreach ($item->richItemRenderer->content as $key => $val) {
if (!$list) $key = "grid" . ucfirst($key);
return (object) [
$key => $val
];
}
} else {
return $item;
}
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\Util;
/**
* Common watch utilities for Rehike.
*
* @author Aubrey Pankow <[email protected]>
* @author Daylin Cooper <[email protected]>
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class WatchUtils
{
/**
* Get the index of the first autoplay video from a set of recommendations.
*
* The autoplay video must be the first compactVideoRenderer, or regular
* video, that can be accessed in the list. It cannot be a playlist type.
*
* @param object[] $results Recommendations sidebar.
* @param int $index Index to return as well (modified by reference).
*/
public static function getRecomAutoplay($results, &$index = 0)
{
// Splice first video from results and return an index.
for ($i = 0; $i < count($results); $i++) if (isset($results[$i]->compactVideoRenderer))
{
$index = $i;
return $results[$i];
}
}
/**
* Temporary method for finding the comment section
* index.
*
* @author YukisCoffee <[email protected]>
* @param object[] $items array
* @return void
*/
public static function findCommentsSection($items)
{
for ($i = 0, $j = count($items); $i < $j; $i++)
{
if (isset(
$items[$i]->itemSectionRenderer->sectionIdentifier
) &&
"comment-item-section" == $items[$i]->itemSectionRenderer->sectionIdentifier
)
{
return $items[$i]->itemSectionRenderer;
}
}
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\Util\Nameserver;
/**
* Structure storing information used to override the nameserver.
*
* @author Taniko Yamamoto <[email protected]>
*/
class NameserverInfo
{
public string $domain;
public string $ipAddress;
public function __construct(string $domain, string $ipAddress)
{
$this->domain = $domain;
$this->ipAddress = $ipAddress;
}
/**
* Serialize into a common nameserver resolution string.
*
* Example:
* www.example.com:443:127.0.0.1
*/
public function serialize(): string
{
return "$this->domain:$this->ipAddress";
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\Util\Nameserver;
use function shell_exec;
use function filter_var;
use function call_user_func;
use const FILTER_VALIDATE_IP;
use const FILTER_FLAG_IPV4;
use const FILTER_FLAG_IPV6;
// Imports for dns_get_record() approach:
// Yes, they really did go with such bad names for the constants.
use function dns_get_record;
use const DNS_CNAME;
use const DNS_A as DNS_IPV4;
use const DNS_AAAA as DNS_IPV6;
/**
* Utilities for DNS overriding.
*
* It's actually surprisingly difficult to pull this off. Remember
* that not all PHP installs support shell_exec(), different
* techniques are completely different, and IPv6 is technically not
* even backwards compatible with IPv4. It's a huge mess.
*
* Since IPv6 is largely backwards compatible with IPv4 and most
* servers support IPv4, IPv6 support is currently limited.
*
* @author Taniko Yamamoto <[email protected]>
*/
class Nameserver
{
public const DEFAULT_NS = "1.1.1.1";
private function __construct() {}
/**
* Perform a lookup from a standard URL. This is the main API method.
*/
public static function get(
string $uri,
string $nameserver = self::DEFAULT_NS,
int $port = -1
): NameserverInfo
{
// If port is -1, then it is handled as an auto value.
if (-1 == $port)
{
$port = self::guessPort($uri);
}
// Only the hostname may be used in a lookup, never the full
// URI.
$hostname = self::getHostName($uri);
return self::lookup($hostname, $port);
}
/**
* Try a number of DNS lookup strategies and attempt to determine
* the IP that a URI resolves to.
*/
public static function lookup(
string $uri,
int $port,
string $lookupServer = self::DEFAULT_NS
): NameserverInfo
{
$strategies = [
"lookupNative",
"lookupViaShell"
];
foreach ($strategies as $strategy)
{
try
{
return call_user_func(
[self::class, $strategy],
$uri,
$port,
$lookupServer
);
}
catch (DnsLookupException $e) {} // Consume exception
}
// If we got here, all strategies have failed, so throw another
// exception.
throw new DnsLookupException($uri, $lookupServer);
}
/**
* Lookup the IP address of a server natively.
*
* This uses PHP's native DNS library to perform the lookup. This
* approach is preferred over the shell_exec method, however it is
* not guaranteed to work identically.
*/
public static function lookupNative(
string $uri,
int $port,
string $lookupServer
): NameserverInfo
{
// Passed by reference. This needs to be a variable
// AND an array!
$ns = [$lookupServer];
$cname = dns_get_record($uri, DNS_CNAME, $ns);
$requestUri = $uri;
if (isset($cname[0]["target"]))
{
$requestUri = $cname[0]["target"];
}
else
{
throw new DnsLookupException($uri, $lookupServer);
}
$records =
dns_get_record($requestUri, DNS_IPV4, $ns) ??
dns_get_record($requestUri, DNS_IPV6, $ns);
if (!empty($records))
{
foreach ($records as $record) if (self::isValidIp(@$record["ip"]))
{
return new NameserverInfo("$uri:$port", $record["ip"]);
}
}
else
{
throw new DnsLookupException($uri, $lookupServer);
}
}
/**
* Lookup the IP address of a server using a command on the OS.
*
* This strategy relies on PHP being able to interface with the shell
* and the operating system providing the nslookup command.
*
* Since neither of these are guaranteed, this function should rarely
* be used.
*/
public static function lookupViaShell(
string $uri,
int $port,
string $lookupServer
): NameserverInfo
{
$rawResult = shell_exec("nslookup $uri $lookupServer");
$results = explode(" ", $rawResult);
foreach ($results as $result)
{
// Strip whitespace since it will mess up the validation.
$result = preg_replace("/\s+/", "", $result);
if (self::isValidIp($result))
{
return new NameserverInfo("$uri:$port", $result);
}
}
throw new DnsLookupException($uri, $lookupServer);
}
/**
* Guess the port of a URI.
*
* This is easy because the default ports of HTTP and HTTPS are,
* respectively, 80 and 443. Any other port needs to be manually
* specified in the URI.
*/
public static function guessPort(string $uri): int
{
if (strpos($uri, "://") > 0)
{
$protocol = explode("://", $uri)[0];
}
else
{
return 80; // Default HTTP port
}
switch ($protocol)
{
case "https":
case "wss":
// Secure HTTP and WebSocket protocols both operate
// by default on port 443.
return 443;
case "http":
case "ws":
default:
// HTTP and WebSocket both operate by default on port 80.
return 80;
}
}
/**
* Check if an IP address is valid.
*/
public static function isValidIp(string $ip): bool
{
return (bool)(
filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) //||
//filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)
);
}
/**
* Get the hostname of a URI.
*
* This strips the protocol and path of a URL, leaving only the
* hostname.
*
* For example:
* https://www.google.com/search?q=hello
* becomes:
* www.google.com
*/
public static function getHostName(string $uri): string
{
return preg_replace("/([A-Za-z]+:\/\/)|(\/.*)/", "", $uri);
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\Util\Nameserver;
use Rehike\Exception\AbstractException;
/**
* Used by the Nameserver module when an error is encountered during
* DNS lookup.
*
* @author Taniko Yamamoto <[email protected]>
*/
class DnsLookupException extends AbstractException
{
public function __construct(string $uri, string $lookupServer)
{
parent::__construct(
"Failed to get DNS records for $uri using server $lookupServer"
);
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\Util\Exception\ResourceUtils;
use Rehike\Exception\AbstractException;
class BadResourceException extends AbstractException {} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\ControllerV2;
/**
* Implements session caching functionality for imported
* Controller v2 controller modules.
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class ControllerStore
{
/** @var object[] */
protected static $items = [];
/** @return bool */
public static function hasController($name)
{
return isset(self::$items[$name]);
}
/** @return object|null */
public static function getController($name)
{
return self::$items[$name] ?? null;
}
/**
* Add a controller to the session cache.
*
* @return void
*/
public static function registerController($name, $controllerImport)
{
self::$items += [$name => $controllerImport];
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\ControllerV2;
/**
* Implements a wrapper for working with imported controllers.
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class GetControllerInstance
{
/** @var string */
private $controllerName;
/** @var object */
private $boundController;
/** Reference to shorten code. @var string */
const wrap = "_cv2WrappedCallControllerMethod";
public function __construct($name, $binding)
{
$this->controllerName = &$name;
$this->boundController = &$binding;
}
/**
* Wrap a method call.
*
* This allows the calling of static methods through this,
* and also throws an exception if the method does not exist.
*
* @param string $name
* @param mixed[] $args
* @return mixed
*/
protected function _cv2WrappedCallControllerMethod($name, $args)
{
// Check if the method exists in the bound controller
if (method_exists($this->boundController, $name))
{
// Check if the method is static or instantiated
if ( (new \ReflectionMethod($this->boundController, $name))->isStatic() )
{
return $this->boundController::$name(
Core::$state, Core::$template, new RequestMetadata(), ...$args
);
}
else
{
return $this->boundController->{$name}(
Core::$state, Core::$template, new RequestMetadata(), ...$args
);
}
}
else
{
throw new Exception\MethodDoesNotExistException(
"Called method \"{$name}\" does not exist on bound controller " .
"\"{$this->controllerName}\"."
);
}
}
/**
* Redirect any call to this object to the wrapper.
*
* @param string $name
* @param mixed[] $args
* @return mixed
*/
public function __call($name, $args)
{
return $this->{self::wrap}($name, $args);
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\ControllerV2;
use Rehike\DataArray;
/**
* Return accessible information from a request.
*
* This is passed as the third argument of each controller
* function. It provides various metadata, such as the request
* method, path (as an array), and parameters (for GET/POST).
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class RequestMetadata
{
/** @var string */
public $method;
/** @var string[] */
public $path;
/** @var string */
public $rawPath;
/** @var string[] */
public $headers;
/** @var string[]|mixed */
public $params;
/** @var mixed|null */
public $body;
public function __construct()
{
$this->method = $_SERVER['REQUEST_METHOD'];
$this->path = self::getPath();
$this->rawPath = $_SERVER["REQUEST_URI"];
$this->headers = self::getHeaders();
$this->params = new DataArray($_GET);
// Body will only be available for POST requests
if ("POST" == $this->method)
{
$this->body = self::getPostBody($this->headers["Content-Type"] ?? "");
}
else
{
unset($this->body);
}
}
/**
* Get the path name from the request and return it
* as a split array.
*
* @return string
*/
protected static function getPath()
{
// Split the path first by "?" to remove params
$path = explode("?", $_SERVER["REQUEST_URI"])[0];
// Then split it by "/"
$path = explode("/", $path);
// If the first item is empty, remove it
if ("" == $path[0])
{
array_splice($path, 0, 1);
}
return $path;
}
/**
* Get all requested headers.
*
* @return string[]
*/
protected static function getHeaders()
{
// Apache (only) has apache_request_headers
// function:
if (function_exists("\apache_request_headers"))
{
$headers = [];
// Convert all elements to lowercase
foreach (\apache_request_headers() as $key => $value)
{
$headers += [strtolower($key) => $value];
}
/**
* Friendly API for accessing HTTP headers.
*
* This converts header names to camelCase at
* access time, allowing them to be accessed with
* simple variable names. It can also be accessed like an
* array.
*
* For example:
*
* Content-Type == contentType
*/
return new DataArray($headers);
}
else
{
// If the above function doesn't exist,
// iterate $_SERVER and collect all HTTP_
// variables.
$headers = [];
foreach ($_SERVER as $key => $value)
{
if ("HTTP_" != substr($key, 0, 5)) continue;
// Not so hellish anymore now that I've stopped caring about
// the case.
$newKey = str_replace('_', '-', strtolower(substr($key, 5)));
$headers += [$newKey => $value];
}
return new DataArray($headers);
}
}
/**
* Get the POST body, attempt to decode it, and then
* return it.
*
* @param string $contentType
* @return mixed
*/
protected static function getPostBody($contentType)
{
// $_POST is only used by x-www-form-urlencoded
// and multipart/form content types. If this
// is available, return it.
if (!empty($_POST))
{
return $_POST;
}
// Otherwise, the input needs to be retrieved and
// decoded manually.
$body = @file_get_contents("php://input");
if (false == $body) return null; // Validate
// Switch on the content type and attempt to
// automatically parse contents.
switch ($contentType)
{
case "application/json":
$obj = @json_decode($body);
if (null != $obj) return $obj;
else return $body;
break;
}
// Otherwise return the raw input.
return $body;
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\ControllerV2;
/**
* A store for custom handlers that the user registers.
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class CallbackStore
{
public static $handleRedirect;
public static function setRedirectHandler($cb)
{
self::$handleRedirect = $cb;
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\ControllerV2;
use Rehike\ControllerV2\Util\GlobToRegexp;
use Rehike\SimpleFunnel;
include_once "includes/polyfill/fnmatch.php";
/**
* Implements the Controller V2 router.
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class Router
{
/**
* Configure router definitions for all GET requests.
*
* @param string[] $defs
* @return mixed
*/
public static function get($defs)
{
if ("GET" == $_SERVER['REQUEST_METHOD'])
return self::baseRequestMethod($defs, "get");
}
/**
* Configure router definitions for all POST requests.
*
* @param string[] $defs
* @return mixed
*/
public static function post($defs)
{
if ("POST" == $_SERVER['REQUEST_METHOD'])
return self::baseRequestMethod($defs, "post");
}
/**
* Configure router definitions for redirections.
*
* @param string[]|callback[] $defs
* @return void
*/
public static function redirect($defs)
{
// Iteration the definitions tree and check the contents.
foreach ($defs as $def => $redir)
{
// Convert the current definition to a regex for
// comparison
$regexp = GlobToRegexp::convert($def, $_SERVER["REQUEST_URI"], 0);
if (preg_match($regexp, $_SERVER["REQUEST_URI"]))
{
// If there's a match, check if it should callback a function
// use simple behaviour using a string.
/** @var string $endpoint */
$endpoint;
if (is_callable($redir))
{
$endpoint = $redir(new RequestMetadata());
// Prevent undefined behaviour
// Also allow for some programmer freedom I guess
if (!is_string($endpoint)) return;
}
else
{
// Otherwise perform the redirection using internal behaviour.
$endpoint = preg_replace($regexp, $redir, $_SERVER["REQUEST_URI"]);
}
// Callback the custom handler, or fallback to the
// default implementation.
if (is_callable(CallbackStore::$handleRedirect))
{
(CallbackStore::$handleRedirect)($endpoint);
}
else
{
header("Location: $endpoint");
die();
}
}
}
}
/**
* Configure router definitions for request funnelling.
*
* These essentially bypass Rehike.
*
* They request the same request URI on www.youtube.com and return
* the same response as given. This is useful for some things, such
* as static resources and API access.
*
* @param string[] $defs
* @return void
*/
public static function funnel($defs)
{
foreach ($defs as $index => $value)
{
// This behaviour will be expanded on later, if ever
// multiple domain support is added.
// Currently the simplefunnel script comes from a very
// outdated project and should probably be rewrote as it
// stands.
/** @var string $name */
$name;
if (is_int($index))
{
$name = $value;
}
else
{
$name = $value;
}
if (\fnmatch($name, explode("?", $_SERVER["REQUEST_URI"])[0]))
{
SimpleFunnel::funnelCurrentPage()->then(fn($r) => $r->output());
}
}
}
/**
* Iterate the router definitions and call the best match.
*
* The best match is determined through iterating through
* the whole array before calling the method.
*
* @param string[] $definitions
* @param string $method
* @return mixed
*/
protected static function baseRequestMethod($definitions, $method)
{
$bestMatch = null;
// Iterate the array and look for a match.
foreach ($definitions as $def => $_val)
if (\fnmatch($def, explode("?", $_SERVER["REQUEST_URI"])[0]))
{
$bestMatch = $def;
}
// If the best match exists (is callable), return it.
// The variable is called best match, but this does
// include only one match as well.
if (!is_null($bestMatch) && !is_null($definitions[$bestMatch]))
{
return self::pointerHandler($definitions[$bestMatch], $method);
}
// If the current URI does not exist, fall back to the
// default condition.
if (isset($definitions["default"]))
{
return self::pointerHandler($definitions["default"], $method);
}
}
/**
* Handle a definition's pointer.
*
* As of right now, only direct callbacks and strings
* pointing to a file path are supported.
*
* @param string|callable $pointer
* @param string $method that now finally gets used by the module!
* @return mixed
*/
protected static function pointerHandler($pointer, $method)
{
/** @var GetControllerInstance $import */
$import;
if (is_callable($pointer))
{
// Premature return since this is a unique case
return $pointer(Core::$state, Core::$template, new RequestMetadata());
}
else if (is_string($pointer))
{
foreach ([
"controllers/$pointer.php",
"controllers/$pointer",
"$pointer.php",
$pointer
] as $path) if (file_exists($path) && is_file($path))
{
$import = Core::import($path, false);
break;
}
}
else
{
$type = gettype($pointer);
throw new Exception\RouterInvalidPointerException(
"Controller pointer of type $type is not supported."
);
}
// Handle imports
return $import->{$method}();
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\ControllerV2;
/**
* Implements core behaviours of the Controller v2
* architecture.
*
* These behaviours include the storing the common state
* and template variables. It also provides an API for
* basic interaction with the system, i.e. importing.
*
* The variables passed to all CV2 controllers are, in this
* precise order:
* - &$state Reference to the global state variable.
* - &$template Reference to the global template variable.
* - $request Contains information about the current
* request.
* ...and then any custom defined arguments after that.
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
* @version 2.0
*/
class Core
{
/**
* A reference to global state variable.
*
* This variable gets passed to each controller, but
* modifications exceed it so that closing services
* may access its contents.
*
* @var object|array
*/
public static $state;
/**
* A reference to the global template file string.
*
* This is mostly useless even with Rehike's own
* implementation of Controller v2, but it was useful
* to keep as a reference during the development of the
* system.
*
* Template rendering should ideally be done by the
* controllers themselves.
*
* @var string
*/
public static $template;
/** Register a state reference. @see $state */
public static function registerStateVariable(&$state)
{
self::$state = &$state;
}
/** Register a template reference. @see $template */
public static function registerTemplateVariable(&$template)
{
self::$template = &$template;
}
/**
* Import a controller's file or pull it from the session
* cache.
*
* The contents are cached in order to allow reimports without
* causing additional errors, such as in the event of a
* function redeclaration.
*
* @return GetControllerInstance
*/
public static function import($controllerName, $appendPhp = true)
{
if (ControllerStore::hasController($controllerName))
{
// Import from cache
$controller = ControllerStore::getController($controllerName);
return new GetControllerInstance($controllerName, $controller);
}
else
{
// Import from file (or die)
$imports = require $controllerName . ($appendPhp ? ".php" : "");
ControllerStore::registerController($controllerName, $imports);
return new GetControllerInstance($controllerName, $imports);
}
}
/**
* @see CallbackStore::setRedirectHandler
*/
public static function setRedirectHandler($cb)
{
return CallbackStore::setRedirectHandler($cb);
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\ControllerV2\Util;
/**
* Convert a glob to a regexp. This is used by Controller v2.
*
* This implementation is somewhat nonstandard, but it works for the
* purpose Rehike uses it. Probably unsafe to use it elsewhere...
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class GlobToRegexp
{
public const PATHNAME = 1;
public const NOESCAPE = 2;
public const PERIOD = 4;
public const CASEFOLD = 16;
/**
* Convert a glob to a regex pattern.
*
* @param string $pattern
* @param string $filename
* @param int $flags
* @return string
*/
public static function convert($pattern, $filename, $flags = 0)
{
$regexFlags = "";
// Declare all possible transformations from
// glob syntax to regexp syntax
$transforms = [
"/\*\*" => "([\?|\/].*)?",
"\*" => ".*",
"\?" => ".",
"\[\!" => "[^",
"\[" => "[",
"\]" => "]",
"\(" => "(",
"\)" => ")",
"\|" => "|",
"\." => "\.",
"\\" => "\\\\"
];
// Handle flags behaviours
if ($flags & self::PATHNAME) $transforms["\*"] = "[^/]*";
if ($flags & self::NOESCAPE) unset($transforms["\\"]);
if ($flags & self::PERIOD && 0 === strpos($filename, ".") && 0 !== strpos($pattern, "."))
return false;
if ($flags & self::CASEFOLD) $regexFlags .= "i";
// Declare regexp pattern
$regexPattern = "#^"
. strtr( preg_quote($pattern, "#"), $transforms )
. "$#"
. $regexFlags
;
return $regexPattern;
}
/**
* Match a glob to a regex pattern.
*
* `match` is a reserved word as of PHP 8, so the method is called
* doMatch instead.
*
* @param string $pattern
* @param string $filename
* @param int $flags
* @return bool
*/
public static function doMatch($pattern, $filename, $flags = 0)
{
$regexPattern = GlobToRegexp::convert($pattern, $filename, $flags);
return (bool)preg_match($regexPattern, $filename);
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\ControllerV2\Exception;
use YukisCoffee\CoffeeException;
class MethodDoesNotExistException extends CoffeeException {} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\ControllerV2\Exception;
use YukisCoffee\CoffeeException;
class RouterInvalidPointerException extends CoffeeException {} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\Debugger;
/**
* Implements a general error wrapper class.
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Developers
*/
class ErrorWrapper
{
public $errno;
public $errstr;
public $errfile;
public $errline;
public function __construct($errno, $errstr, $errfile, $errline)
{
$this->errno = $errno;
$this->errstr = $errstr;
$this->errfile = $errfile;
$this->errline = $errline;
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\Debugger;
use \Rehike\RehikeConfigManager;
use \Rehike\TemplateManager;
use \Rehike\i18n;
use \YukisCoffee\CoffeeException;
use \Rehike\Model\Rehike\Debugger\{
MOpenButton as OpenButton,
MDialog as Dialog,
MErrorTab as ErrorTab,
MYtWalker as YtWalker,
MLoadingTab as LoadingTab,
MNetworkTab as NetworkTab
};
/**
* Implements the PHP end of Rehike Debugger/Rebug.
*
* A comment on nomenclature: We tend to call it the debugger in PHP land,
* whereas it's called Rebug on the HTML and JS side of things.
*
* HTML and JS lands are implemented in template/hitchhiker/rehike/debugger.
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Developers
*/
class Debugger
{
/**
* Stores the common context of this session's debugger.
*
* @var Context
*/
protected static $context;
/**
* Reference to the global context.
*
* @var object
*/
protected static $yt;
/**
* Stores the result of getting the debugger's condensed status.
*
* The debugger is condensed when it is disabled (it's not really ever
* REALLY disabled because it's used for beautiful error message delivery
* too).
*
* @var bool
*/
public static $condensed = true;
/**
* Stores a log of all errors (not exceptions) that have occurred since
* the debugger was registered.
*
* @var ErrorWrapper[]
*/
protected static $errors = [];
/**
* Get if the debugger is condensed.
*
* @return bool
*/
public static function isCondensed()
{
return self::$condensed;
}
/**
* Initialise the debugger.
*
* @param object $yt global state
* @return void
*/
public static function init(&$yt)
{
self::refreshInternalCondensedStatus();
// Variable walker data should only be
// exposed if the debugger is enabled
if (!self::$condensed) self::$yt = &$yt;
self::setupI18n();
self::$context = new Context();
error_reporting(E_ALL);
//ini_set("display_errors", "off");
TemplateManager::addGlobal("rehikeDebugger", self::$context);
// Disable the CoffeeException custom error screen
CoffeeException::disableBeautifulError();
set_error_handler("\\Rehike\\Debugger\\YcRehikeDebuggerErrorHandler");
}
/**
* Runs right before a standard page shutdown.
*
* @return void
*/
public static function shutdown()
{
if (!in_array($_GET["rebug_get_info"] ?? "false", ["false", "0"]))
{
self::handleGetInfo();
}
}
/**
* Handle a page requested with ?rebug_get_info=1
*/
public static function handleGetInfo()
{
$headers = headers_list();
// normalise
foreach ($headers as $index => $value)
{
list($key, $value) = explode(': ', $value);
unset($headers[$index]);
$headers[$key] = $value;
}
$originalContentType = $headers["Content-Type"] ?? "text/html";
header("X-Rebug-Get-Info: true");
header("Content-Type: application/json");
$pageContent = ob_get_clean();
$response = (object)[];
$response->content_type = $originalContentType;
$response->rebug_data = self::exposeSpf();
$response->response = $pageContent;
echo json_encode($response);
}
/**
* Get the internal context used by the debugger.
*
* @return object
*/
public static function getInternalContext()
{
return self::$context;
}
/**
* Setup the tabs available to the debugger session.
*
* @param Dialog|FullPage $context
* @return void
*/
public static function setupTabs($context)
{
$i18n = &i18n::getNamespace("rebug");
$errorTab = $context->addTab(
ErrorTab::createTab(
$i18n->tabErrorTitle(number_format(self::getErrorCount())),
"error",
true
)
);
$errorTab->pushErrors(self::$errors);
if (!self::$condensed)
{
/*
$context->addTab(
NetworkTab::createTab(
$i18n->tabNetworkTitle,
"network"
)
);
*/
$ytWalker = $context->addTab(
YtWalker::createTab(
$i18n->tabYtWalkerTitle, "global_walker"
)
);
$ytWalker->addYt(self::$yt);
}
}
/**
* Expose the debugger to the templater.
*
* @return void
*/
public static function expose()
{
$i18n = &i18n::getNamespace("rebug");
$context = &self::$context;
$context->condensed = self::$condensed;
$context->openButton = new OpenButton(self::getErrorCount(), self::$condensed);
$context->dialog = new Dialog(self::$condensed);
self::setupTabs($context->dialog);
}
/**
* Expose the debugger to an SPF response.
*
* @return object
*/
public static function exposeSpf()
{
self::expose();
$context = self::$context;
$response = (object)[];
$response->updatedTabs = [];
foreach ($context->getTabs() as $tab) if ($tab->content->enableJsHistory)
{
$html = TemplateManager::render(
["tab" => $tab], "rehike/debugger/spf/tab_content"
);
$response->updatedTabs += [
$tab->id => [
"title" => $tab->title,
"html" => $html
]
];
}
$response->openButton = TemplateManager::render(
[], "rehike/debugger/open_button"
);
if (!self::$condensed)
{
$response->globalWalker = (object)[];
$response->globalWalker->data = (object)[];
$response->globalWalker->data->yt = self::$yt;
$response->globalWalker->attr = $context->jsAttrs;
}
return $response;
}
/**
* Get the current error count.
*
* @return int
*/
public static function getErrorCount()
{
return count(self::$errors);
}
/**
* Push an error to the debugger.
*
* @param ErrorWrapper $err
* @return void
*/
public static function pushError($err)
{
self::$errors[] = $err;
}
/**
* Add data to the context.
*
* @param string $name
* @param mixed $value
* @return void
*/
public static function addContext($name, $value)
{
self::$context->{$name} = $value;
}
/**
* Initialise i18n
*
* @return void
*/
protected static function setupI18n()
{
$i18n = &i18n::newNamespace("rebug");
$i18n->registerFromFile("en", "i18n/rehike/debugger/en.json");
}
/**
* Refresh the condensed status.
*
* @return void
*/
protected static function refreshInternalCondensedStatus()
{
self::$condensed = RehikeConfigManager::getConfigProp("advanced.enableDebugger")
? false
: true
;
}
}
/**
* Handles all errors and logs them in the debugger.
*
* @return void
*/
function YcRehikeDebuggerErrorHandler($errno, $errstr, $errfile, $errline)
{
// Surpress @ operator
$errorReporting = error_reporting();
if (
E_ALL != $errorReporting
)
{
return false;
}
switch ($errno)
{
case E_USER_ERROR:
case E_ERROR:
// Call the general fatal handler
\fatalHandler();
break;
default:
Debugger::pushError(
new ErrorWrapper($errno, $errstr, $errfile, $errline)
);
break;
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\Debugger;
use \Rehike\Model\Rehike\Debugger\{
MOpenButton,
MDialog,
MTab,
MErrorTab,
MYtWalker,
MLoadingTab
};
/**
* Implements the Rehike debugger context.
*
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class Context
{
/**
* Properties used to build the dialog view.
*
* @var MDialog
*/
public $dialog = null;
/**
* Properties used to build the open button's view.
*
* @var MOpenButton
*/
public $openButton = null;
/**
* Reports if the debugger is in condensed mode (disabled generally).
*
* @var bool
*/
public $condensed = false;
/**
* Get all tabs in the dialog.
*
* @return MTab[]
*/
public function getTabs()
{
return $this->dialog->tabs;
}
/**
* Get all tab IDs available in the debugger.
*
* @return string[]
*/
public function getTabIds()
{
$out = [];
foreach ($this->getTabs() as $tab)
{
$out[] = $tab->id;
}
return $out;
}
/**
* Get the tab IDs to be affected by the history manager in the JS land.
*
* @return string[]
*/
public function getJsHistoryTabIds()
{
$out = [];
foreach ($this->getTabs() as $tab) if ($tab->content->enableJsHistory)
{
$out[] = $tab->id;
}
return $out;
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\SignInV2;
/**
* Implements the main sign-in API.
*
* @author Daylin Cooper <[email protected]>
* @author The Rehike Maintainers
*/
class SignIn
{
public static function isSignedIn(): bool
{
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\SignInV2;
use Rehike\SignInV2\{
Builder\SessionInfoBuilder,
Enum\SessionErrors,
Exception\FailedSwitcherRequestException,
Info\SessionInfo,
Parser\SwitcherParser
};
use Rehike\Network;
use Rehike\Async\Promise;
use function Rehike\Async\async;
/**
* Manages Google Account (GAIA) authentication and initialization.
*
* @author Daylin Cooper <[email protected]>
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class GaiaAuthManager
{
/**
* Stores the user's "SAPISID" session cookie, which plays a crucial role
* in authentication.
*
* If the cookie is unavailable, then this will be unset.
*/
private static string $sapisid;
private static string $loginInfoCookie;
public static function __initStatic(): void
{
if (isset($_COOKIE) && isset($_COOKIE["SAPISID"]) && isset($_COOKIE["LOGIN_INFO"]))
{
self::$sapisid = $_COOKIE["SAPISID"];
self::$loginInfoCookie = $_COOKIE["LOGIN_INFO"];
}
}
/**
* Checks if GAIA authentication should be attempted.
*
* If this function returns false, all GAIA-related behavior should be
* ignored.
*/
public static function shouldAttemptAuth(): bool
{
return isset(self::$sapisid);
}
/**
* Generates a new SAPISIDHASH for the current timestamp, which is used in
* the HTTP Authorization header.
*/
public static function generateSapisidHash(string $origin = "https://www.youtube.com"): string
{
$sapisid = self::$sapisid;
$time = time();
$sha1 = sha1("{$time} {$sapisid} {$origin}");
return "SAPISIDHASH {$time}_{$sha1}";
}
/**
* Newly requests session data from YouTube's servers.
*
* For performance reasons, the result will be cached and reused for some
* time after the initial request.
*
* @return Promise<SessionInfo>
*/
public static function getFreshInfoFromRemote(): Promise/*<SessionInfo>*/
{
return async(function() {
$infoBuilder = new SessionInfoBuilder();
try
{
$accSwitcher = yield self::requestAccountSwitcherData();
$switcherParser = new SwitcherParser($accSwitcher);
$switcherParser->outputToBuilder($infoBuilder);
return $infoBuilder->build();
}
catch (FailedSwitcherRequestException $e)
{
$infoBuilder->pushSessionError(SessionErrors::FAILED_REQUEST);
return $infoBuilder->build();
}
});
}
/**
* Requests account switcher data from the server for parsing.'
*
* As this is not a standard InnerTube endpoint, it features a JSON buster
* that must be removed or it will break the JSON parser.
*
* @return Promise<object>
*/
private static function requestAccountSwitcherData(): Promise/*<object>*/
{
return async(function() {
$response = yield Network::urlRequestFirstParty(
"https://www.youtube.com/getAccountSwitcherEndpoint",
Network::getDefaultYoutubeOpts()
);
$object = json_decode(
substr($response->getText(), 4)
);
if ($response->status != 200 || !is_object($object))
{
throw new FailedSwitcherRequestException(
"Failed to request account switcher data."
);
}
return $object;
});
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
# Rehike Sign-In v2 Documentation
This documents changes made in this rewrite of the sign-in API Rehike uses and the motivations for rewriting it.
The original sign-in API was created early on in Rehike's life by Taniko. At the time, the team didn't focus on code quality as much as we do now, and the original implementation made some very weird choices. With Rehike v0.7 "Asynchike", these became very abundant and the sign-in system was lazily patched to adopt the new networking system.
## Problems with the original API
UX issues and prevalent bugs:
- The original API never implemented proper support for multiuser use. This is visible with Google Accounts that have multiple YouTube channels (Brand Accounts), but it is especially noticeable for users who use multiple Google Accounts at one time.
- On the code side of things, we never bothered implementing support for the `X-Goog-Auth-User` header.
- The sign-in cache doesn't have proper error handling, and corruption of this file or a bug in Rehike can make Rehike fail to load for non-obvious reasons. The whole implementation of the sign-in cache was just kinda lazy.
- Also as an example of the above problem, the changing of a user's profile picture will not work correctly if Rehike is installed.
- Similarly, logging out of a session would not allow Rehike to load again until the session cookies were removed from the user's browser.
- Rehike does not account for Google Accounts which have no YouTube channels at all.
Code-exclusive problems:
- The code overall was very messy, and it only got worse with Asynchike. Type safety was not employed, and neither was proper exception handling.
- Almost all code was centralised in the original AuthManager class, save for parsing- and caching-related functionality.
## Focuses of the rewrite
The rewrite aims to:
- Fully support multiple Google accounts and YouTube channels.
- Elegantly manage caching and easily adapt to changes while remaining consistent.
- Have a clean, manageable, and asynchronous-by-design codebase design.
## Additional concerns
This update should be released as part of the "Asynchike" update to Rehike (version 0.7). Maintainers can still modify the legacy sign in system if they want to, especially while the main version continues to be 0.5, but I don't think that's going to happen.
## Additional plans
There are some aspects of this update that should influence further updates to improve overall code clarity.
As of this rewrite, Rehike does not have a shared caching system, and each module that uses caching needs its own implementation. We should move towards a single system in the future in order to better guarantee stability and consistency across all caching in Rehike.
The configuration system is similarly in need of a major reworking. This update introduces an experiments tab, which can be used to easily toggle between the old and new sign-in systems, but this has some limitation. As Rehike only works in English at the moment, the fact that configuration entries are only listed at all if they are localised is not too much of an issue, but it will become one in the future. The best implementation I see for Rehike configuration is a one source code file modification, plus additional modification for localising the settings, but otherwise it can fallback on English rather than not displaying the option at all.
## Code design
This section of the document will explain the design of the code of this update. Unlike the original design, which only had four files and was in desperate need of a cleanup, this update focuses on separating responsibilities and having classes that only encapsulate the functionality that they require. This creates a more manageable design that can easily be altered or improved.
The main, public API is implemented in the `SignIn` class. This class is to be used in order to evaluate, in PHP code, whether or not the used is signed in or to get additional information about the user session. This class is comparable to the former `Signin\API` class of the old system, which was created as a bit of a bandage in order to improve code clarity.
There are now additional sets of classes which divide responsibility more evenly. These are:
- **Info** classes, which are immutable classes used to retrieve information from the user's logged in session, such as their name and profile picture. These are publicly accessible and may be returned by the main `SignIn` API.
- **Builder** classes, which are used in order to create an Info class. They are only used internally, but mutable.
- **Parser** classes, which are used to scrape information from a third-party source, such as a YouTube API. These work in tandem with Builder classes in order to create the final Info class.
- **Manager** classes, of which there are presently only one, are used to implement an authentication service and coordinate the efforts to get information. It is likely that only the GAIA authentication manager (`GaiaAuthManager`) will be needed, unless Google or YouTube radically change their authentication systems within Rehike's lifetime.
New features are able to be easily added, due to the vastly improved code quality, including a proper error handling mechanism. The `SessionErrors` enum defines a bitmask which can be used to identify problems with signing in and handle them from anywhere within Rehike.
Although the new API hardly resembles the old one at all, there is some need for backwards compatibility with the `yt.signin` structure, which templates used heavily. During the writing of this update, many templates referenced `yt.signin.isLoggedIn` to verify if the user was logged in. This is currently still used by V2, but it may be abandoned in the future if the developers wish to further improve the clarity of responsibilities in templates (i.e. it would move to `rehike.signin`, being representative of Rehike state rather than a direct feature of the YouTube page) or support conditions such as the user being logged into an account without a channel. | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\SignInV2\Builder;
use Rehike\SignInV2\Info\YtChannelAccountInfo;
use Rehike\SignInV2\Info\GoogleAccountInfo;
/**
* Builder for the YtChannelAccountInfo class.
*
* @author Daylin Cooper <[email protected]>
* @author The Rehike Maintainers
*/
class YtChannelAccountInfoBuilder
{
private GoogleAccountInfo $ownerAccount;
private string $ucid;
public function build(): YtChannelAccountInfo
{
return new YtChannelAccountInfo();
}
public function getOwnerAccount(): GoogleAccountInfo
{
return $this->ownerAccount;
}
public function setOwnerAccount(GoogleAccountInfo $instance): void
{
$this->ownerAccount = $instance;
}
public function getUcid(): string
{
return $this->ucid;
}
public function setUcid(string $newValue): void
{
$this->ucid = $newValue;
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\SignInV2\Builder;
use Rehike\SignInV2\Info\SessionInfo;
/**
* Builds a session info object using data that is collected elsewhere.
*
* The builder is not a public interface, so it can be considered less volatile
* than the final class. Temporary state can be stored here.
*
* @author Daylin Cooper <[email protected]>
* @author The Rehike Maintainers
*/
class SessionInfoBuilder
{
private string $displayName;
private string $emailAddress;
private int $sessionErrors;
public function build(): SessionInfo
{
return new SessionInfo(
isSignedIn: false
);
}
public function pushSessionError(int $error): void
{
$this->sessionErrors |= $error;
}
public function getDisplayName(): ?string
{
return $this->displayName ?? null;
}
public function setDisplayName(string $newName): void
{
$this->displayName = $newName;
}
public function getEmailAddress(): ?string
{
return $this->emailAddress ?? null;
}
public function setEmailAddress(string $newEmail): void
{
$this->emailAddress = $newEmail;
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\SignInV2\Enum;
/**
* Defines enumerations for types of session errors. These are used as a
* bitmask.
*
* @author Daylin Cooper <[email protected]>
* @author The Rehike Maintainers
*/
class SessionErrors
{
public const FAILED_REQUEST = 0x01;
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\SignInV2\Info;
/**
* Used to store and retrieve information about a YouTube channel.
*
* Since YouTube channels are internally based on the otherwise deprecated
* Brand Account system, they share many similarities with full-on
* Google Accounts and are implemented as a subclass as a result.
*
* @author Daylin Cooper <[email protected]>
* @author The Rehike Maintainers
*/
class YtChannelAccountInfo extends GoogleAccountInfo
{
/**
* The Google Account which owns the channel's Brand Account, or which
* is used to access it.
*/
protected GoogleAccountInfo $ownerAccount;
/**
* The unique identifier used to identify the user channel by YouTube.
*/
protected string $ucid;
public function __construct(
GoogleAccountInfo $ownerAccount,
string $displayName,
string $gaiaId,
string $ucid,
string $avatarUrl
)
{
$this->ownerAccount = $ownerAccount;
$this->gaiaId = $gaiaId;
$this->ucid = $ucid;
$this->avatarUrl = $avatarUrl;
}
/**
* Get the email address of the account which is used to access this
* channel.
*/
public function getAccountEmail(): string
{
return $this->ownerAccount->getAccountEmail();
}
/**
* Get the Google Account which owns the channel's Brand Account, or which
* is used to access it.
*/
public function getOwnerAccount(): GoogleAccountInfo
{
return $this->ownerAccount;
}
/**
* Get the unique identifier used to identify the user channel by YouTube.
*/
public function getUcid(): string
{
return $this->ucid;
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\SignInV2\Info;
/**
* Used to store and retrieve information about a Google Account.
*
* @author Daylin Cooper <[email protected]>
* @author The Rehike Maintainers
*/
class GoogleAccountInfo
{
/**
* The public display name of the account, used to identify the account
* to the user.
*
* This can be unavailable, such as in the case of multiple Google
* Accounts logged into at the same time, because YouTube only reports
* the display name for the active account.
*/
protected ?string $displayName = null;
/**
* The internal GAIA ID of the account, used to identify the account
* within Google's services.
*/
protected string $gaiaId;
/**
* The email address associated with this Google Account.
*/
private string $accountEmail;
/**
* A URL linking to the account's profile picture.
*/
protected string $avatarUrl;
public function __construct(
?string $displayName = null,
string $gaiaId,
string $accountEmail,
string $avatarUrl
)
{
$this->displayName = $displayName;
$this->gaiaId = $gaiaId;
$this->accountEmail = $accountEmail;
$this->avatarUrl = $avatarUrl;
}
/**
* Get the public display name of the account, used to identify the account
* to the user.
*/
public function getDisplayName(): ?string
{
return $this->displayName;
}
/**
* Get the internal GAIA ID of the account, used to identify the account
* within Google's services.
*/
public function getGaiaId(): string
{
return $this->gaiaId;
}
/**
* Get the email address associated with this Google Account.
*/
public function getAccountEmail(): string
{
return $this->accountEmail;
}
/**
* Get a URL linking to the account's profile picture.
*/
public function getAvatarUrl(): string
{
return $this->avatarUrl;
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\SignInV2\Info;
/**
* Provides information about the current user session. This is the top-most
* class for accessing data about the user session in the PHP world.
*
* @author Daylin Cooper <[email protected]>
* @author The Rehike Maintainers
*/
class SessionInfo
{
/**
* States whether or not the user is signed into a valid session.
*/
protected bool $isSignedIn = false;
/**
* Stores information about the currently signed in Google Account.
*
* TODO(ev): SessionInfo doesn't account for multiple Google Accounts at
* all, which is a major issue. This MUST be added at some point!!!!
*/
protected GoogleAccountInfo $googleAccount;
/**
* Stores information about the currently used YouTube channel.
*/
protected YtChannelAccountInfo $activeChannel;
/**
* Stores a list of other YouTube channels accessible under the current
* Google Account.
*
* @var YtChannelAccountInfo[]
*/
protected array $otherAccounts;
/**
* A bitmask that stores information about various errors that may have
* occurred in signing in.
*
* This will be 0 if there are no errors.
*/
protected int $sessionErrors = 0;
public function __construct(
bool $isSignedIn,
GoogleAccountInfo $googleAccount = null,
YtChannelAccountInfo $activeChannel = null,
array $otherAccounts = [],
array $sessionErrors = []
)
{
$this->isSignedIn = $isSignedIn && $googleAccount != null;
if ($googleAccount != null)
$this->googleAccount = $googleAccount;
if ($activeChannel != null)
$this->activeChannel = $activeChannel;
$this->otherAccounts = $otherAccounts;
$this->sessionErrors = $sessionErrors;
}
/**
* Gets whether or not the user is signed into a valid session.
*/
public function getIsSignedIn(): bool
{
return $this->isSignedIn;
}
/**
* Gets information about the currently signed in Google Account.
*/
public function getGoogleAccount(): GoogleAccountInfo
{
return $this->googleAccount;
}
/**
* Gets information about the currently used YouTube channel.
*/
public function getActiveChannel(): YtChannelAccountInfo
{
return $this->activeChannel;
}
/**
* Gets a list of other YouTube channels accessible under the current
* Google Account.
*/
public function getOtherAccounts(): array
{
return $this->otherAccounts;
}
/**
* Gets a bitmask that stores information about various errors that may
* have occurred in signing in.
*
* The result will be 0 if there are no errors.
*/
public function getSessionErrors(): int
{
return $this->sessionErrors;
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
<?php
namespace Rehike\SignInV2\Parser;
use Rehike\SignInV2\{
Builder\SessionInfoBuilder,
Parser\Exception\UnfinishedParsingException
};
/**
* Parses and retrieves information from the account switcher, requested at
* /getAccountSwitcherEndpoint.
*
* This class stores temporary, transitional copies of the data while it forms
* the standardized class.
*
* @author Daylin Cooper <[email protected]>
* @author Taniko Yamamoto <[email protected]>
* @author The Rehike Maintainers
*/
class SwitcherParser
{
/**
* The account switcher response, JSON decoded.
*/
private object $response;
/**
* Used in order to determine if the parser has ran yet.
*/
private bool $hasParsed = false;
/**
* Stores the number of Google Accounts accessible by the user.
*/
private int $numberOfGoogleAccounts = 0;
/**
* Stores temporary state about the current Google Account, which is fed
* to the builder.
*/
private array $googleAccountInfo = [
"email" => null,
"name" => null
];
/**
* Stores temporary state about the currently used YouTube channel.
*
* This schema is also used for all children of the $channels array.
*/
private array $currentChannelInfo = [
"name" => null,
"photo" => null,
"byline" => null,
"selected" => null,
"hasChannel" => null,
"gaiaId" => null,
"switchUrl" => null
];
/**
* Stores temporary state for all other channels that can be accessed by
* a Google Account.
*
* Children of this array should follow the same schema as
* $currentChannelInfo.
*/
private array $channels = [];
public function __construct(object $response)
{
$this->response = $response;
}
/**
* Parse the given account switcher response and modify this class's
* data accordingly.
*/
public function parse(): self
{
$this->retrieveGoogleAccountInfo();
$this->retrieveChannels();
$this->hasParsed = true;
return $this;
}
/**
* Forward all current data in this class to the info builder.
*/
public function outputToBuilder(SessionInfoBuilder $builder): void
{
if ($this->hasParsed)
{
$builder->setDisplayName($this->googleAccountInfo["name"]);
$builder->setEmailAddress($this->googleAccountInfo["email"]);
}
else
{
throw new UnfinishedParsingException(
"Cannot output unparsed SwitcherParser data to builder. " .
"Run the parser and try again."
);
}
}
// ========================================================================
/**
* Get the main renderer, which is the root of most other information
* sources.
*
* This is an array that will an array containing various information
* about each of the Google Accounts.
*/
protected function getMainRenderer(): array
{
return $this->response->data->actions[0]->getMultiPageMenuAction
->menu->multiPageMenuRenderer->sections;//[0]
//->accountSectionListRenderer;
}
/**
* Parse the available Google Accounts in the respopnse and set class
* properties accordingly.
*/
protected function retrieveAccounts(): void
{
}
/**
* Get the account header renderer, which contains certain information
* about the currently used Google Account.
*/
protected function getAccountHeaderRenderer(): object
{
return $this->getMainRenderer()->header->googleAccountHeaderRenderer;
}
/**
* Get the root rendererer of all available YouTube channels on a given
* account.
*/
protected function getChannelItemsRenderer(): object
{
return $this->getMainRenderer()->contents;
}
/**
* Parse the Google Account information available in the response and
* set class properties accordingly.
*/
protected function retrieveGoogleAccountInfo(): void
{
$headerInfo = $this->getAccountHeaderRenderer();
$this->googleAccountInfo["email"] = $headerInfo->email->simpleText;
$this->googleAccountInfo["name"] = $headerInfo->name->simpleText;
}
/**
* Parse all of the channels listed in the response and set class
* properties accordingly.
*/
protected function retrieveChannels(): void
{
$items = $this->getChannelItemsRenderer();
foreach ($items as $item)
{
if (isset($item->accountItem))
{
$channelInfo = $this->getChannelInfo($item->accountItem);
if ($channelInfo["selected"])
{
$this->currentChannelInfo = $channelInfo;
}
$this->channels[] = $channelInfo;
}
}
}
/**
* Get the information of a single channel.
*
* @see getChannels() Source of the iteration of $channel.
*/
protected function getChannelInfo(object $channel): array
{
if (isset(
$channel->serviceEndpoint->selectActiveIdentityEndpoint
->supportedTokens
))
{
$supportedTokens = $channel->serviceEndpoint
->selectActiveIdentityEndpoint->supportedTokens;
foreach ($supportedTokens as $token)
{
if (isset($token->pageIdToken))
{
$gaiaId = $token->pageIdToken->pageId;
}
if (isset($token->accountSigninToken))
{
$switchUrl = $token->accountSigninToken->signinUrl;
}
}
}
$nameText = $channel->accountName->simpleText;
$photoUrl = $channel->accountPhoto->thumbnails[0]->url;
$bylineText = $channel->accountByline->simpleText;
$selectedState = $channel->isSelected;
$hasChannel = $channel->hasChannel;
return [
"name" => $nameText,
"photo" => $photoUrl,
"byline" => $bylineText,
"selected" => $selectedState,
"hasChannel" => $hasChannel,
"gaiaId" => $gaiaId ?? null,
"switchUrl" => $switchUrl ?? null
];
}
} | {
"repo_name": "Rehike/Rehike",
"stars": "81",
"repo_language": "PHP",
"file_name": "config.php",
"mime_type": "text/x-php"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.