本文整理汇总了PHP中Webmozart\Assert\Assert::keyExists方法的典型用法代码示例。如果您正苦于以下问题:PHP Assert::keyExists方法的具体用法?PHP Assert::keyExists怎么用?PHP Assert::keyExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Webmozart\Assert\Assert
的用法示例。
在下文中一共展示了Assert::keyExists方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: calculate
/**
* {@inheritdoc}
*/
public function calculate(ProductVariantInterface $productVariant, array $context)
{
Assert::keyExists($context, 'channel');
$channelPricing = $productVariant->getChannelPricingForChannel($context['channel']);
Assert::notNull($channelPricing);
return $channelPricing->getPrice();
}
示例2: preSubmit
/**
* @param FormEvent $event
*/
public function preSubmit(FormEvent $event)
{
$attributeValue = $event->getData();
Assert::keyExists($attributeValue, 'attribute', 'Cannot create an attribute value form on pre submit event without an "attribute" key in data.');
$form = $event->getForm();
$attribute = $this->attributeRepository->find($attributeValue['attribute']);
$this->addValueField($form, $attribute);
}
示例3: addListenerToSuite
/**
* @param Suite $suite
* @param string $listenerName
* @param array $listenerAttributes
*/
private function addListenerToSuite(Suite $suite, $listenerName, array $listenerAttributes)
{
Assert::keyExists($listenerAttributes, 'options');
$listener = $this->listenerRegistry->getListener($listenerName);
$listenerOptions = $this->optionsProcessor->processConfiguration($listener, $listenerAttributes['options']);
$listenerPriority = isset($listenerAttributes['priority']) ? $listenerAttributes['priority'] : 0;
$suite->addListener($listener, $listenerOptions, $listenerPriority);
}
示例4: filter
/**
* {@inheritdoc}
*/
public function filter(array $items, array $configuration)
{
if (!$this->isConfigured($configuration)) {
return $items;
}
Assert::keyExists($configuration, 'channel');
$filteredItems = [];
foreach ($items as $item) {
if ($this->isItemVariantInPriceRange($item->getVariant(), $configuration)) {
$filteredItems[] = $item;
}
}
return $filteredItems;
}
示例5: getSubscribedEvents
/**
* {@inheritDoc}
*/
public function getSubscribedEvents()
{
return ['phpab.participation.variant_run' => function (array $options) {
Assert::notEmpty($options, 'Array passed to closure cannot be empty.');
Assert::keyExists($options, 1, 'Second parameter passed to closure must be instance of Bag.');
Assert::isInstanceOf($options[1], 'PhpAb\\Test\\Bag', 'Second parameter passed to closure must be instance of Bag.');
Assert::keyExists($options, 2, 'Third parameter passed to closure must be instance of VariantInterface.');
Assert::isInstanceOf($options[2], 'PhpAb\\Variant\\VariantInterface', 'Third parameter passed to closure must be instance of VariantInterface.');
/** @var TestInterface $test */
$test = $options[1]->getTest();
/** @var VariantInterface $chosenVariant */
$chosenVariant = $options[2];
// Call the add method
$this->addParticipation($test->getIdentifier(), $chosenVariant->getIdentifier());
}];
}
示例6: getEmailFromConfiguration
/**
* @param string $code
*
* @return EmailInterface
*/
private function getEmailFromConfiguration($code)
{
Assert::keyExists($this->configuration, $code, sprintf('Email with code "%s" does not exist!', $code));
/** @var EmailInterface $email */
$email = $this->emailFactory->createNew();
$configuration = $this->configuration[$code];
$email->setCode($code);
$email->setSubject($configuration['subject']);
$email->setTemplate($configuration['template']);
if (isset($configuration['enabled']) && false === $configuration['enabled']) {
$email->setEnabled(false);
}
if (isset($configuration['sender']['name'])) {
$email->setSenderName($configuration['sender']['name']);
}
if (isset($configuration['sender']['address'])) {
$email->setSenderAddress($configuration['sender']['address']);
}
return $email;
}
示例7: getSubscribedEvents
/**
* {@inheritDoc}
*/
public function getSubscribedEvents()
{
return ['phpab.participation.variant_run' => function ($options) {
Assert::notEmpty($options, 'Array passed to closure cannot be empty.');
Assert::keyExists($options, 1, 'Second parameter passed to closure must be instance of Bag.');
Assert::isInstanceOf($options[1], 'PhpAb\\Test\\Bag', 'Second parameter passed to closure must be instance of Bag.');
Assert::keyExists($options, 2, 'Third parameter passed to closure must be instance of VariantInterface.');
Assert::isInstanceOf($options[2], 'PhpAb\\Variant\\VariantInterface', 'Third parameter passed to closure must be instance of VariantInterface.');
/** @var TestInterface $test */
$test = $options[1]->getTest();
Assert::keyExists($test->getOptions(), static::EXPERIMENT_ID, 'A Google Analytics Experiment Id must be set as options.');
$experimentId = $test->getOptions()[static::EXPERIMENT_ID];
/** @var VariantInterface $chosenVariant */
$chosenVariant = $options[2];
$variants = $test->getVariants();
// Get the index number of the element
$chosenIndex = array_search($chosenVariant->getIdentifier(), array_keys($variants));
// Call the add method
$this->addParticipation($experimentId, $chosenIndex);
}];
}
示例8: isConfigurationValid
/**
* {@inheritdoc}
*/
protected function isConfigurationValid(array $configuration)
{
Assert::keyExists($configuration, 'amount');
Assert::integer($configuration['amount']);
}
示例9: assertConfiguration
/**
* @param array $configuration
* @param array $keys
*/
protected function assertConfiguration($configuration, $keys)
{
foreach ($keys as $key) {
Assert::keyExists($configuration, $key, 'Configuration key "%s" is required in action "' . $this->getName() . '"');
}
}
示例10: sortBy
/**
* {@inheritdoc}
*/
public function sortBy($fieldName)
{
$sortableHeaders = $this->tableAccessor->getSortableHeaders($this->getElement('table'));
Assert::keyExists($sortableHeaders, $fieldName, sprintf('Column "%s" is not sortable.', $fieldName));
$sortableHeaders[$fieldName]->find('css', 'a')->click();
}
示例11: getPrice
/**
* {@inheritdoc}
*/
public function getPrice(ProductVariantInterface $productVariant, array $context)
{
Assert::keyExists($context, 'channel');
return $this->productVariantPriceCalculator->calculate($productVariant, $context);
}
示例12: assertValidDca
/**
* Assert that an valid dca is loaded.
*
* @param string $name Dca name.
*
* @return void
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
protected function assertValidDca($name)
{
Assert::keyExists($GLOBALS['TL_DCA'], $name);
Assert::isArray($GLOBALS['TL_DCA'][$name]);
}