sentence1
stringlengths 52
3.87M
| sentence2
stringlengths 1
47.2k
| label
stringclasses 1
value |
---|---|---|
protected function shouldBeIncluded(string $sectionName): bool
{
return (count($this->includeExcluded) > 0 && in_array($sectionName, $this->includeExcluded));
} | @param string $sectionName
@return bool | entailment |
protected function isExcludedByName(string $sectionName): bool
{
return count($this->excludedSections) > 0 && in_array($sectionName, $this->excludedSections);
} | @param string $sectionName
@return bool | entailment |
public function buildSection(string $name, array $definition): SectionInterface
{
$section = new Section($name);
$this->setExcluded($section, $definition);
$this->setPreCommand($section, $definition);
$this->setPostCommand($section, $definition);
return $section;
} | @param string $name
@param array $definition
@return \Spryker\Install\Stage\Section\SectionInterface | entailment |
protected function setExcluded(SectionInterface $section, array $definition)
{
if (isset($definition[static::CONFIG_EXCLUDED]) && $definition[static::CONFIG_EXCLUDED]) {
$section->markAsExcluded();
}
} | @param \Spryker\Install\Stage\Section\SectionInterface $section
@param array $definition
@return void | entailment |
protected function setPreCommand(SectionInterface $section, array $definition)
{
if (isset($definition[static::CONFIG_PRE_COMMAND])) {
$section->setPreCommand($definition[static::CONFIG_PRE_COMMAND]);
}
} | @param \Spryker\Install\Stage\Section\SectionInterface $section
@param array $definition
@return void | entailment |
protected function setPostCommand(SectionInterface $section, array $definition)
{
if (isset($definition[static::CONFIG_POST_COMMAND])) {
$section->setPostCommand($definition[static::CONFIG_POST_COMMAND]);
}
} | @param \Spryker\Install\Stage\Section\SectionInterface $section
@param array $definition
@return void | entailment |
private static function _createBatchHelper(Api\MtBatchSmsCreate &$batch)
{
$fields = [
'from' => $batch->getSender(),
'to' => $batch->getRecipients()
];
if (null != $batch->getDeliveryReport()) {
$fields['delivery_report'] = $batch->getDeliveryReport();
}
if (null != $batch->getSendAt()) {
$fields['send_at'] = Serialize::_dateTime($batch->getSendAt());
}
if (null != $batch->getExpireAt()) {
$fields['expire_at'] = Serialize::_dateTime($batch->getExpireAt());
}
if (null != $batch->getTags()) {
$fields['tags'] = $batch->getTags();
}
if (null != $batch->getCallbackUrl()) {
$fields['callback_url'] = $batch->getCallbackUrl();
}
return $fields;
} | Helper that prepares the fields of a batch creates for JSON
serialization.
@param Api\MtBatchSmsCreate $batch the batch to serialize
@return [] associative array for JSON serialization | entailment |
public static function textBatch(Api\MtBatchTextSmsCreate $batch)
{
$fields = Serialize::_createBatchHelper($batch);
$fields['type'] = 'mt_text';
$fields['body'] = $batch->getBody();
if (!empty($batch->getParameters())) {
$fields['parameters'] = $batch->getParameters();
}
return Serialize::_toJson($fields);
} | Serializes the given text batch into JSON.
@param Api\MtBatchTextSmsCreate $batch the batch to serialize
@return string JSON formatted string | entailment |
public static function binaryBatch(Api\MtBatchBinarySmsCreate $batch)
{
$fields = Serialize::_createBatchHelper($batch);
$fields['type'] = 'mt_binary';
$fields['body'] = base64_encode($batch->getBody());
$fields['udh'] = bin2hex($batch->getUdh());
return Serialize::_toJson($fields);
} | Serializes the given binary batch into JSON.
@param Api\MtBatchBinarySmsCreate $batch the batch to serialize
@return string JSON formatted string | entailment |
private static function _batchUpdateHelper(Api\MtBatchSmsUpdate $batch)
{
$fields = [];
if (!empty($batch->getRecipientInsertions())) {
$fields['to_add'] = $batch->getRecipientInsertions();
}
if (!empty($batch->getRecipientRemovals())) {
$fields['to_remove'] = $batch->getRecipientRemovals();
}
if (null != $batch->getSender()) {
$fields['from'] = $batch->getSender();
}
if (null != $batch->getDeliveryReport()) {
if ($batch->getDeliveryReport() === Api\Reset::reset()) {
$fields['delivery_report'] = null;
} else {
$fields['delivery_report'] = $batch->getDeliveryReport();
}
}
if (null != $batch->getSendAt()) {
if ($batch->getSendAt() === Api\Reset::reset()) {
$fields['send_at'] = null;
} else {
$fields['send_at'] = Serialize::_dateTime($batch->getSendAt());
}
}
if (null != $batch->getExpireAt()) {
if ($batch->getExpireAt() === Api\Reset::reset()) {
$fields['expire_at'] = null;
} else {
$fields['expire_at']
= Serialize::_dateTime($batch->getExpireAt());
}
}
if (null != $batch->getCallbackUrl()) {
if ($batch->getCallbackUrl() === Api\Reset::reset()) {
$fields['callback_url'] = null;
} else {
$fields['callback_url'] = $batch->getCallbackUrl();
}
}
return $fields;
} | Helper that prepares the given batch for serialization
@param Api\MtBatchSmsUpdate $batch the batch to serialize
@return [] associative array suitable for JSON serialization | entailment |
public static function textBatchUpdate(Api\MtBatchTextSmsUpdate $batch)
{
$fields = Serialize::_batchUpdateHelper($batch);
$fields['type'] = 'mt_text';
if (null != $batch->getBody()) {
$fields['body'] = $batch->getBody();
}
if (null != $batch->getParameters()) {
if ($batch->getParameters() === Api\Reset::reset()) {
$fields['parameters'] = null;
} else {
$fields['parameters'] = $batch->getParameters();
}
}
return Serialize::_toJson($fields);
} | Serializes the given text batch update into JSON.
@param Api\MtBatchTextSmsUpdate $batch the batch update to serialize
@return string JSON formatted string | entailment |
public static function binaryBatchUpdate(Api\MtBatchBinarySmsUpdate $batch)
{
$fields = Serialize::_batchUpdateHelper($batch);
$fields['type'] = 'mt_binary';
if (null != $batch->getBody()) {
$fields['body'] = base64_encode($batch->getBody());
}
if (null != $batch->getUdh()) {
$fields['udh'] = bin2hex($batch->getUdh());
}
return Serialize::_toJson($fields);
} | Serializes the given binary batch update into JSON.
@param Api\MtBatchBinarySmsUpdate $batch the batch update to serialize
@return string JSON formatted string | entailment |
public static function _groupAutoUpdateHelper(
Api\GroupAutoUpdate $autoUpdate
) {
$fields = [ 'to' => $autoUpdate->getRecipient() ];
if (null != $autoUpdate->getAddFirstWord()) {
$fields['add']['first_word'] = $autoUpdate->getAddFirstWord();
}
if (null != $autoUpdate->getAddSecondWord()) {
$fields['add']['second_word'] = $autoUpdate->getAddSecondWord();
}
if (null != $autoUpdate->getRemoveFirstWord()) {
$fields['remove']['first_word'] = $autoUpdate->getRemoveFirstWord();
}
if (null != $autoUpdate->getRemoveSecondWord()) {
$fields['remove']['second_word'] = $autoUpdate->getRemoveSecondWord();
}
return $fields;
} | Helper that prepares the given group auto update for JSON
serialization.
@param Api\GroupAutoUpdate $autoUpdate the auto update to serialize
@return [] associative array suitable for JSON serialization | entailment |
public static function group(Api\GroupCreate $group)
{
$fields = [];
if ($group->getName() != null) {
$fields['name'] = $group->getName();
}
if (!empty($group->getMembers())) {
$fields['members'] = $group->getMembers();
}
if (!empty($group->getChildGroups())) {
$fields['child_groups'] = $group->getChildGroups();
}
if ($group->getAutoUpdate() != null) {
$fields['auto_update'] = Serialize::_groupAutoUpdateHelper(
$group->getAutoUpdate()
);
}
if (!empty($group->getTags())) {
$fields['tags'] = $group->getTags();
}
return Serialize::_toJson($fields);
} | Serializes the given group create object to JSON.
@param Api\GroupCreate $group the group to serialize
@return string a JSON string | entailment |
public static function groupUpdate(Api\GroupUpdate $groupUpdate)
{
$fields = [];
if (null != $groupUpdate->getName()) {
$fields['name'] = $groupUpdate->getName() === Api\Reset::reset()
? null
: $groupUpdate->getName();
}
if (!empty($groupUpdate->getMemberInsertions())) {
$fields['add'] = $groupUpdate->getMemberInsertions();
}
if (!empty($groupUpdate->getMemberRemovals())) {
$fields['remove'] = $groupUpdate->getMemberRemovals();
}
if (!empty($groupUpdate->getChildGroupInsertions())) {
$fields['child_groups_add']
= $groupUpdate->getChildGroupInsertions();
}
if (!empty($groupUpdate->getChildGroupRemovals())) {
$fields['child_groups_remove']
= $groupUpdate->getChildGroupRemovals();
}
if (null != $groupUpdate->getAddFromGroup()) {
$fields['add_from_group'] = $groupUpdate->getAddFromGroup();
}
if (null != $groupUpdate->getRemoveFromGroup()) {
$fields['remove_from_group'] = $groupUpdate->getRemoveFromGroup();
}
if (null != $groupUpdate->getAutoUpdate()) {
if ($groupUpdate->getAutoUpdate() === Api\Reset::reset()) {
$fields['auto_update'] = null;
} else {
$fields['auto_update'] = Serialize::_groupAutoUpdateHelper(
$groupUpdate->getAutoUpdate()
);
}
}
return empty($fields) ? '{}' : Serialize::_toJson($fields);
} | Serializes the given group update object to JSON.
@param Api\GroupUpdate $groupUpdate the group update to serialize
@return string a JSON string | entailment |
protected function addActivate(Builder $builder): void
{
$builder->macro('activate', function (Builder $builder) {
$builder->withNotActivated();
return $builder->update(['is_active' => 1]);
});
} | Add the `activate` extension to the builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@return void | entailment |
protected function addUndoActivate(Builder $builder): void
{
$builder->macro('undoActivate', function (Builder $builder) {
return $builder->update(['is_active' => 0]);
});
} | Add the `undoActivate` extension to the builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@return void | entailment |
protected function addWithNotActivated(Builder $builder): void
{
$builder->macro('withNotActivated', function (Builder $builder) {
return $builder->withoutGlobalScope($this);
});
} | Add the `withNotActivated` extension to the builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@return void | entailment |
protected function addWithoutNotActivated(Builder $builder): void
{
$builder->macro('withoutNotActivated', function (Builder $builder) {
return $builder->withoutGlobalScope($this)->where('is_active', 1);
});
} | Add the `withoutNotActivated` extension to the builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@return void | entailment |
protected function addOnlyNotActivated(Builder $builder): void
{
$builder->macro('onlyNotActivated', function (Builder $builder) {
return $builder->withoutGlobalScope($this)->where('is_active', 0);
});
} | Add the `onlyNotActivated` extension to the builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@return void | entailment |
public function run(CommandInterface $command, ConfigurationInterface $configuration)
{
if (!$this->shouldBeExecuted($command, $configuration)) {
return;
}
$this->environmentHelper->putEnvs($command->getEnv());
$this->runPreCommand($command, $configuration);
$this->runCommand($command, $configuration);
$this->runPostCommand($command, $configuration);
$this->environmentHelper->unsetEnvs($command->getEnv());
$this->environmentHelper->putEnvs($configuration->getEnv());
if ($configuration->isDebugMode() && !$configuration->getOutput()->confirm('Should install resume?', true)) {
throw new InstallException('Install aborted...');
}
} | @param \Spryker\Install\Stage\Section\Command\CommandInterface $command
@param \Spryker\Install\Configuration\ConfigurationInterface $configuration
@throws \Spryker\Install\Exception\InstallException
@return void | entailment |
protected function runPreCommand(CommandInterface $command, ConfigurationInterface $configuration)
{
if ($command->hasPreCommand()) {
$this->run($configuration->findCommand($command->getPreCommand()), $configuration);
}
} | @param \Spryker\Install\Stage\Section\Command\CommandInterface $command
@param \Spryker\Install\Configuration\ConfigurationInterface $configuration
@return void | entailment |
protected function runCommand(CommandInterface $command, ConfigurationInterface $configuration)
{
$executable = $this->executableFactory->createExecutableFromCommand($command, $configuration);
if (!$command->isStoreAware()) {
$this->executeExecutable($executable, $command, $configuration);
return;
}
foreach ($this->getExecutableStoresForCommand($command, $configuration) as $store) {
$this->environmentHelper->putEnv('APPLICATION_STORE', $store);
$this->executeExecutable($executable, $command, $configuration, $store);
$this->environmentHelper->unsetEnv('APPLICATION_STORE');
}
} | @param \Spryker\Install\Stage\Section\Command\CommandInterface $command
@param \Spryker\Install\Configuration\ConfigurationInterface $configuration
@return void | entailment |
protected function getExecutableStoresForCommand(CommandInterface $command, ConfigurationInterface $configuration): array
{
if (!$command->hasStores()) {
return $configuration->getExecutableStores();
}
return array_intersect($configuration->getExecutableStores(), $command->getStores());
} | @param \Spryker\Install\Stage\Section\Command\CommandInterface $command
@param \Spryker\Install\Configuration\ConfigurationInterface $configuration
@return string[] | entailment |
protected function runPostCommand(CommandInterface $command, ConfigurationInterface $configuration)
{
if ($command->hasPostCommand()) {
$this->run($configuration->findCommand($command->getPostCommand()), $configuration);
}
} | @param \Spryker\Install\Stage\Section\Command\CommandInterface $command
@param \Spryker\Install\Configuration\ConfigurationInterface $configuration
@return void | entailment |
protected function shouldBeExecuted(CommandInterface $command, ConfigurationInterface $configuration): bool
{
if ($configuration->isDryRun()) {
$configuration->getOutput()->dryRunCommand($command);
return false;
}
if ($command->isExcluded() || $this->hasConditionAndConditionNotMatched($command)) {
return false;
}
return true;
} | @param \Spryker\Install\Stage\Section\Command\CommandInterface $command
@param \Spryker\Install\Configuration\ConfigurationInterface $configuration
@return bool | entailment |
protected function hasConditionAndConditionNotMatched(CommandInterface $command): bool
{
if (!$this->isConditionalCommand($command) || $this->conditionMatched($command)) {
return false;
}
return true;
} | @param \Spryker\Install\Stage\Section\Command\CommandInterface $command
@return bool | entailment |
protected function conditionMatched(CommandInterface $command): bool
{
$matchedConditions = true;
foreach ($command->getConditions() as $condition) {
if (!$condition->match($this->commandExitCodes)) {
$matchedConditions = false;
}
}
return $matchedConditions;
} | @param \Spryker\Install\Stage\Section\Command\CommandInterface $command
@return bool | entailment |
protected function executeExecutable(
ExecutableInterface $executable,
CommandInterface $command,
ConfigurationInterface $configuration,
?string $store = null
) {
$configuration->getOutput()->startCommand($command, $store);
$exitCode = $executable->execute($configuration->getOutput());
$this->commandExitCodes[$command->getName()] = $exitCode;
$configuration->getOutput()->endCommand($command, $exitCode, $store);
} | @param \Spryker\Install\Executable\ExecutableInterface $executable
@param \Spryker\Install\Stage\Section\Command\CommandInterface $command
@param \Spryker\Install\Configuration\ConfigurationInterface $configuration
@param string|null $store
@return void | entailment |
public function getHeaders(bool $implode = false, bool $ucwords = false): array
{
if ($ucwords && $implode) {
$headers = [];
foreach ($this->headers as $key => $val) {
$key = ucwords($key, '-');
$headers[$key] = implode(', ', $val);
}
return $headers;
} elseif ($ucwords) {
$headers = [];
foreach ($this->headers as $key => $val) {
$key = ucwords($key, '-');
$headers[$key] = $val;
}
return $headers;
} elseif ($implode) {
$headers = [];
foreach ($this->headers as $key => $val) {
$headers[$key] = implode(', ', $val);
}
return $headers;
}
return $this->headers;
} | get all headers
@param bool $implode
@param bool $ucwords
@return array | entailment |
public static function getResponseBodySummary(Response $response): string
{
$body = $response->getBody();
$size = $body->getSize();
if ($size === 0) {
return '';
}
$summary = $body->read(120);
$body->rewind();
if ($size > 120) {
$summary .= ' (truncated...)';
}
// Matches any printable character, including unicode characters:
// letters, marks, numbers, punctuation, spacing, and separators.
if (preg_match('/[^\pL\pM\pN\pP\pS\pZ\n\r\t]/', $summary)) {
return '';
}
return $summary;
} | Get a short summary of the response
Will return `null` if the response is not printable.
@param Response $response
@return string | entailment |
public function startInstall(StageInterface $stage)
{
$this->timer->start($stage);
$message = sprintf('Install <fg=green>%s</> environment', $stage->getName());
$messageLengthWithoutDecoration = Helper::strlenWithoutDecoration($this->output->getFormatter(), $message);
$message = $message . str_pad(' ', $this->lineLength - $messageLengthWithoutDecoration);
$this->writeln([
str_repeat('=', $this->lineLength),
$message,
str_repeat('=', $this->lineLength),
]);
$this->newLine();
} | @param \Spryker\Install\Stage\StageInterface $stage
@return void | entailment |
public function endInstall(StageInterface $stage)
{
$message = sprintf('Install <fg=green>%s</> finished in <fg=green>%ss</>', $stage->getName(), $this->timer->end($stage));
$this->writeln($message);
} | @param \Spryker\Install\Stage\StageInterface $stage
@return void | entailment |
public function startSection(SectionInterface $section)
{
$this->timer->start($section);
$message = sprintf('<bg=green;options=bold> Section %s</>', $section->getName());
$messageLengthWithoutDecoration = Helper::strlenWithoutDecoration($this->output->getFormatter(), $message);
$messageLength = $this->lineLength - $messageLengthWithoutDecoration;
$this->writeln([
sprintf('<bg=green>%s</>', str_repeat(' ', $this->lineLength)),
sprintf('<bg=green;options=bold>%s%s</>', $message, str_pad(' ', $messageLength)),
sprintf('<bg=green>%s</>', str_repeat(' ', $this->lineLength)),
]);
$this->newLine();
} | @param \Spryker\Install\Stage\Section\SectionInterface $section
@return void | entailment |
public function endSection(SectionInterface $section)
{
$this->newLine();
if ($this->output->isVerbose()) {
$message = sprintf('Section <fg=green>%s</> finished in <fg=green>%ss</>', $section->getName(), $this->timer->end($section));
$this->writeln($message);
$this->writeln(str_repeat('=', $this->lineLength));
$this->newLine(3);
}
} | @param \Spryker\Install\Stage\Section\SectionInterface $section
@return void | entailment |
public function startCommand(CommandInterface $command, $store = null)
{
$this->timer->start($command);
$message = $this->getStartCommandMessage($command, $store);
if ($this->output->getVerbosity() === static::VERBOSITY_NORMAL) {
$message .= sprintf(' <fg=magenta>(In progress...)</>');
}
if ($this->output->isVerbose()) {
$this->writeln($message);
$this->writeln(str_repeat('-', $this->lineLength));
$this->newLine();
return;
}
$this->writeln($message);
} | @param \Spryker\Install\Stage\Section\Command\CommandInterface $command
@param string|null $store
@return void | entailment |
protected function getStartCommandMessage(CommandInterface $command, $store = null)
{
$commandInfo = sprintf('Command <fg=green>%s</>', $command->getName());
$storeInfo = ($store) ? sprintf(' for <info>%s</info> store', $store) : '';
$executedInfo = sprintf(' <fg=yellow>[%s]</>', $command->getExecutable());
return $commandInfo . $storeInfo . $executedInfo;
} | @param \Spryker\Install\Stage\Section\Command\CommandInterface $command
@param string|null $store
@return string | entailment |
public function endCommand(CommandInterface $command, $exitCode, $store = null)
{
if ($this->output->isVeryVerbose()) {
$this->newLine();
}
if ($this->output->isVerbose()) {
$this->writeln($this->getVerboseCommandEndMessage($command, $exitCode));
$this->newLine();
return;
}
$this->endCommandOutputIfNormalOutput($command, $store);
} | @param \Spryker\Install\Stage\Section\Command\CommandInterface $command
@param int $exitCode
@param string|null $store
@return void | entailment |
protected function endCommandOutputIfNormalOutput(CommandInterface $command, $store = null)
{
if ($this->output->getVerbosity() === static::VERBOSITY_NORMAL) {
$message = $this->getStartCommandMessage($command, $store);
$message .= sprintf(' <fg=green>(%ss)</>', $this->timer->end($command));
$this->moveLineUp();
$this->moveCursorToBeginOfLine();
$this->eraseLine();
$this->writeln($message);
}
} | @param \Spryker\Install\Stage\Section\Command\CommandInterface $command
@param string|null $store
@return void | entailment |
protected function getVerboseCommandEndMessage(CommandInterface $command, $exitCode)
{
return sprintf(
'<fg=green>//</> Command <fg=green>%s</> finished in <fg=green>%ss</>, exit code <fg=%s>%s</>',
$command->getName(),
$this->timer->end($command),
($exitCode !== 0) ? 'red' : 'green',
$exitCode
);
} | @param \Spryker\Install\Stage\Section\Command\CommandInterface $command
@param int $exitCode
@return string | entailment |
public function dryRunCommand(CommandInterface $command)
{
$this->newLine();
$this->write(' // Dry-run: ' . $command->getName());
$this->newLine(3);
} | @param \Spryker\Install\Stage\Section\Command\CommandInterface $command
@return void | entailment |
public function innerCommand($output)
{
if ($this->output->isVeryVerbose()) {
$this->write($output);
}
if (!$this->output->isVeryVerbose()) {
$this->outputBuffer[] = $output;
}
} | @param string $output
@return void | entailment |
public function write($messages, $options = 0)
{
$this->log($messages);
$this->output->write($messages, false, $options);
} | @param array|string $messages
@param int $options
@return void | entailment |
protected function writeln($messages, $options = 0)
{
$this->log($messages);
$this->output->writeln($messages, $options);
} | @param array|string $messages
@param int $options
@return void | entailment |
protected function log($message): void
{
if ($this->logger !== null) {
$this->logger->log($message);
}
} | @param string|array $message
@return void | entailment |
public static function isDefaultPort(UriInterface $uri): bool
{
return $uri->getPort() === null
|| (isset(self::$defaultPorts[$uri->getScheme()]) && $uri->getPort() === self::$defaultPorts[$uri->getScheme()]);
} | Whether the URI has the default port of the current scheme.
`Psr\Http\Message\UriInterface::getPort` may return null or the standard port. This method can be used
independently of the implementation.
@param UriInterface $uri
@return bool | entailment |
public static function resolve($base, $rel): ?UriInterface
{
if ($base && $rel) {
if (!($base instanceof UriInterface)) {
$base = new self($base);
}
if (!($rel instanceof UriInterface)) {
$rel = new self($rel);
}
return UriResolver::resolve($base, $rel);
} elseif ($rel) {
return $rel instanceof UriInterface ? $rel : new self($rel);
} elseif ($base) {
return $base instanceof UriInterface ? $base : new self($base);
} else {
return null;
}
} | Converts the relative URI into a new URI that is resolved against the base URI.
@param string|UriInterface $base Base URI
@param string|UriInterface $rel Relative URI
@return UriInterface
@see UriResolver::resolve | entailment |
public static function withoutQueryValue(UriInterface $uri, $key): UriInterface
{
$current = $uri->getQuery();
if ($current === '') {
return $uri;
}
$decodedKey = rawurldecode($key);
$result = array_filter(explode('&', $current), function ($part) use ($decodedKey) {
return rawurldecode(explode('=', $part)[0]) !== $decodedKey;
});
return $uri->withQuery(implode('&', $result));
} | Creates a new URI with a specific query string value removed.
Any existing query string values that exactly match the provided key are
removed.
@param UriInterface $uri URI to use as a base.
@param string $key Query string key to remove.
@return UriInterface | entailment |
public static function withQueryValue(UriInterface $uri, $key, $value): UriInterface
{
$current = $uri->getQuery();
if ($current === '') {
$result = [];
} else {
$decodedKey = rawurldecode($key);
$result = array_filter(explode('&', $current), function ($part) use ($decodedKey) {
return rawurldecode(explode('=', $part)[0]) !== $decodedKey;
});
}
// Query string separators ("=", "&") within the key or value need to be encoded
// (while preventing double-encoding) before setting the query string. All other
// chars that need percent-encoding will be encoded by withQuery().
$key = strtr($key, self::$replaceQuery);
if ($value !== null) {
$result[] = $key . '=' . strtr($value, self::$replaceQuery);
} else {
$result[] = $key;
}
return $uri->withQuery(implode('&', $result));
} | Creates a new URI with a specific query string value.
Any existing query string values that exactly match the provided key are
removed and replaced with the given key value pair.
A value of null will set the query string key without a value, e.g. "key"
instead of "key=value".
@param UriInterface $uri URI to use as a base.
@param string $key Key to set.
@param string|null $value Value to set
@return UriInterface | entailment |
public static function fromParts(array $parts): UriInterface
{
$uri = new self();
$uri->applyParts($parts);
$uri->validateState();
return $uri;
} | Creates a URI from a hash of `parse_url` components.
@param array $parts
@return UriInterface
@link http://php.net/manual/en/function.parse-url.php
@throws TypeError If the components do not form a valid URI. | entailment |
private function filterHost(string $host): string
{
if ($host && $host !== self::HTTP_DEFAULT_HOST && strpos($host, '.') === false) {
throw new InvalidArgumentException("Host '{$host}' is illegal!");
}
return strtolower($host);
} | @param string $host
@return string
@throws TypeError If the host is invalid. | entailment |
public function createCondition(array $condition): ConditionInterface
{
foreach ($this->conditionNameToConditionClassMap as $conditionName => $conditionClass) {
if (isset($condition[$conditionName])) {
return new $conditionClass($condition['command'], $condition[$conditionName]);
}
}
throw new ConditionNotFoundException(sprintf('Condition could not be found, available conditions are: %s', implode(', ', $this->conditionNameToConditionClassMap)));
} | @param array $condition
@throws \Spryker\Install\Stage\Section\Command\Condition\Exception\ConditionNotFoundException
@return \Spryker\Install\Stage\Section\Command\Condition\ConditionInterface | entailment |
public function apply(Builder $builder, Model $model): void
{
if (method_exists($model, 'shouldApplyEndedAtScope') && $model->shouldApplyEndedAtScope()) {
$builder->whereNull('ended_at');
}
} | Apply the scope to a given Eloquent query builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@param \Illuminate\Database\Eloquent\Model $model
@return void | entailment |
protected function addUndoEnd(Builder $builder): void
{
$builder->macro('undoEnd', function (Builder $builder) {
$builder->withEnded();
return $builder->update(['ended_at' => null]);
});
} | Add the `undoEnd` extension to the builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@return void | entailment |
protected function addEnd(Builder $builder): void
{
$builder->macro('end', function (Builder $builder) {
return $builder->update(['ended_at' => Date::now()]);
});
} | Add the `end` extension to the builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@return void | entailment |
protected function addWithoutEnded(Builder $builder): void
{
$builder->macro('withoutEnded', function (Builder $builder) {
return $builder->withoutGlobalScope($this)->whereNull('ended_at');
});
} | Add the `withoutEnded` extension to the builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@return void | entailment |
protected function addOnlyEnded(Builder $builder): void
{
$builder->macro('onlyEnded', function (Builder $builder) {
return $builder->withoutGlobalScope($this)->whereNotNull('ended_at');
});
} | Add the `onlyEnded` extension to the builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@return void | entailment |
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->input = $input;
$this->output = $this->createOutput($input, $output);
$this->getFacade()->runInstall(
$this->getCommandLineArgumentContainer(),
$this->getCommandLineOptionContainer(),
$this->output
);
return 0;
} | @param \Symfony\Component\Console\Input\InputInterface $input
@param \Symfony\Component\Console\Output\OutputInterface $output
@return int|null | entailment |
protected function createOutput(InputInterface $input, OutputInterface $output): StyleInterface
{
$shouldLog = $input->getOption(static::OPTION_LOG);
return new SprykerStyle(
$input,
$output,
$this->getFactory()->createTimer(),
($shouldLog) ? $this->getFactory()->createOutputLogger() : null
);
} | @param \Symfony\Component\Console\Input\InputInterface $input
@param \Symfony\Component\Console\Output\OutputInterface $output
@return \Spryker\Style\StyleInterface | entailment |
protected function getCommandLineArgumentContainer(): CommandLineArgumentContainer
{
$store = $this->input->getArgument(self::ARGUMENT_STORE);
if ($store !== null && !is_string($store)) {
throw new InstallException(
sprintf(
'Value of `%s` argument should return `string|null` type. Return type is `%s`.',
self::ARGUMENT_STORE,
gettype($store)
)
);
}
return new CommandLineArgumentContainer($store);
} | @throws \Spryker\Install\Exception\InstallException
@return \Spryker\Install\CommandLine\CommandLineArgumentContainer | entailment |
protected function getCommandLineOptionContainer(): CommandLineOptionContainer
{
$recipeOption = $this->input->getOption(self::OPTION_RECIPE);
if (!is_string($recipeOption)) {
throw new InstallException(
sprintf(
'Value of `%s` option should return `string` type. Return `%s`.',
self::OPTION_RECIPE,
gettype($recipeOption)
)
);
}
return new CommandLineOptionContainer(
$recipeOption,
$this->getSectionsToBeExecuted(),
$this->getGroupsToBeExecuted(),
$this->getExcludedStagesAndExcludedGroups(),
$this->getIncludeExcluded(),
(bool)$this->input->getOption(static::OPTION_INTERACTIVE),
(bool)$this->input->getOption(static::OPTION_DRY_RUN),
(bool)$this->input->getOption(static::OPTION_BREAKPOINT),
(bool)$this->input->getOption(static::OPTION_ASK_BEFORE_CONTINUE)
);
} | @throws \Spryker\Install\Exception\InstallException
@return \Spryker\Install\CommandLine\CommandLineOptionContainer | entailment |
protected function getOptionAndComment($optionKey, $commentPattern): array
{
$option = (array)$this->input->getOption($optionKey);
if (count($option) > 0) {
$this->output->note(sprintf($commentPattern, implode(', ', $option)));
}
return $option;
} | @param string $optionKey
@param string $commentPattern
@return array | entailment |
public function addCommand(CommandInterface $command): SectionInterface
{
if (isset($this->commands[$command->getName()])) {
throw new CommandExistsException(sprintf('Command with name "%s" already exists.', $command->getName()));
}
$this->commands[$command->getName()] = $command;
return $this;
} | @param \Spryker\Install\Stage\Section\Command\CommandInterface $command
@throws \Spryker\Install\Stage\Section\Command\Exception\CommandExistsException
@return \Spryker\Install\Stage\Section\SectionInterface | entailment |
public function getCommand(string $commandName): CommandInterface
{
if (!isset($this->commands[$commandName])) {
throw new CommandNotFoundException(sprintf('Command "%s" not found in "%s" section', $commandName, $this->getName()));
}
return $this->commands[$commandName];
} | @param string $commandName
@throws \Spryker\Install\Stage\Section\Command\Exception\CommandNotFoundException
@return \Spryker\Install\Stage\Section\Command\CommandInterface | entailment |
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
{
$classMetadata = $eventArgs->getClassMetadata();
$reflClass = $classMetadata->reflClass;
if (!$reflClass) {
return;
}
if ($reflClass->implementsInterface('Prezent\Doctrine\Translatable\TranslatableInterface')) {
$this->mapTranslatable($classMetadata);
}
if ($reflClass->implementsInterface('Prezent\Doctrine\Translatable\TranslationInterface')) {
$this->mapTranslation($classMetadata);
}
} | Add mapping to translatable entities
@param LoadClassMetadataEventArgs $eventArgs
@return void | entailment |
private function mapTranslatable(ClassMetadata $mapping)
{
$metadata = $this->getTranslatableMetadata($mapping->name);
if ($metadata->targetEntity
&& $metadata->translations
&& !$mapping->hasAssociation($metadata->translations->name)
) {
$targetMetadata = $this->getTranslatableMetadata($metadata->targetEntity);
$mapping->mapOneToMany(array(
'fieldName' => $metadata->translations->name,
'targetEntity' => $metadata->targetEntity,
'mappedBy' => $targetMetadata->translatable->name,
'fetch' => ClassMetadataInfo::FETCH_EXTRA_LAZY,
'indexBy' => $targetMetadata->locale->name,
'cascade' => array('persist', 'merge', 'remove'),
'orphanRemoval' => true,
));
}
} | Add mapping data to a translatable entity
@param ClassMetadata $mapping
@return void | entailment |
private function mapTranslation(ClassMetadata $mapping)
{
$metadata = $this->getTranslatableMetadata($mapping->name);
// Map translatable relation
if ($metadata->targetEntity
&& $metadata->translatable
&& !$mapping->hasAssociation($metadata->translatable->name)
) {
$targetMetadata = $this->getTranslatableMetadata($metadata->targetEntity);
$mapping->mapManyToOne(array(
'fieldName' => $metadata->translatable->name,
'targetEntity' => $metadata->targetEntity,
'inversedBy' => $targetMetadata->translations->name,
'joinColumns' => array(array(
'name' => 'translatable_id',
'referencedColumnName' => 'id',
'onDelete' => 'CASCADE',
'nullable' => false,
)),
));
}
if (!$metadata->translatable) {
return;
}
// Map locale field
if (!$mapping->hasField($metadata->locale->name)) {
$mapping->mapField(array(
'fieldName' => $metadata->locale->name,
'type' => 'string',
));
}
// Map unique index
$columns = array(
$mapping->getSingleAssociationJoinColumnName($metadata->translatable->name),
$metadata->locale->name,
);
if (!$this->hasUniqueConstraint($mapping, $columns)) {
$constraints = isset($mapping->table['uniqueConstraints']) ? $mapping->table['uniqueConstraints']: array();
$constraints[$mapping->getTableName() . '_uniq_trans'] = array(
'columns' => $columns,
);
$mapping->setPrimaryTable(array(
'uniqueConstraints' => $constraints,
));
}
} | Add mapping data to a translation entity
@param ClassMetadata $mapping
@return void | entailment |
public function getTranslatableMetadata($className)
{
if (array_key_exists($className, $this->cache)) {
return $this->cache[$className];
}
if ($metadata = $this->metadataFactory->getMetadataForClass($className)) {
if (!$metadata->reflection->isAbstract()) {
$metadata->validate();
}
}
$this->cache[$className] = $metadata;
return $metadata;
} | Get translatable metadata
@param string $className
@return TranslatableMetadata|TranslationMetadata | entailment |
private function hasUniqueConstraint(ClassMetadata $mapping, array $columns)
{
if (!array_diff($mapping->getIdentifierColumnNames(), $columns)) {
return true;
}
if (!isset($mapping->table['uniqueConstraints'])) {
return false;
}
foreach ($mapping->table['uniqueConstraints'] as $constraint) {
if (!array_diff($constraint['columns'], $columns)) {
return true;
}
}
return false;
} | Check if an unique constraint has been defined
@param ClassMetadata $mapping
@param array $columns
@return bool | entailment |
public function postLoad(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
$metadata = $this->getTranslatableMetadata(get_class($entity));
if ($metadata instanceof TranslatableMetadata) {
if ($metadata->fallbackLocale) {
$metadata->fallbackLocale->setValue($entity, $this->getFallbackLocale());
}
if ($metadata->currentLocale) {
$metadata->currentLocale->setValue($entity, $this->getCurrentLocale());
}
}
} | Load translations
@param LifecycleEventArgs $args
@return void | entailment |
private function readMapping($className)
{
$file = $this->getMappingFile($className);
return $file ? $this->parse($file) : null;
} | Reads the configuration for the given classname.
@param string $className
@return mixed|null | entailment |
public static function parseHeader(string $raw_header): array
{
static $whole_fields = [
'date' => true,
'user-agent' => true,
];
/**
* 生成供于遍历的的header数组 ['row','row','row']
*/
// Pretend CRLF = LF for compatibility (RFC 2616, section 19.3)
$raw_header = str_replace("\r\n", "\n", $raw_header);
// Unfold headers (replace [CRLF] 1*( SP | HT ) with SP) as per RFC 2616 (section 2.2)
$raw_header = preg_replace('/\n[ \t]/', ' ', $raw_header);
$header = [];
$raw_header = preg_replace_callback('/(?:.*)HTTP\/[\d.]+(?: (\d+) [\w -]+)?\n/i',
function (array $match) use (&$header) {
if (!empty($match[1])) {
$header['status'] = [(int)$match[1]];
}
return '';
}, $raw_header);
$raw_header = explode("\n", $raw_header);
/**
* 生成可用的header数组 ['key'=>['val'],'key'=>['val'],'key'=>['val']]
*/
foreach ($raw_header as $row) {
list($key, $value) = explode(':', $row, 2);
$key = strtolower($key);
if ($key === 'set-cookie') {
$header[$key][] = self::trimHeaderValues($value);
} else {
$value = self::trimHeaderValues(
isset($whole_fields[$key]) ? [$value] : explode(",", $value)
);
$header[$key] = $value;
}
}
return $header;
} | 解析单个header
@param string $raw_header
@return array | entailment |
public static function parseHeaders(string $raw_header): array
{
$raw_header = explode("\r\n\r\n", $raw_header);
if (count($raw_header) > 1) {
$headers = [];
foreach ($raw_header as $header) {
$headers[] = self::parseHeader($header);
}
return $headers;
} else {
return self::parseHeader($raw_header[0]);
}
} | 解析header,传入多个header时返回[{header},{header},{header}]
@param string $raw_header
@return array | entailment |
protected function addAccept(Builder $builder): void
{
$builder->macro('accept', function (Builder $builder) {
$builder->withNotAccepted();
return $builder->update(['accepted_at' => Date::now()]);
});
} | Add the `accept` extension to the builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@return void | entailment |
protected function addUndoAccept(Builder $builder): void
{
$builder->macro('undoAccept', function (Builder $builder) {
return $builder->update(['accepted_at' => null]);
});
} | Add the `undoAccept` extension to the builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@return void | entailment |
protected function addWithNotAccepted(Builder $builder): void
{
$builder->macro('withNotAccepted', function (Builder $builder) {
return $builder->withoutGlobalScope($this);
});
} | Add the `withNotAccepted` extension to the builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@return void | entailment |
protected function addWithoutNotAccepted(Builder $builder): void
{
$builder->macro('withoutNotAccepted', function (Builder $builder) {
return $builder->withoutGlobalScope($this)->whereNotNull('accepted_at');
});
} | Add the `withoutNotAccepted` extension to the builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@return void | entailment |
protected function addOnlyNotAccepted(Builder $builder): void
{
$builder->macro('onlyNotAccepted', function (Builder $builder) {
return $builder->withoutGlobalScope($this)->whereNull('accepted_at');
});
} | Add the `onlyNotAccepted` extension to the builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@return void | entailment |
public function query($url, $data = null, $headers = array(), $method = 'get', $timeout = null)
{
$token = $this->getToken();
if (array_key_exists('expires_in', $token) && $token['created'] + $token['expires_in'] < time() + 20)
{
if (!$this->getOption('userefresh'))
{
return false;
}
$token = $this->refreshToken($token['refresh_token']);
}
if (!$this->getOption('authmethod') || $this->getOption('authmethod') == 'bearer')
{
$headers['Authorization'] = 'Bearer ' . $token['access_token'];
}
elseif ($this->getOption('authmethod') == 'get')
{
if (strpos($url, '?'))
{
$url .= '&';
}
else
{
$url .= '?';
}
$url .= $this->getOption('getparam') ? $this->getOption('getparam') : 'access_token';
$url .= '=' . $token['access_token'];
}
switch ($method)
{
case 'head':
case 'get':
case 'delete':
case 'trace':
$response = $this->http->$method($url, $headers, $timeout);
break;
case 'post':
case 'put':
case 'patch':
$response = $this->http->$method($url, $data, $headers, $timeout);
break;
default:
throw new InvalidArgumentException('Unknown HTTP request method: ' . $method . '.');
}
if ($response->code < 200 || $response->code >= 400)
{
// As of 2.0 this will throw an UnexpectedResponseException
throw new RuntimeException('Error code ' . $response->code . ' received requesting data: ' . $response->body . '.');
}
return $response;
} | Send a signed Oauth request.
@param string $url The URL for the request.
@param mixed $data The data to include in the request
@param array $headers The headers to send with the request
@param string $method The method with which to send the request
@param int $timeout The timeout for the request
@return \Joomla\Http\Response The http response object.
@since 1.0
@throws InvalidArgumentException
@throws RuntimeException | entailment |
public function setToken($value)
{
if (\is_array($value) && !array_key_exists('expires_in', $value) && array_key_exists('expires', $value))
{
$value['expires_in'] = $value['expires'];
unset($value['expires']);
}
$this->setOption('accesstoken', $value);
return $this;
} | Set an option for the Client instance.
@param array $value The access token
@return Client This object for method chaining
@since 1.0 | entailment |
public function filter(array $items): array
{
$filtered = [];
foreach ($items as $commandName => $commandDefinition) {
if ($commandName === static::EXCLUDED) {
continue;
}
$isExcluded = true;
if ($this->shouldCommandBeAdded($commandName, $commandDefinition)) {
$isExcluded = false;
}
$commandDefinition[static::EXCLUDED] = $isExcluded;
$filtered[$commandName] = $commandDefinition;
}
return $filtered;
} | @param array $items
@return array | entailment |
protected function shouldCommandBeAdded(string $commandName, array $commandDefinition): bool
{
$commandGroups = $this->getCommandGroups($commandDefinition);
if ($this->isCommandExcluded($commandName, $commandDefinition, $commandGroups)) {
return false;
}
if ($this->isGroupExcluded($commandGroups)) {
return false;
}
if ($this->runOnlySpecified()) {
return $this->isGroupRequested($commandGroups);
}
return true;
} | @param string $commandName
@param array $commandDefinition
@return bool | entailment |
protected function isCommandExcluded(string $commandName, array $commandDefinition, array $commandGroups): bool
{
if ($this->isExcludedByName($commandName)) {
return true;
}
if ($this->isExcludedByDefinition($commandDefinition) && !$this->shouldBeIncluded($commandName, $commandGroups)) {
return true;
}
return false;
} | @param string $commandName
@param array $commandDefinition
@param array $commandGroups
@return bool | entailment |
protected function isGroupExcluded(array $commandGroups): bool
{
return (count($this->excludedCommandsAndGroups) > 0 && (count(array_intersect($this->excludedCommandsAndGroups, $commandGroups)) > 0));
} | @param array $commandGroups
@return bool | entailment |
protected function isGroupRequested(array $commandGroups): bool
{
return (count($this->groupsToBeExecuted) > 0 && (count(array_intersect($this->groupsToBeExecuted, $commandGroups)) > 0));
} | @param array $commandGroups
@return bool | entailment |
protected function shouldBeIncluded(string $commandName, array $commandGroups): bool
{
if (count($this->includeExcluded) > 0) {
return (in_array($commandName, $this->includeExcluded) || count(array_intersect($this->includeExcluded, $commandGroups)) > 0);
}
return false;
} | @param string $commandName
@param array $commandGroups
@return bool | entailment |
public function findCommand(string $name): CommandInterface
{
[$section, $command] = explode('/', $name);
return $this->stage->getSection($section)->getCommand($command);
} | @param string $name
@return \Spryker\Install\Stage\Section\Command\CommandInterface | entailment |
public function run(
CommandLineArgumentContainer $commandLineArgumentContainer,
CommandLineOptionContainer $commandLineOptionContainer,
StyleInterface $output
) {
$configuration = $this->configurationBuilder->buildConfiguration(
$commandLineArgumentContainer,
$commandLineOptionContainer,
$output
);
$this->environmentHelper->putEnv('FORCE_COLOR_MODE', true);
$this->environmentHelper->putEnvs($configuration->getEnv());
$this->executeStage($configuration);
$output->endInstall($configuration->getStage());
} | @param \Spryker\Install\CommandLine\CommandLineArgumentContainer $commandLineArgumentContainer
@param \Spryker\Install\CommandLine\CommandLineOptionContainer $commandLineOptionContainer
@param \Spryker\Style\StyleInterface $output
@return void | entailment |
protected function executeStage(ConfigurationInterface $configuration)
{
$stage = $configuration->getStage();
$configuration->getOutput()->startInstall($stage);
foreach ($stage->getSections() as $section) {
if ($section->isExcluded()) {
continue;
}
$this->sectionRunner->run($section, $configuration);
}
} | @param \Spryker\Install\Configuration\ConfigurationInterface $configuration
@return void | entailment |
public function setCookie(array $options): self
{
if (isset($options['name']) && is_string($options['name'])) {
//正常COOKIE的设定
$this->cookies->add($options);
} else {
if (key($options) === 0) {
//数组COOKIE的设定
foreach ($options as $parent_name => $obj) {
$obj['name'] = $parent_name . '[' . $obj['name'] . ']';
$this->cookies->add($obj);
}
}
}
return $this;
} | Set Cookie to Cookies->$cookie list, cookie of the same name will be overwritten
@param $options
@return $this | entailment |
public function unsetCookie(string $name, string $path = '', string $domain = ''): self
{
$this->cookies->add([
'name' => $name,
'expires' => -1,
'path' => $path,
'domain' => $domain,
]);
return $this;
} | Unset cookie
@param string $name
@param string $path
@param string $domain
@return $this | entailment |
protected function addAccept(Builder $builder): void
{
$builder->macro('accept', function (Builder $builder) {
$builder->withNotAccepted();
return $builder->update(['is_accepted' => 1]);
});
} | Add the `accept` extension to the builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@return void | entailment |
protected function addWithoutNotAccepted(Builder $builder): void
{
$builder->macro('withoutNotAccepted', function (Builder $builder) {
return $builder->withoutGlobalScope($this)->where('is_accepted', 1);
});
} | Add the `withoutNotAccepted` extension to the builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@return void | entailment |
protected function addOnlyNotAccepted(Builder $builder): void
{
$builder->macro('onlyNotAccepted', function (Builder $builder) {
return $builder->withoutGlobalScope($this)->where('is_accepted', 0);
});
} | Add the `onlyNotAccepted` extension to the builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@return void | entailment |
protected function loadUri($uri)
{
try {
// Try to load the file through PHP's include().
// Make sure we don't accidentally create output.
ob_start();
$data = include($uri);
ob_end_clean();
return $data;
} catch (Exception $exception) {
throw new FailedToLoadConfigException(
sprintf(
_('Could not include PHP config file "%1$s". Reason: "%2$s".'),
$uri,
$exception->getMessage()
),
$exception->getCode(),
$exception
);
}
} | Load the contents of an resource identified by an URI.
@since 0.4.0
@param string $uri URI of the resource.
@return array|null Raw data loaded from the resource. Null if no data found.
@throws FailedToLoadConfigException If the resource could not be loaded. | entailment |
public function getKey($_)
{
$keys = $this->validateKeys(func_get_args());
$keys = array_reverse($keys);
$array = $this->getArrayCopy();
while (count($keys) > 0) {
$key = array_pop($keys);
$array = $array[$key];
}
return $array;
} | Get the value of a specific key.
To get a value several levels deep, add the keys for each level as a comma-separated list.
@since 0.1.0
@since 0.1.4 Accepts list of keys.
@param string|array $_ List of keys.
@return mixed
@throws KeyNotFoundException If an unknown key is requested. | entailment |
public function hasKey($_)
{
try {
$keys = array_reverse($this->getKeyArguments(func_get_args()));
$array = $this->getArrayCopy();
while (count($keys) > 0) {
$key = array_pop($keys);
if (! array_key_exists($key, $array)) {
return false;
}
$array = $array[$key];
}
} catch (Exception $exception) {
return false;
}
return true;
} | Check whether the Config has a specific key.
To check a value several levels deep, add the keys for each level as a comma-separated list.
@since 0.1.0
@since 0.1.4 Accepts list of keys.
@param string|array $_ List of keys.
@return bool | entailment |
public function getSubConfig($_)
{
$keys = $this->validateKeys(func_get_args());
$subConfig = clone $this;
$subConfig->reduceToSubKey($keys);
return $subConfig;
} | Get a new config at a specific sub-level.
@since 0.1.13
@param string|array $_ List of keys.
@return ConfigInterface
@throws KeyNotFoundException If an unknown key is requested. | entailment |
public function validateKeys($_)
{
$keys = $this->getKeyArguments(func_get_args());
if (! $this->hasKey($keys)) {
throw new KeyNotFoundException(
sprintf(
_('The configuration key %1$s does not exist.'),
implode('->', $keys)
)
);
}
return $keys;
} | Validate a set of keys to make sure they exist.
@since 0.1.13
@param string|array $_ List of keys.
@return array List of keys.
@throws KeyNotFoundException If an unknown key is requested. | entailment |
protected function getKeyArguments($arguments)
{
$keys = [];
foreach ($arguments as $argument) {
if (is_array($argument)) {
$keys = array_merge($keys, $this->getKeyArguments($argument));
}
if (is_string($argument)) {
$keys = array_merge($keys, $this->parseKeysString($argument));
}
}
return $keys;
} | Recursively extract the configuration key arguments from an arbitrary array.
@since 0.1.6
@param array $arguments Array as fetched through get_func_args().
@return array Array of strings. | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.