_id stringlengths 2 7 | title stringlengths 3 151 | partition stringclasses 3
values | text stringlengths 83 13k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q15700 | JobConfigurationTrait.jobConfigurationProperties | train | public function jobConfigurationProperties(
$projectId,
array $config,
$location
) {
$this->config = array_replace_recursive([
'projectId' => $projectId,
'jobReference' => ['projectId' => $projectId]
], $config);
if ($location && !isset($this->config['jobReference']['location'])) {
$this->config['jobReference']['location'] = $location;
}
if (!isset($this->config['jobReference']['jobId'])) {
$this->config['jobReference']['jobId'] = $this->generateJobId();
}
} | php | {
"resource": ""
} |
q15701 | JobConfigurationTrait.toArray | train | public function toArray()
{
if ($this->jobIdPrefix) {
$this->config['jobReference']['jobId'] = sprintf(
'%s-%s',
$this->jobIdPrefix,
$this->config['jobReference']['jobId']
);
}
return $this->config;
} | php | {
"resource": ""
} |
q15702 | TransactionalReadTrait.singleUseState | train | private function singleUseState()
{
if ($this->type === self::TYPE_SINGLE_USE) {
if ($this->state === self::STATE_SINGLE_USE_USED) {
throw new \BadMethodCallException('This single-use transaction has already been used.');
}
$this->state = self::STATE_SINGLE_USE_USED;
return true;
}
return false;
} | php | {
"resource": ""
} |
q15703 | TransactionalReadTrait.checkReadContext | train | private function checkReadContext()
{
if ($this->type === self::TYPE_SINGLE_USE && $this->context === SessionPoolInterface::CONTEXT_READWRITE) {
throw new \BadMethodCallException('Cannot use a single-use read-write transaction for read or execute.');
}
} | php | {
"resource": ""
} |
q15704 | CloudWorkspaceSourceContext.setWorkspaceId | train | public function setWorkspaceId($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\DevTools\Source\V1\CloudWorkspaceId::class);
$this->workspace_id = $var;
return $this;
} | php | {
"resource": ""
} |
q15705 | SessionEntityType.setEntityOverrideMode | train | public function setEntityOverrideMode($var)
{
GPBUtil::checkEnum($var, \Google\Cloud\Dialogflow\V2\SessionEntityType_EntityOverrideMode::class);
$this->entity_override_mode = $var;
return $this;
} | php | {
"resource": ""
} |
q15706 | Image.requestObject | train | public function requestObject($encode = true)
{
return array_filter([
'image' => $this->imageObject($encode),
'features' => $this->features,
'imageContext' => $this->options['imageContext']
]);
} | php | {
"resource": ""
} |
q15707 | Image.imageObject | train | private function imageObject($encode)
{
if ($this->type === self::TYPE_BYTES) {
$bytes = (string) $this->image;
return [
'content' => ($encode) ? base64_encode($bytes) : $bytes
];
}
if ($this->type === self::TYPE_STRING) {
$string = $this->image;
return [
'content' => ($encode) ? base64_encode($string) : $string
];
}
return [
'source' => [
'imageUri' => $this->image
]
];
} | php | {
"resource": ""
} |
q15708 | Image.normalizeFeatures | train | private function normalizeFeatures(array $features)
{
$result = [];
foreach ($features as $key => $feature) {
$maxResults = $this->maxResult($feature);
if (array_key_exists($feature, $this->featureShortNames)) {
$feature = $this->featureShortNames[$feature];
}
$result[] = array_filter([
'type' => $feature,
'maxResults' => $maxResults
]);
}
return $result;
} | php | {
"resource": ""
} |
q15709 | Image.maxResult | train | private function maxResult($feature)
{
return (isset($this->options['maxResults'][$feature]))
? $this->options['maxResults'][$feature]
: null;
} | php | {
"resource": ""
} |
q15710 | ProductSearchParams.setProductCategories | train | public function setProductCategories($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING);
$this->product_categories = $arr;
return $this;
} | php | {
"resource": ""
} |
q15711 | InstanceConfiguration.reload | train | public function reload(array $options = [])
{
$this->info = $this->connection->getInstanceConfig($options + [
'name' => $this->name,
'projectId' => $this->projectId
]);
return $this->info;
} | php | {
"resource": ""
} |
q15712 | InstanceConfiguration.fullyQualifiedConfigName | train | private function fullyQualifiedConfigName($name, $projectId)
{
try {
return InstanceAdminClient::instanceConfigName(
$projectId,
$name
);
} catch (ValidationException $e) {
return $name;
}
} | php | {
"resource": ""
} |
q15713 | AsyncBatchAnnotateFilesRequest.setRequests | train | public function setRequests($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Vision\V1\AsyncAnnotateFileRequest::class);
$this->requests = $arr;
return $this;
} | php | {
"resource": ""
} |
q15714 | ListNotificationChannelDescriptorsResponse.setChannelDescriptors | train | public function setChannelDescriptors($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Monitoring\V3\NotificationChannelDescriptor::class);
$this->channel_descriptors = $arr;
return $this;
} | php | {
"resource": ""
} |
q15715 | Topic.reload | train | public function reload(array $options = [])
{
return $this->info = $this->connection->getTopic($options + [
'topic' => $this->name
]);
} | php | {
"resource": ""
} |
q15716 | Topic.publishBatch | train | public function publishBatch(array $messages, array $options = [])
{
foreach ($messages as &$message) {
$message = $this->formatMessage($message);
}
return $this->connection->publishMessage($options + [
'topic' => $this->name,
'messages' => $messages
]);
} | php | {
"resource": ""
} |
q15717 | Topic.subscribe | train | public function subscribe($name, array $options = [])
{
$subscription = $this->subscriptionFactory($name);
$subscription->create($options);
return $subscription;
} | php | {
"resource": ""
} |
q15718 | Topic.subscriptions | train | public function subscriptions(array $options = [])
{
$resultLimit = $this->pluck('resultLimit', $options, false);
return new ItemIterator(
new PageIterator(
function ($subscription) {
return $this->subscriptionFactory($subscription);
},
[$this->connection, 'listSubscriptionsByTopic'],
$options + ['topic' => $this->name],
[
'itemsKey' => 'subscriptions',
'resultLimit' => $resultLimit
]
)
);
} | php | {
"resource": ""
} |
q15719 | Topic.iam | train | public function iam()
{
if (!$this->iam) {
$iamConnection = new IamTopic($this->connection);
$this->iam = new Iam($iamConnection, $this->name);
}
return $this->iam;
} | php | {
"resource": ""
} |
q15720 | Topic.formatMessage | train | private function formatMessage(array $message)
{
if (isset($message['data']) && $this->encode) {
$message['data'] = base64_encode($message['data']);
}
if (!array_key_exists('data', $message) &&
!array_key_exists('attributes', $message)) {
throw new InvalidArgumentException('At least one of $data or
$attributes must be specified on each message, but neither
was given.');
}
return $message;
} | php | {
"resource": ""
} |
q15721 | Topic.subscriptionFactory | train | private function subscriptionFactory($name, array $info = [])
{
return new Subscription(
$this->connection,
$this->projectId,
$name,
$this->name,
$this->encode,
$info
);
} | php | {
"resource": ""
} |
q15722 | Expressions.setLogicalOperator | train | public function setLogicalOperator($var)
{
GPBUtil::checkEnum($var, \Google\Cloud\Dlp\V2\RecordCondition_Expressions_LogicalOperator::class);
$this->logical_operator = $var;
return $this;
} | php | {
"resource": ""
} |
q15723 | CreateSessionRequest.setSession | train | public function setSession($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\Spanner\V1\Session::class);
$this->session = $var;
return $this;
} | php | {
"resource": ""
} |
q15724 | BatchGetAssetsHistoryRequest.setReadTimeWindow | train | public function setReadTimeWindow($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\Asset\V1beta1\TimeWindow::class);
$this->read_time_window = $var;
return $this;
} | php | {
"resource": ""
} |
q15725 | VideoContext.setShotChangeDetectionConfig | train | public function setShotChangeDetectionConfig($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\VideoIntelligence\V1\ShotChangeDetectionConfig::class);
$this->shot_change_detection_config = $var;
return $this;
} | php | {
"resource": ""
} |
q15726 | VideoContext.setExplicitContentDetectionConfig | train | public function setExplicitContentDetectionConfig($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\VideoIntelligence\V1\ExplicitContentDetectionConfig::class);
$this->explicit_content_detection_config = $var;
return $this;
} | php | {
"resource": ""
} |
q15727 | VideoContext.setSpeechTranscriptionConfig | train | public function setSpeechTranscriptionConfig($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\VideoIntelligence\V1\SpeechTranscriptionConfig::class);
$this->speech_transcription_config = $var;
return $this;
} | php | {
"resource": ""
} |
q15728 | VideoContext.setTextDetectionConfig | train | public function setTextDetectionConfig($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\VideoIntelligence\V1\TextDetectionConfig::class);
$this->text_detection_config = $var;
return $this;
} | php | {
"resource": ""
} |
q15729 | DlpJob.setState | train | public function setState($var)
{
GPBUtil::checkEnum($var, \Google\Cloud\Dlp\V2\DlpJob_JobState::class);
$this->state = $var;
return $this;
} | php | {
"resource": ""
} |
q15730 | DlpJob.setRiskDetails | train | public function setRiskDetails($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\Dlp\V2\AnalyzeDataSourceRiskDetails::class);
$this->writeOneof(4, $var);
return $this;
} | php | {
"resource": ""
} |
q15731 | DlpJob.setInspectDetails | train | public function setInspectDetails($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\Dlp\V2\InspectDataSourceDetails::class);
$this->writeOneof(5, $var);
return $this;
} | php | {
"resource": ""
} |
q15732 | Page.setBlocks | train | public function setBlocks($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Vision\V1\Block::class);
$this->blocks = $arr;
return $this;
} | php | {
"resource": ""
} |
q15733 | TrainingPhrase.setType | train | public function setType($var)
{
GPBUtil::checkEnum($var, \Google\Cloud\Dialogflow\V2\Intent_TrainingPhrase_Type::class);
$this->type = $var;
return $this;
} | php | {
"resource": ""
} |
q15734 | SetLabelsRequest.setResourceLabels | train | public function setResourceLabels($var)
{
$arr = GPBUtil::checkMapField($var, \Google\Protobuf\Internal\GPBType::STRING, \Google\Protobuf\Internal\GPBType::STRING);
$this->resource_labels = $arr;
return $this;
} | php | {
"resource": ""
} |
q15735 | SearchAgentsResponse.setAgents | train | public function setAgents($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Dialogflow\V2\Agent::class);
$this->agents = $arr;
return $this;
} | php | {
"resource": ""
} |
q15736 | BatchGetDocumentsRequest.setNewTransaction | train | public function setNewTransaction($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\Firestore\V1beta1\TransactionOptions::class);
$this->writeOneof(5, $var);
return $this;
} | php | {
"resource": ""
} |
q15737 | Skill.setLevel | train | public function setLevel($var)
{
GPBUtil::checkEnum($var, \Google\Cloud\Talent\V4beta1\SkillProficiencyLevel::class);
$this->level = $var;
return $this;
} | php | {
"resource": ""
} |
q15738 | ErrorGroupStats.setGroup | train | public function setGroup($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\ErrorReporting\V1beta1\ErrorGroup::class);
$this->group = $var;
return $this;
} | php | {
"resource": ""
} |
q15739 | ErrorGroupStats.setAffectedServices | train | public function setAffectedServices($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\ErrorReporting\V1beta1\ServiceContext::class);
$this->affected_services = $arr;
return $this;
} | php | {
"resource": ""
} |
q15740 | ErrorGroupStats.setRepresentative | train | public function setRepresentative($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\ErrorReporting\V1beta1\ErrorEvent::class);
$this->representative = $var;
return $this;
} | php | {
"resource": ""
} |
q15741 | QuoteInfo.setDateTime | train | public function setDateTime($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\Dlp\V2\DateTime::class);
$this->writeOneof(2, $var);
return $this;
} | php | {
"resource": ""
} |
q15742 | ListCryptoKeyVersionsRequest.setView | train | public function setView($var)
{
GPBUtil::checkEnum($var, \Google\Cloud\Kms\V1\CryptoKeyVersion_CryptoKeyVersionView::class);
$this->view = $var;
return $this;
} | php | {
"resource": ""
} |
q15743 | Model.setImageClassificationModelMetadata | train | public function setImageClassificationModelMetadata($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\AutoMl\V1beta1\ImageClassificationModelMetadata::class);
$this->writeOneof(13, $var);
return $this;
} | php | {
"resource": ""
} |
q15744 | Model.setTextClassificationModelMetadata | train | public function setTextClassificationModelMetadata($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\AutoMl\V1beta1\TextClassificationModelMetadata::class);
$this->writeOneof(14, $var);
return $this;
} | php | {
"resource": ""
} |
q15745 | Model.setTranslationModelMetadata | train | public function setTranslationModelMetadata($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\AutoMl\V1beta1\TranslationModelMetadata::class);
$this->writeOneof(15, $var);
return $this;
} | php | {
"resource": ""
} |
q15746 | Model.setDeploymentState | train | public function setDeploymentState($var)
{
GPBUtil::checkEnum($var, \Google\Cloud\AutoMl\V1beta1\Model_DeploymentState::class);
$this->deployment_state = $var;
return $this;
} | php | {
"resource": ""
} |
q15747 | ListDeidentifyTemplatesResponse.setDeidentifyTemplates | train | public function setDeidentifyTemplates($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Dlp\V2\DeidentifyTemplate::class);
$this->deidentify_templates = $arr;
return $this;
} | php | {
"resource": ""
} |
q15748 | Interview.setRating | train | public function setRating($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\Talent\V4beta1\Rating::class);
$this->rating = $var;
return $this;
} | php | {
"resource": ""
} |
q15749 | AnnotateFileRequest.setInputConfig | train | public function setInputConfig($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\Vision\V1\InputConfig::class);
$this->input_config = $var;
return $this;
} | php | {
"resource": ""
} |
q15750 | AnnotateFileRequest.setFeatures | train | public function setFeatures($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Vision\V1\Feature::class);
$this->features = $arr;
return $this;
} | php | {
"resource": ""
} |
q15751 | AnnotateFileRequest.setPages | train | public function setPages($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
$this->pages = $arr;
return $this;
} | php | {
"resource": ""
} |
q15752 | Transaction.insertBatch | train | public function insertBatch(array $entities)
{
$entities = $this->operation->allocateIdsToEntities($entities);
foreach ($entities as $entity) {
$this->mutations[] = $this->operation->mutation('insert', $entity, Entity::class);
}
return $this;
} | php | {
"resource": ""
} |
q15753 | Transaction.updateBatch | train | public function updateBatch(array $entities, array $options = [])
{
$options += [
'allowOverwrite' => false
];
$this->operation->checkOverwrite($entities, $options['allowOverwrite']);
foreach ($entities as $entity) {
$this->mutations[] = $this->operation->mutation('update', $entity, Entity::class);
}
return $this;
} | php | {
"resource": ""
} |
q15754 | Transaction.deleteBatch | train | public function deleteBatch(array $keys)
{
foreach ($keys as $key) {
$this->mutations[] = $this->operation->mutation('delete', $key, Key::class);
}
return $this;
} | php | {
"resource": ""
} |
q15755 | Transaction.commit | train | public function commit(array $options = [])
{
$options['transaction'] = $this->transactionId;
return $this->operation->commit($this->mutations, $options);
} | php | {
"resource": ""
} |
q15756 | StreamingDetectIntentResponse.setRecognitionResult | train | public function setRecognitionResult($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\Dialogflow\V2\StreamingRecognitionResult::class);
$this->recognition_result = $var;
return $this;
} | php | {
"resource": ""
} |
q15757 | ListAssetsResult.setStateChange | train | public function setStateChange($var)
{
GPBUtil::checkEnum($var, \Google\Cloud\SecurityCenter\V1\ListAssetsResponse_ListAssetsResult_StateChange::class);
$this->state_change = $var;
return $this;
} | php | {
"resource": ""
} |
q15758 | UptimeCheckIp.setRegion | train | public function setRegion($var)
{
GPBUtil::checkEnum($var, \Google\Cloud\Monitoring\V3\UptimeCheckRegion::class);
$this->region = $var;
return $this;
} | php | {
"resource": ""
} |
q15759 | UpdateDeidentifyTemplateRequest.setDeidentifyTemplate | train | public function setDeidentifyTemplate($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\Dlp\V2\DeidentifyTemplate::class);
$this->deidentify_template = $var;
return $this;
} | php | {
"resource": ""
} |
q15760 | ValueValidation.setValues | train | public function setValues($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING);
$this->values = $arr;
return $this;
} | php | {
"resource": ""
} |
q15761 | BatchUpdateIntentsRequest.setIntentBatchInline | train | public function setIntentBatchInline($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\Dialogflow\V2\IntentBatch::class);
$this->writeOneof(3, $var);
return $this;
} | php | {
"resource": ""
} |
q15762 | PartOfSpeech.setTag | train | public function setTag($var)
{
GPBUtil::checkEnum($var, \Google\Cloud\Language\V1beta2\PartOfSpeech_Tag::class);
$this->tag = $var;
return $this;
} | php | {
"resource": ""
} |
q15763 | PartOfSpeech.setCase | train | public function setCase($var)
{
GPBUtil::checkEnum($var, \Google\Cloud\Language\V1beta2\PartOfSpeech_Case::class);
$this->case = $var;
return $this;
} | php | {
"resource": ""
} |
q15764 | PartOfSpeech.setForm | train | public function setForm($var)
{
GPBUtil::checkEnum($var, \Google\Cloud\Language\V1beta2\PartOfSpeech_Form::class);
$this->form = $var;
return $this;
} | php | {
"resource": ""
} |
q15765 | PartOfSpeech.setGender | train | public function setGender($var)
{
GPBUtil::checkEnum($var, \Google\Cloud\Language\V1beta2\PartOfSpeech_Gender::class);
$this->gender = $var;
return $this;
} | php | {
"resource": ""
} |
q15766 | PartOfSpeech.setNumber | train | public function setNumber($var)
{
GPBUtil::checkEnum($var, \Google\Cloud\Language\V1beta2\PartOfSpeech_Number::class);
$this->number = $var;
return $this;
} | php | {
"resource": ""
} |
q15767 | PartOfSpeech.setProper | train | public function setProper($var)
{
GPBUtil::checkEnum($var, \Google\Cloud\Language\V1beta2\PartOfSpeech_Proper::class);
$this->proper = $var;
return $this;
} | php | {
"resource": ""
} |
q15768 | PolicyBuilder.setBindings | train | public function setBindings(array $bindings = [])
{
$this->bindings = [];
foreach ($bindings as $binding) {
$this->addBinding($binding['role'], $binding['members']);
}
return $this;
} | php | {
"resource": ""
} |
q15769 | PolicyBuilder.removeBinding | train | public function removeBinding($role, array $members)
{
$bindings = $this->bindings;
foreach ((array) $bindings as $i => $binding) {
if ($binding['role'] == $role) {
$newMembers = array_diff($binding['members'], $members);
if (count($newMembers) != count($binding['members']) - count($members)) {
throw new InvalidArgumentException('One or more role-members were not found.');
}
if (empty($newMembers)) {
unset($bindings[$i]);
$bindings = array_values($bindings);
} else {
$binding['members'] = array_values($newMembers);
$bindings[$i] = $binding;
}
$this->bindings = $bindings;
return $this;
}
}
throw new InvalidArgumentException('The role was not found.');
} | php | {
"resource": ""
} |
q15770 | Logger.entries | train | public function entries(array $options = [])
{
$resultLimit = $this->pluck('resultLimit', $options, false);
$logNameFilter = "logName = $this->formattedName";
$options += [
'resourceNames' => ["projects/$this->projectId"],
'filter' => isset($options['filter'])
? $options['filter'] .= " AND $logNameFilter"
: $logNameFilter
];
return new ItemIterator(
new PageIterator(
function (array $entry) {
return new Entry($entry);
},
[$this->connection, 'listEntries'],
$options,
[
'itemsKey' => 'entries',
'resultLimit' => $resultLimit
]
)
);
} | php | {
"resource": ""
} |
q15771 | Logger.write | train | public function write($entry, array $options = [])
{
$entryOptions = $this->pluckArray($this->entryOptions, $options);
$this->writeBatch(
[$this->handleEntry($entry, $entryOptions)],
$options
);
} | php | {
"resource": ""
} |
q15772 | Logger.writeBatch | train | public function writeBatch(array $entries, array $options = [])
{
$this->validateBatch($entries, Entry::class);
foreach ($entries as &$entry) {
$entry = $entry->info();
}
$this->connection->writeEntries($options + ['entries' => $entries]);
} | php | {
"resource": ""
} |
q15773 | ListenResponse.setTargetChange | train | public function setTargetChange($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\Firestore\V1\TargetChange::class);
$this->writeOneof(2, $var);
return $this;
} | php | {
"resource": ""
} |
q15774 | Lifecycle.clearRules | train | public function clearRules($action = null)
{
if (!$action) {
$this->lifecycle = [];
return $this;
}
if (!is_string($action) && !is_callable($action)) {
throw new \InvalidArgumentException(
sprintf(
'Expected either a string or callable, instead got \'%s\'.',
gettype($action)
)
);
}
if (isset($this->lifecycle['rule'])) {
if (is_string($action)) {
$action = function ($rule) use ($action) {
return $rule['action']['type'] !== $action;
};
}
$this->lifecycle['rule'] = array_filter(
$this->lifecycle['rule'],
$action
);
if (!$this->lifecycle['rule']) {
$this->lifecycle = [];
}
}
return $this;
} | php | {
"resource": ""
} |
q15775 | SetMaintenancePolicyRequest.setMaintenancePolicy | train | public function setMaintenancePolicy($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\Container\V1\MaintenancePolicy::class);
$this->maintenance_policy = $var;
return $this;
} | php | {
"resource": ""
} |
q15776 | ArrayTrait.pluck | train | private function pluck($key, array &$arr, $isRequired = true)
{
if (!array_key_exists($key, $arr)) {
if ($isRequired) {
throw new \InvalidArgumentException(
"Key $key does not exist in the provided array."
);
}
return null;
}
$value = $arr[$key];
unset($arr[$key]);
return $value;
} | php | {
"resource": ""
} |
q15777 | ArrayTrait.pluckArray | train | private function pluckArray(array $keys, &$arr)
{
$values = [];
foreach ($keys as $key) {
if (array_key_exists($key, $arr)) {
$values[$key] = $this->pluck($key, $arr, false);
}
}
return $values;
} | php | {
"resource": ""
} |
q15778 | ArrayTrait.arrayMergeRecursive | train | private function arrayMergeRecursive(array $array1, array $array2)
{
foreach ($array2 as $key => $value) {
if (array_key_exists($key, $array1) && is_array($array1[$key]) && is_array($value)) {
$array1[$key] = ($this->isAssoc($array1[$key]) && $this->isAssoc($value))
? $this->arrayMergeRecursive($array1[$key], $value)
: array_merge($array1[$key], $value);
} else {
$array1[$key] = $value;
}
}
return $array1;
} | php | {
"resource": ""
} |
q15779 | Sink.update | train | public function update(array $metadata, array $options = [])
{
$options += $metadata;
$options += $this->info($options);
return $this->info = $this->connection->updateSink($options + [
'sinkName' => $this->formattedName
]);
} | php | {
"resource": ""
} |
q15780 | Sink.reload | train | public function reload(array $options = [])
{
return $this->info = $this->connection->getSink($options + [
'sinkName' => $this->formattedName
]);
} | php | {
"resource": ""
} |
q15781 | RedactImageRequest.setImageRedactionConfigs | train | public function setImageRedactionConfigs($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Dlp\V2\RedactImageRequest\ImageRedactionConfig::class);
$this->image_redaction_configs = $arr;
return $this;
} | php | {
"resource": ""
} |
q15782 | RedactImageRequest.setByteItem | train | public function setByteItem($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\Dlp\V2\ByteContentItem::class);
$this->byte_item = $var;
return $this;
} | php | {
"resource": ""
} |
q15783 | SearchProfilesResponse.setSpellCorrection | train | public function setSpellCorrection($var)
{
GPBUtil::checkMessage($var, \Google\Cloud\Talent\V4beta1\SpellingCorrection::class);
$this->spell_correction = $var;
return $this;
} | php | {
"resource": ""
} |
q15784 | Instance.setType | train | public function setType($var)
{
GPBUtil::checkEnum($var, \Google\Cloud\Bigtable\Admin\V2\Instance_Type::class);
$this->type = $var;
return $this;
} | php | {
"resource": ""
} |
q15785 | Intersection.setRules | train | public function setRules($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Bigtable\Admin\V2\GcRule::class);
$this->rules = $arr;
return $this;
} | php | {
"resource": ""
} |
q15786 | CacheSessionPool.release | train | public function release(Session $session)
{
$this->config['lock']->synchronize(function () use ($session) {
$item = $this->cacheItemPool->getItem($this->cacheKey);
$data = $item->get();
$name = $session->name();
if (isset($data['inUse'][$name])) {
unset($data['inUse'][$name]);
array_push($data['queue'], [
'name' => $name,
'expiration' => $session->expiration()
?: $this->time() + SessionPoolInterface::SESSION_EXPIRATION_SECONDS
]);
$this->cacheItemPool->save($item->set($data));
}
});
} | php | {
"resource": ""
} |
q15787 | CacheSessionPool.keepAlive | train | public function keepAlive(Session $session)
{
$this->config['lock']->synchronize(function () use ($session) {
$item = $this->cacheItemPool->getItem($this->cacheKey);
$data = $item->get();
$data['inUse'][$session->name()]['lastActive'] = $this->time();
$this->cacheItemPool->save($item->set($data));
});
} | php | {
"resource": ""
} |
q15788 | CacheSessionPool.warmup | train | public function warmup()
{
$toCreate = $this->config['lock']->synchronize(function () {
$item = $this->cacheItemPool->getItem($this->cacheKey);
$data = (array) $item->get() ?: $this->initialize();
$count = $this->getSessionCount($data);
$toCreate = [];
if ($count < $this->config['minSessions']) {
$toCreate = $this->buildToCreateList($this->config['minSessions'] - $count);
$data['toCreate'] += $toCreate;
$this->cacheItemPool->save($item->set($data));
}
return $toCreate;
});
if (!$toCreate) {
return 0;
}
$createdSessions = [];
$exception = null;
try {
$createdSessions = $this->createSessions(count($toCreate));
} catch (\Exception $exception) {
}
$this->config['lock']->synchronize(function () use ($toCreate, $createdSessions) {
$item = $this->cacheItemPool->getItem($this->cacheKey);
$data = $item->get();
$data['queue'] = array_merge($data['queue'], $createdSessions);
// Now that we've created the sessions, we can remove them from
// the list of intent.
foreach ($toCreate as $id => $time) {
unset($data['toCreate'][$id]);
}
$this->cacheItemPool->save($item->set($data));
});
if ($exception) {
throw $exception;
}
return count($toCreate);
} | php | {
"resource": ""
} |
q15789 | CacheSessionPool.clear | train | public function clear()
{
$sessions = $this->config['lock']->synchronize(function () {
$item = $this->cacheItemPool->getItem($this->cacheKey);
$data = (array) $item->get() ?: $this->initialize();
$sessions = $data['queue'] + $data['inUse'];
$this->cacheItemPool->clear();
return $sessions;
});
$this->deleteSessions($sessions);
} | php | {
"resource": ""
} |
q15790 | CacheSessionPool.setDatabase | train | public function setDatabase(Database $database)
{
$this->database = $database;
$identity = $database->identity();
$this->cacheKey = sprintf(
self::CACHE_KEY_TEMPLATE,
$identity['projectId'],
$identity['instance'],
$identity['database']
);
if (!isset($this->config['lock'])) {
$this->config['lock'] = $this->getDefaultLock();
}
} | php | {
"resource": ""
} |
q15791 | CacheSessionPool.buildToCreateList | train | private function buildToCreateList($number)
{
$toCreate = [];
$time = $this->time();
for ($i = 0; $i < $number; $i++) {
$toCreate[uniqid($time . '_', true)] = $time;
}
return $toCreate;
} | php | {
"resource": ""
} |
q15792 | CacheSessionPool.purgeOrphanedToCreateItems | train | private function purgeOrphanedToCreateItems(array &$data)
{
foreach ($data['toCreate'] as $key => $timestamp) {
$time = $this->time();
if ($timestamp + self::DURATION_TWENTY_MINUTES < $this->time()) {
unset($data['toCreate'][$key]);
}
}
} | php | {
"resource": ""
} |
q15793 | CacheSessionPool.purgeOrphanedInUseSessions | train | private function purgeOrphanedInUseSessions(array &$data)
{
foreach ($data['inUse'] as $key => $session) {
if ($session['lastActive'] + SessionPoolInterface::SESSION_EXPIRATION_SECONDS < $this->time()) {
unset($data['inUse'][$key]);
} elseif ($session['lastActive'] + self::DURATION_TWENTY_MINUTES < $this->time()) {
unset($session['lastActive']);
array_push($data['queue'], $session);
unset($data['inUse'][$key]);
}
}
} | php | {
"resource": ""
} |
q15794 | CacheSessionPool.getSession | train | private function getSession(array &$data)
{
$session = array_shift($data['queue']);
if ($session) {
if ($session['expiration'] - self::DURATION_ONE_MINUTE < $this->time()) {
return $this->getSession($data);
}
$data['inUse'][$session['name']] = $session + [
'lastActive' => $this->time()
];
if ($this->config['shouldAutoDownsize']) {
$this->manageSessionsToDelete($data);
}
}
return $session;
} | php | {
"resource": ""
} |
q15795 | CacheSessionPool.createSessions | train | private function createSessions($count)
{
$args = [
'database' => $this->database->name(),
'session' => [
'labels' => isset($this->config['labels']) ? $this->config['labels'] : []
]
];
$promises = [];
for ($i = 0; $i < $count; $i++) {
$promises[] = $this->database->connection()->createSessionAsync($args);
}
$results = Promise\settle($promises)->wait();
$sessions = [];
foreach ($results as $result) {
if ($result['state'] === 'fulfilled') {
$name = $result['value']->getName();
$sessions[] = [
'name' => $name,
'expiration' => $this->time() + SessionPoolInterface::SESSION_EXPIRATION_SECONDS
];
}
}
return $sessions;
} | php | {
"resource": ""
} |
q15796 | CacheSessionPool.isSessionValid | train | private function isSessionValid(array $session)
{
$halfHourBeforeExpiration = $session['expiration'] - (SessionPoolInterface::SESSION_EXPIRATION_SECONDS / 2);
if ($this->time() < $halfHourBeforeExpiration) {
return true;
} elseif ($halfHourBeforeExpiration < $this->time() && $this->time() < $session['expiration']) {
return $this->database
->session($session['name'])
->exists();
}
return false;
} | php | {
"resource": ""
} |
q15797 | CacheSessionPool.handleSession | train | private function handleSession(array $session)
{
if ($this->isSessionValid($session)) {
return $session;
}
$this->config['lock']->synchronize(function () use ($session) {
$item = $this->cacheItemPool->getItem($this->cacheKey);
$data = $item->get();
unset($data['inUse'][$session['name']]);
$this->cacheItemPool->save($item->set($data));
});
} | php | {
"resource": ""
} |
q15798 | CacheSessionPool.waitForNextAvailableSession | train | private function waitForNextAvailableSession()
{
$elapsedCycles = 0;
while (true) {
$session = $this->config['lock']->synchronize(function () use ($elapsedCycles) {
$item = $this->cacheItemPool->getItem($this->cacheKey);
$data = $item->get();
$session = $this->getSession($data);
if ($session) {
$this->cacheItemPool->save($item->set($data));
return $session;
}
if ($this->config['maxCyclesToWaitForSession'] <= $elapsedCycles) {
$this->cacheItemPool->save($item->set($data));
throw new \RuntimeException(
'A session did not become available in the allotted number of attempts.'
);
}
});
if ($session && $this->handleSession($session)) {
return $session;
}
$elapsedCycles++;
usleep($this->config['sleepIntervalSeconds'] * 1000000);
}
} | php | {
"resource": ""
} |
q15799 | CacheSessionPool.getDefaultLock | train | private function getDefaultLock()
{
if ($this->isSysvIPCLoaded()) {
return new SemaphoreLock(
$this->getSysvKey(crc32($this->cacheKey))
);
}
return new FlockLock($this->cacheKey);
} | php | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.