sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
public function createGroup(Api\GroupCreate $group) { $json = Serialize::group($group); $result = $this->_post($this->_url('/groups'), $json); return Deserialize::groupResponse($result); }
Creates the given group. @param Api\GroupCreate $group group description @return Api\GroupResult the created group
entailment
public function replaceGroupTags($groupId, array $tags) { $json = Serialize::tags($tags); $result = $this->_put($this->_groupUrl($groupId, '/tags'), $json); return Deserialize::tags($result); }
Replaces the tags of the given group. @param string $groupId identifier of the group @param string[] $tags the new set of group tags @return string[] the new group tags
entailment
public function replaceGroup($groupId, Api\GroupCreate $group) { $json = Serialize::group($group); $result = $this->_put($this->_groupUrl($groupId), $json); return Deserialize::groupResponse($result); }
Replaces the group with the given group identifier. @param string $groupId identifier of the group @param Api\GroupCreate $group new group description @return Api\GroupResult the group after replacement
entailment
public function updateGroup($groupId, Api\GroupUpdate $group) { $json = Serialize::groupUpdate($group); $result = $this->_post($this->_groupUrl($groupId), $json); return Deserialize::groupResponse($result); }
Updates the group with the given identifier. @param string $groupId identifier of the group @param Api\GroupUpdate $group the update description @return Api\GroupResult the updated batch
entailment
public function updateGroupTags( $groupId, array $tagsToAdd, array $tagsToRemove ) { $json = Serialize::tagsUpdate($tagsToAdd, $tagsToRemove); $result = $this->_post($this->_groupUrl($groupId, '/tags'), $json); return Deserialize::tags($result); }
Updates the tags of the given group. @param string $groupId group identifier @param string[] $tagsToAdd tags to add to group @param string[] $tagsToRemove tags to remove from group @return string[] the updated group tags
entailment
public function fetchGroup($groupId) { $result = $this->_get($this->_groupUrl($groupId)); return Deserialize::groupResponse($result); }
Fetches the group with the given group identifier. @param string $groupId group identifier @return Api\GroupResult the corresponding group
entailment
public function fetchGroups(GroupFilter $filter = null) { return new Api\Pages( function ($page) use ($filter) { $params = ["page=$page"]; if (!is_null($filter)) { if (null != $filter->getPageSize()) { array_push( $params, 'page_size=' . $filter->getPageSize() ); } if (null != $filter->getTags()) { $val = urlencode(join(',', $filter->getTags())); array_push($params, 'tags=' . $val); } } $q = join('&', $params); $result = $this->_get($this->_url('/groups?' . $q)); return Deserialize::groupsPage($result); } ); }
Fetch the groups matching the given filter. Note, calling this method does not actually cause any network traffic. Listing groups in XMS may return the result over multiple pages and this call therefore returns an object of the type {@link \Clx\Xms\Api\Pages}, which will fetch result pages as needed. @param GroupFilter|null $filter the group filter @return Api\Pages the result pages
entailment
public function fetchGroupMembers($groupId) { $result = $this->_get($this->_groupUrl($groupId, '/members')); return Deserialize::groupMembers($result); }
Fetches the members that belong to the given group. @param string $groupId the group identifier @return string[] a list of MSISDNs
entailment
public function fetchGroupTags($groupId) { $result = $this->_get($this->_groupUrl($groupId, '/tags')); return Deserialize::tags($result); }
Fetches the tags associated with the given group. @param string $groupId the group identifier @return string[] a list of tags
entailment
public function fetchInbound($inboundId) { $eiid = rawurlencode($inboundId); if (empty($eiid)) { throw new \InvalidArgumentException("Empty inbound ID given"); } $result = $this->_get($this->_url("/inbounds/$eiid")); return Deserialize::moSms($result); }
Fetches the inbound message with the given identifier. The returned message is either {@link Clx\Xms\Api\MoTextSms textual} or {@link Clx\Xms\Api\MoBinarySms binary}. @param string $inboundId message identifier @return Api\MoSms the fetched message
entailment
public function fetchInbounds(InboundsFilter $filter = null) { return new Api\Pages( function ($page) use ($filter) { $params = ["page=$page"]; if (!is_null($filter)) { if (null != $filter->getPageSize()) { array_push( $params, 'page_size=' . $filter->getPageSize() ); } if (null != $filter->getRecipients()) { $val = urlencode(join(',', $filter->getRecipients())); array_push($params, 'to=' . $val); } if (null != $filter->getStartDate()) { $val = $filter->getStartDate()->format('Y-m-d'); array_push($params, 'start_date=' . $val); } if (null != $filter->getEndDate()) { $val = $filter->getEndDate()->format('Y-m-d'); array_push($params, 'end_date=' . $val); } } $q = join('&', $params); $result = $this->_get($this->_url('/inbounds?' . $q)); return Deserialize::inboundsPage($result); } ); }
Fetch inbound messages matching the given filter. Note, calling this method does not actually cause any network traffic. Listing inbound messages in XMS may return the result over multiple pages and this call therefore returns an object of the type {@link \Clx\Xms\Api\Pages}, which will fetch result pages as needed. @param InboundsFilter|null $filter the inbound message filter @return Api\Pages the result pages
entailment
public function buildCommand(string $name, array $definition): CommandInterface { $command = new Command($name); $command->setExecutable($definition[static::CONFIG_COMMAND]); $this->setExcluded($command, $definition); $this->setGroups($command, $definition); $this->setEnv($command, $definition); $this->setIsStoreAware($command, $definition); $this->setStores($command, $definition); $this->addCommandConditions($command, $definition); $this->setPreCommand($command, $definition); $this->setPostCommand($command, $definition); $this->setBreakOnFailure($command, $definition); $this->setTimeout($command, $definition); return $command; }
@param string $name @param array $definition @return \Spryker\Install\Stage\Section\Command\CommandInterface
entailment
protected function setExcluded(CommandInterface $command, array $definition) { if (isset($definition[static::CONFIG_EXCLUDED]) && $definition[static::CONFIG_EXCLUDED]) { $command->markAsExcluded(); } }
@param \Spryker\Install\Stage\Section\Command\CommandInterface $command @param array $definition @return void
entailment
protected function setGroups(CommandInterface $command, array $definition) { if (isset($definition[static::CONFIG_GROUPS])) { $command->setGroups($definition[static::CONFIG_GROUPS]); } }
@param \Spryker\Install\Stage\Section\Command\CommandInterface $command @param array $definition @return void
entailment
protected function setEnv(CommandInterface $command, array $definition) { if (isset($definition[static::CONFIG_ENV])) { $command->setEnv($definition[static::CONFIG_ENV]); } }
@param \Spryker\Install\Stage\Section\Command\CommandInterface $command @param array $definition @return void
entailment
protected function setIsStoreAware(CommandInterface $command, array $definition) { if (isset($definition[static::CONFIG_STORES])) { $command->setIsStoreAware($this->getIsStoreAware($definition)); } }
@param \Spryker\Install\Stage\Section\Command\CommandInterface $command @param array $definition @return void
entailment
protected function setStores(CommandInterface $command, array $definition) { if (isset($definition[static::CONFIG_STORES]) && is_array($definition[static::CONFIG_STORES])) { $command->setStores($definition[static::CONFIG_STORES]); } }
@param \Spryker\Install\Stage\Section\Command\CommandInterface $command @param array $definition @return void
entailment
protected function addCommandConditions(CommandInterface $command, array $definition) { if (!isset($definition[static::CONFIG_CONDITIONS])) { return; } foreach ($definition[static::CONFIG_CONDITIONS] as $condition) { $condition = $this->conditionFactory->createCondition($condition); $command->addCondition($condition); } }
@param \Spryker\Install\Stage\Section\Command\CommandInterface $command @param array $definition @return void
entailment
protected function setPreCommand(CommandInterface $command, array $definition) { if (isset($definition[static::CONFIG_PRE_COMMAND])) { $command->setPreCommand($definition[static::CONFIG_PRE_COMMAND]); } }
@param \Spryker\Install\Stage\Section\Command\CommandInterface $command @param array $definition @return void
entailment
protected function setPostCommand(CommandInterface $command, array $definition) { if (isset($definition[static::CONFIG_POST_COMMAND])) { $command->setPostCommand($definition[static::CONFIG_POST_COMMAND]); } }
@param \Spryker\Install\Stage\Section\Command\CommandInterface $command @param array $definition @return void
entailment
protected function setBreakOnFailure(CommandInterface $command, array $definition) { if (isset($definition[static::CONFIG_BREAK_ON_FAILURE])) { $command->setBreakOnFailure($definition[static::CONFIG_BREAK_ON_FAILURE]); } }
@param \Spryker\Install\Stage\Section\Command\CommandInterface $command @param array $definition @return void
entailment
protected function setTimeout(CommandInterface $command, array $definition) { if (isset($definition[static::CONFIG_TIMEOUT])) { $command->setTimeout($definition[static::CONFIG_TIMEOUT]); } }
@param \Spryker\Install\Stage\Section\Command\CommandInterface $command @param array $definition @return void
entailment
protected function parseSchema($data, $key) { $this->parseDefined($key); if (array_key_exists(self::REQUIRED_KEY, $data)) { $this->parseRequired( $key, $data[self::REQUIRED_KEY] ); } if (array_key_exists(self::DEFAULT_VALUE, $data)) { $this->parseDefault( $key, $data[self::DEFAULT_VALUE] ); } }
Parse a single provided schema entry. @since 0.1.0 @param mixed $data The data associated with the key. @param string $key The key of the schema data.
entailment
protected function addDraft(Builder $builder): void { $builder->macro('draft', function (Builder $builder) { return $builder->update(['is_drafted' => 1]); }); }
Add the `draft` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addWithoutDrafted(Builder $builder): void { $builder->macro('withoutDrafted', function (Builder $builder) { return $builder->withoutGlobalScope($this)->where('is_drafted', 0); }); }
Add the `withoutDrafted` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addOnlyDrafted(Builder $builder): void { $builder->macro('onlyDrafted', function (Builder $builder) { return $builder->withoutGlobalScope($this)->where('is_drafted', 1); }); }
Add the `onlyDrafted` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addInvite(Builder $builder): void { $builder->macro('invite', function (Builder $builder) { $builder->withNotInvited(); return $builder->update(['invited_at' => Date::now()]); }); }
Add the `invite` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addWithNotInvited(Builder $builder): void { $builder->macro('withNotInvited', function (Builder $builder) { return $builder->withoutGlobalScope($this); }); }
Add the `withNotInvited` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addWithoutNotInvited(Builder $builder): void { $builder->macro('withoutNotInvited', function (Builder $builder) { return $builder->withoutGlobalScope($this)->whereNotNull('invited_at'); }); }
Add the `withoutNotInvited` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addOnlyNotInvited(Builder $builder): void { $builder->macro('onlyNotInvited', function (Builder $builder) { return $builder->withoutGlobalScope($this)->whereNull('invited_at'); }); }
Add the `onlyNotInvited` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
public function addSection(SectionInterface $section): StageInterface { if (isset($this->sections[$section->getName()])) { throw new SectionExistsException(sprintf('Section with name "%s" already exists.', $section->getName())); } $this->sections[$section->getName()] = $section; return $this; }
@param \Spryker\Install\Stage\Section\SectionInterface $section @throws \Spryker\Install\Stage\Section\Exception\SectionExistsException @return \Spryker\Install\Stage\StageInterface
entailment
public function getSection(string $sectionName): SectionInterface { if (!isset($this->sections[$sectionName])) { throw new SectionNotFoundException(sprintf('Section "%s" not found in "%s" stage', $sectionName, $this->name)); } return $this->sections[$sectionName]; }
@param string $sectionName @throws \Spryker\Install\Stage\Section\Exception\SectionNotFoundException @return \Spryker\Install\Stage\Section\SectionInterface
entailment
public function start($object): TimerInterface { $this->timer[spl_object_hash($object)] = microtime(true); return $this; }
@param object $object @return \Spryker\Install\Timer\TimerInterface
entailment
public function end($object): float { $start = $this->timer[spl_object_hash($object)]; $runtime = microtime(true) - $start; return round($runtime, 2); }
@param object $object @return float
entailment
protected function addArchive(Builder $builder): void { $builder->macro('archive', function (Builder $builder) { return $builder->update(['is_archived' => 1]); }); }
Add the `archive` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addWithoutArchived(Builder $builder): void { $builder->macro('withoutArchived', function (Builder $builder) { return $builder->withoutGlobalScope($this)->where('is_archived', 0); }); }
Add the `withoutArchived` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addOnlyArchived(Builder $builder): void { $builder->macro('onlyArchived', function (Builder $builder) { return $builder->withoutGlobalScope($this)->where('is_archived', 1); }); }
Add the `onlyArchived` 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(['is_ended' => 1]); }); }
Add the `end` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addWithEnded(Builder $builder): void { $builder->macro('withEnded', function (Builder $builder) { return $builder->withoutGlobalScope($this); }); }
Add the `withEnded` 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)->where('is_ended', 0); }); }
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)->where('is_ended', 1); }); }
Add the `onlyEnded` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
public function apply(Builder $builder, Model $model): void { if (method_exists($model, 'shouldApplyVerifiedAtScope') && $model->shouldApplyVerifiedAtScope()) { $builder->whereNotNull('verified_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 addVerify(Builder $builder): void { $builder->macro('verify', function (Builder $builder) { $builder->withNotVerified(); return $builder->update(['verified_at' => Date::now()]); }); }
Add the `verify` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addUndoVerify(Builder $builder): void { $builder->macro('undoVerify', function (Builder $builder) { return $builder->update(['verified_at' => null]); }); }
Add the `undoVerify` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addWithNotVerified(Builder $builder): void { $builder->macro('withNotVerified', function (Builder $builder) { return $builder->withoutGlobalScope($this); }); }
Add the `withNotVerified` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addWithoutNotVerified(Builder $builder): void { $builder->macro('withoutNotVerified', function (Builder $builder) { return $builder->withoutGlobalScope($this)->whereNotNull('verified_at'); }); }
Add the `withoutNotVerified` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addOnlyNotVerified(Builder $builder): void { $builder->macro('onlyNotVerified', function (Builder $builder) { return $builder->withoutGlobalScope($this)->whereNull('verified_at'); }); }
Add the `onlyNotVerified` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
public function buildConfiguration( CommandLineArgumentContainer $commandLineArgumentContainer, CommandLineOptionContainer $commandLineOptionContainer, StyleInterface $output ): ConfigurationInterface { $this->commandLineArgumentContainer = $commandLineArgumentContainer; $this->commandLineOptionContainer = $commandLineOptionContainer; $this->output = $output; $this->configuration->setOutput($output); $this->configuration->setIsDryRun($commandLineOptionContainer->isDryRun()); $this->configuration->setIsDebugMode($commandLineOptionContainer->isDebugMode()); $this->configuration->setAskBeforeContinueAfterException($commandLineOptionContainer->askBeforeContinueOnException()); $configuration = $this->configurationLoader->loadConfiguration($commandLineOptionContainer->getRecipe()); $this->setEnv($configuration); $this->setStores($configuration); $this->setCommandTimeout($configuration); $this->setExecutableStores(); $this->addStageToConfiguration($commandLineOptionContainer->getRecipe(), $configuration['sections']); return $this->configuration; }
@param \Spryker\Install\CommandLine\CommandLineArgumentContainer $commandLineArgumentContainer @param \Spryker\Install\CommandLine\CommandLineOptionContainer $commandLineOptionContainer @param \Spryker\Style\StyleInterface $output @return \Spryker\Install\Configuration\ConfigurationInterface
entailment
protected function setEnv(array $configuration) { if (isset($configuration[static::CONFIG_ENV])) { $this->configuration->setEnv($configuration[static::CONFIG_ENV]); } }
@param array $configuration @return void
entailment
protected function setStores(array $configuration) { if (isset($configuration[static::CONFIG_STORES])) { $this->configuration->setStores($configuration[static::CONFIG_STORES]); } }
@param array $configuration @return void
entailment
protected function setCommandTimeout(array $configuration) { if (isset($configuration[static::CONFIG_COMMAND_TIMEOUT])) { $this->configuration->setCommandTimeout($configuration[static::CONFIG_COMMAND_TIMEOUT]); } }
@param array $configuration @return void
entailment
protected function addStageToConfiguration(string $stageName, array $sections) { $stage = new Stage($stageName); foreach ($this->filterSections($sections) as $sectionName => $commands) { $stage->addSection($this->buildSection($sectionName, $commands)); } $this->configuration->setStage($stage); }
@param string $stageName @param array $sections @return void
entailment
protected function buildSection($sectionName, array $sectionDefinition): SectionInterface { $section = $this->sectionBuilder->buildSection($sectionName, $sectionDefinition); foreach ($this->filterCommands($sectionDefinition) as $commandName => $commandDefinition) { $section->addCommand($this->commandBuilder->buildCommand($commandName, $commandDefinition)); } return $section; }
@param string $sectionName @param array $sectionDefinition @return \Spryker\Install\Stage\Section\SectionInterface
entailment
protected function addPublish(Builder $builder): void { $builder->macro('publish', function (Builder $builder) { $builder->withNotPublished(); return $builder->update(['is_published' => 1]); }); }
Add the `publish` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addUndoPublish(Builder $builder): void { $builder->macro('undoPublish', function (Builder $builder) { return $builder->update(['is_published' => 0]); }); }
Add the `undoPublish` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addWithNotPublished(Builder $builder): void { $builder->macro('withNotPublished', function (Builder $builder) { return $builder->withoutGlobalScope($this); }); }
Add the `withNotPublished` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addWithoutNotPublished(Builder $builder): void { $builder->macro('withoutNotPublished', function (Builder $builder) { return $builder->withoutGlobalScope($this)->where('is_published', 1); }); }
Add the `withoutNotPublished` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addOnlyNotPublished(Builder $builder): void { $builder->macro('onlyNotPublished', function (Builder $builder) { return $builder->withoutGlobalScope($this)->where('is_published', 0); }); }
Add the `onlyNotPublished` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
public function filter(array $items): array { foreach ($this->filter as $filter) { $items = $filter->filter($items); } return $items; }
@param array $items @return array
entailment
protected function addInvite(Builder $builder): void { $builder->macro('invite', function (Builder $builder) { $builder->withNotInvited(); return $builder->update(['is_invited' => 1]); }); }
Add the `invite` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addUndoInvite(Builder $builder): void { $builder->macro('undoInvite', function (Builder $builder) { return $builder->update(['is_invited' => 0]); }); }
Add the `undoInvite` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addWithoutNotInvited(Builder $builder): void { $builder->macro('withoutNotInvited', function (Builder $builder) { return $builder->withoutGlobalScope($this)->where('is_invited', 1); }); }
Add the `withoutNotInvited` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addOnlyNotInvited(Builder $builder): void { $builder->macro('onlyNotInvited', function (Builder $builder) { return $builder->withoutGlobalScope($this)->where('is_invited', 0); }); }
Add the `onlyNotInvited` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
public function putEnvs(array $env) { foreach ($env as $key => $value) { $this->putEnv($key, $value); } }
@param array $env @return void
entailment
public function choice($question, array $choices, $default = null) { if ($default) { $values = array_flip($choices); $default = $values[$default]; } $question = new ChoiceQuestion($question, $choices, $default); $question->setMultiselect(true); return $this->askQuestion($question); }
@param string $question @param array $choices @param string|int|null $default @return bool|mixed|string|null
entailment
protected function addVerify(Builder $builder): void { $builder->macro('verify', function (Builder $builder) { $builder->withNotVerified(); return $builder->update(['is_verified' => 1]); }); }
Add the `verify` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addWithoutNotVerified(Builder $builder): void { $builder->macro('withoutNotVerified', function (Builder $builder) { return $builder->withoutGlobalScope($this)->where('is_verified', 1); }); }
Add the `withoutNotVerified` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addOnlyNotVerified(Builder $builder): void { $builder->macro('onlyNotVerified', function (Builder $builder) { return $builder->withoutGlobalScope($this)->where('is_verified', 0); }); }
Add the `onlyNotVerified` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addUndoExpire(Builder $builder): void { $builder->macro('undoExpire', function (Builder $builder) { $builder->withExpired(); return $builder->update(['is_expired' => 0]); }); }
Add the `undoExpire` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addExpire(Builder $builder): void { $builder->macro('expire', function (Builder $builder) { return $builder->update(['is_expired' => 1]); }); }
Add the `expire` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addWithoutExpired(Builder $builder): void { $builder->macro('withoutExpired', function (Builder $builder) { return $builder->withoutGlobalScope($this)->where('is_expired', 0); }); }
Add the `withoutExpired` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addOnlyExpired(Builder $builder): void { $builder->macro('onlyExpired', function (Builder $builder) { return $builder->withoutGlobalScope($this)->where('is_expired', 1); }); }
Add the `onlyExpired` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
public static function fromRegistry(ManagerRegistry $registry) { $drivers = array(); foreach ($registry->getManagers() as $manager) { $drivers[] = self::fromManager($manager); } return new DriverChain($drivers); }
Create a driver from a Doctrine registry @param ManagerRegistry $registry @return DriverInterface
entailment
public static function fromMetadataDriver(MappingDriver $omDriver) { if ($omDriver instanceof MappingDriverChain) { $drivers = array(); foreach ($omDriver->getDrivers() as $nestedOmDriver) { $drivers[] = self::fromMetadataDriver($nestedOmDriver); } return new DriverChain($drivers); } if ($omDriver instanceof DoctrineAnnotationDriver) { return new AnnotationDriver($omDriver->getReader()); } if ($omDriver instanceof DoctrineFileDriver) { $reflClass = new \ReflectionClass($omDriver); $driverName = $reflClass->getShortName(); if ($omDriver instanceof SimplifiedYamlDriver || $omDriver instanceof SimplifiedXmlDriver) { $driverName = str_replace('Simplified', '', $driverName); } $class = 'Prezent\\Doctrine\\Translatable\\Mapping\\Driver\\' . $driverName; if (class_exists($class)) { return new $class($omDriver->getLocator()); } } throw new \InvalidArgumentException('Cannot adapt Doctrine driver of class ' . get_class($omDriver)); }
Create a driver from a Doctrine metadata driver @param MappingDriver $omDriver @return DriverInterface
entailment
public function validate() { if (!$this->translations) { throw new MappingException(sprintf('No translations specified for %s', $this->name)); } if (!$this->targetEntity) { throw new MappingException(sprintf('No translations targetEntity specified for %s', $this->name)); } }
Validate the metadata @return void
entailment
public function merge(MergeableInterface $object) { if (!$object instanceof self) { throw new \InvalidArgumentException(sprintf('$object must be an instance of %s.', __CLASS__)); } parent::merge($object); if ($object->targetEntity) { $this->targetEntity = $object->targetEntity; } if ($object->currentLocale) { $this->currentLocale = $object->currentLocale; } if ($object->fallbackLocale) { $this->fallbackLocale = $object->fallbackLocale; } if ($object->translations) { $this->translations = $object->translations; } }
{@inheritdoc}
entailment
public function serialize() { return serialize(array( $this->targetEntity, $this->currentLocale ? $this->currentLocale->name : null, $this->fallbackLocale ? $this->fallbackLocale->name : null, $this->translations ? $this->translations->name : null, parent::serialize(), )); }
{@inheritdoc}
entailment
public function unserialize($str) { list ( $this->targetEntity, $currentLocale, $fallbackLocale, $translations, $parent ) = unserialize($str); parent::unserialize($parent); if ($currentLocale) { $this->currentLocale = $this->propertyMetadata[$currentLocale]; } if ($fallbackLocale) { $this->fallbackLocale = $this->propertyMetadata[$fallbackLocale]; } if ($translations) { $this->translations = $this->propertyMetadata[$translations]; } }
{@inheritdoc}
entailment
protected function loadTranslatableMetadata($className, $config) { if (!$config) { return; } $xml = new SimpleXMLElement($config); $xml->registerXPathNamespace('prezent', 'prezent'); $nodeList = $xml->xpath('//prezent:translatable'); if (0 == count($nodeList)) { return; } if (1 < count($nodeList)) { throw new \Exception("Configuration defined twice"); } $node = $nodeList[0]; $classMetadata = new TranslatableMetadata($className); $translatableField = (string)$node['field']; $propertyMetadata = new PropertyMetadata( $className, // defaults to translatable !empty($translatableField) ? $translatableField : 'translations' ); // default targetEntity $targetEntity = $className . 'Translation'; $translatableTargetEntity = (string)$node['target-entity']; $classMetadata->targetEntity = !empty($translatableTargetEntity) ? $translatableTargetEntity : $targetEntity; $classMetadata->translations = $propertyMetadata; $classMetadata->addPropertyMetadata($propertyMetadata); $currentLocale = (string)$node['current-locale']; if (!empty($currentLocale)) { $propertyMetadata = new PropertyMetadata($className, $currentLocale); $classMetadata->currentLocale = $propertyMetadata; $classMetadata->addPropertyMetadata($propertyMetadata); } $fallbackLocale = (string)$node['fallback-locale']; if (!empty($fallbackLocale)) { $propertyMetadata = new PropertyMetadata($className, $fallbackLocale); $classMetadata->fallbackLocale = $propertyMetadata; $classMetadata->addPropertyMetadata($propertyMetadata); } return $classMetadata; }
Load metadata for a translatable class @param string $className @param mixed $config @throws \Exception @return TranslatableMetadata|null
entailment
protected function loadTranslationMetadata($className, $config) { if (!$config) { return; } $xml = new SimpleXMLElement($config); $xml->registerXPathNamespace('prezent', 'prezent'); $nodeList = $xml->xpath('//prezent:translatable'); if (0 == count($nodeList)) { return; } if (1 < count($nodeList)) { throw new \Exception("Configuration defined twice"); } $nodeTranslatable = $nodeList[0]; $translatableField = (string)$nodeTranslatable['field']; $translatableTargetEntity = (string)$nodeTranslatable['target-entity']; $locale = (string)(string)$nodeTranslatable['locale']; $classMetadata = new TranslationMetadata($className); $propertyMetadata = new PropertyMetadata( $className, // defaults to translatable !empty($translatableField) ? $translatableField : 'translatable' ); $targetEntity = 'Translation' === substr($className, -11) ? substr($className, 0, -11) : null; $classMetadata->targetEntity = !empty($translatableTargetEntity) ? $translatableTargetEntity : $targetEntity; $classMetadata->translatable = $propertyMetadata; $classMetadata->addPropertyMetadata($propertyMetadata); if ($locale) { $propertyMetadata = new PropertyMetadata($className, $locale); $classMetadata->locale = $propertyMetadata; $classMetadata->addPropertyMetadata($propertyMetadata); } // Set to default if no locale property has been set if (!$classMetadata->locale) { $propertyMetadata = new PropertyMetadata($className, 'locale'); $classMetadata->locale = $propertyMetadata; $classMetadata->addPropertyMetadata($propertyMetadata); } return $classMetadata; }
Load metadata for a translation class @param string $className @param mixed $config @throws \Exception @return TranslationMetadata|null
entailment
private function loadTranslatableMetadata(\ReflectionClass $class) { $classMetadata = new TranslatableMetadata($class->name); foreach ($class->getProperties() as $property) { if ($property->class !== $class->name) { continue; } $propertyMetadata = new PropertyMetadata($class->name, $property->getName()); if ($this->reader->getPropertyAnnotation($property, 'Prezent\\Doctrine\\Translatable\\Annotation\\CurrentLocale')) { $classMetadata->currentLocale = $propertyMetadata; $classMetadata->addPropertyMetadata($propertyMetadata); } if ($this->reader->getPropertyAnnotation($property, 'Prezent\\Doctrine\\Translatable\\Annotation\\FallbackLocale')) { $classMetadata->fallbackLocale = $propertyMetadata; $classMetadata->addPropertyMetadata($propertyMetadata); } if ($annot = $this->reader->getPropertyAnnotation($property, 'Prezent\\Doctrine\\Translatable\\Annotation\\Translations')) { $classMetadata->targetEntity = $annot->targetEntity; $classMetadata->translations = $propertyMetadata; $classMetadata->addPropertyMetadata($propertyMetadata); } } return $classMetadata; }
Load metadata for a translatable class @param \ReflectionClass $class @return TranslatableMetadata
entailment
private function loadTranslationMetadata(\ReflectionClass $class) { $classMetadata = new TranslationMetadata($class->name); foreach ($class->getProperties() as $property) { if ($property->class !== $class->name) { continue; } $propertyMetadata = new PropertyMetadata($class->name, $property->getName()); if ($annot = $this->reader->getPropertyAnnotation($property, 'Prezent\\Doctrine\\Translatable\\Annotation\\Translatable')) { $classMetadata->targetEntity = $annot->targetEntity; $classMetadata->translatable = $propertyMetadata; $classMetadata->addPropertyMetadata($propertyMetadata); } if ($this->reader->getPropertyAnnotation($property, 'Prezent\\Doctrine\\Translatable\\Annotation\\Locale')) { $classMetadata->locale = $propertyMetadata; $classMetadata->addPropertyMetadata($propertyMetadata); } } return $classMetadata; }
Load metadata for a translation class @param \ReflectionClass $class @return TranslationMetadata
entailment
protected function addKeep(Builder $builder): void { $builder->macro('keep', function (Builder $builder) { $builder->withNotKept(); return $builder->update(['is_kept' => 1]); }); }
Add the `keep` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addUndoKeep(Builder $builder): void { $builder->macro('undoKeep', function (Builder $builder) { return $builder->update(['is_kept' => 0]); }); }
Add the `undoKeep` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addWithNotKept(Builder $builder): void { $builder->macro('withNotKept', function (Builder $builder) { return $builder->withoutGlobalScope($this); }); }
Add the `withNotKept` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addWithoutNotKept(Builder $builder): void { $builder->macro('withoutNotKept', function (Builder $builder) { return $builder->withoutGlobalScope($this)->where('is_kept', 1); }); }
Add the `withoutNotKept` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addOnlyNotKept(Builder $builder): void { $builder->macro('onlyNotKept', function (Builder $builder) { return $builder->withoutGlobalScope($this)->where('is_kept', 0); }); }
Add the `onlyNotKept` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
public function getDefinedOptions() { if (! $this->defined) { return null; } if ($this->defined instanceof ConfigInterface) { return $this->defined->getArrayCopy(); } return (array)$this->defined; }
Get the set of defined options. @since 0.1.0 @return array|null
entailment
public function getDefaultOptions() { if (! $this->defaults) { return null; } if ($this->defaults instanceof ConfigInterface) { return $this->defaults->getArrayCopy(); } return (array)$this->defaults; }
Get the set of default options. @since 0.1.0 @return array|null
entailment
public function getRequiredOptions() { if (! $this->required) { return null; } if ($this->required instanceof ConfigInterface) { return $this->required->getArrayCopy(); } return (array)$this->required; }
Get the set of required options. @since 0.1.0 @return array|null
entailment
public function filter(array $items): array { if (isset($items[$this->keyToUnset])) { unset($items[$this->keyToUnset]); } return $items; }
@param array $items @return array
entailment
public function match(array $exitCodes): bool { if (!isset($exitCodes[$this->command]) || $exitCodes[$this->command] !== $this->exitCode) { return false; } return true; }
@param int[] $exitCodes @return bool
entailment
protected function addPublish(Builder $builder): void { $builder->macro('publish', function (Builder $builder) { $builder->withNotPublished(); return $builder->update(['published_at' => Date::now()]); }); }
Add the `publish` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addWithoutNotPublished(Builder $builder): void { $builder->macro('withoutNotPublished', function (Builder $builder) { return $builder->withoutGlobalScope($this)->whereNotNull('published_at'); }); }
Add the `withoutNotPublished` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
protected function addOnlyNotPublished(Builder $builder): void { $builder->macro('onlyNotPublished', function (Builder $builder) { return $builder->withoutGlobalScope($this)->whereNull('published_at'); }); }
Add the `onlyNotPublished` extension to the builder. @param \Illuminate\Database\Eloquent\Builder $builder @return void
entailment
public function filter(array $items): array { $filtered = []; foreach ($items as $sectionName => $sectionDefinition) { $isExcluded = true; if ($this->shouldSectionBeAdded($sectionName, $sectionDefinition)) { $isExcluded = false; } $sectionDefinition[static::EXCLUDED] = $isExcluded; $filtered[$sectionName] = $sectionDefinition; } return $filtered; }
@param array $items @return array
entailment
protected function shouldSectionBeAdded(string $sectionName, array $sectionDefinition): bool { if ($this->containsRequestedGroup($sectionDefinition)) { return true; } if ($this->onlyRunSelected()) { return $this->isSectionRequested($sectionName); } if (!$this->isSectionExcluded($sectionName, $sectionDefinition)) { return true; } return false; }
@param string $sectionName @param array $sectionDefinition @return bool
entailment
protected function containsRequestedGroup(array $sectionDefinition): bool { foreach ($this->filterForRequestedGroupCheck($sectionDefinition) as $commandDefinition) { if (array_intersect($commandDefinition['groups'], $this->groupsToBeExecuted)) { return true; } } return false; }
@param array $sectionDefinition @return bool
entailment
protected function filterForRequestedGroupCheck(array $sectionDefinition): array { $filtered = []; foreach ($sectionDefinition as $commandName => $commandDefinition) { if ($commandName !== static::EXCLUDED && isset($commandDefinition['groups'])) { $filtered[$commandName] = $commandDefinition; } } return $filtered; }
@param array $sectionDefinition @return array
entailment
protected function isSectionExcluded(string $sectionName, array $sectionDefinition): bool { if ($this->isExcludedByName($sectionName)) { return true; } if ($this->isExcludedByDefinition($sectionDefinition) && !$this->shouldBeIncluded($sectionName)) { return true; } return false; }
@param string $sectionName @param array $sectionDefinition @return bool
entailment