本文整理汇总了PHP中Pim\Bundle\CatalogBundle\Exception\InvalidArgumentException类的典型用法代码示例。如果您正苦于以下问题:PHP InvalidArgumentException类的具体用法?PHP InvalidArgumentException怎么用?PHP InvalidArgumentException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InvalidArgumentException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addAttributeFilter
/**
* {@inheritdoc}
*/
public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
{
try {
$options = $this->resolver->resolve($options);
} catch (\Exception $e) {
throw InvalidArgumentException::expectedFromPreviousException($e, $attribute->getCode(), 'filter', 'options');
}
$this->checkLocaleAndScope($attribute, $locale, $scope, 'options');
if ($operator != Operators::IS_EMPTY) {
$this->checkValue($options['field'], $value);
}
$joinAlias = $this->getUniqueAlias('filter' . $attribute->getCode());
$joinAliasOpt = $this->getUniqueAlias('filterO' . $attribute->getCode());
$backendField = sprintf('%s.%s', $joinAliasOpt, 'id');
if (Operators::IS_EMPTY === $operator) {
$this->qb->leftJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope));
$this->qb->leftJoin($joinAlias . '.' . $attribute->getBackendType(), $joinAliasOpt)->andWhere($this->qb->expr()->isNull($backendField));
} else {
if (FieldFilterHelper::getProperty($options['field']) === FieldFilterHelper::CODE_PROPERTY) {
$value = $this->objectIdResolver->getIdsFromCodes('option', $value);
}
$this->qb->innerJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope))->innerJoin($joinAlias . '.' . $attribute->getBackendType(), $joinAliasOpt, 'WITH', $this->qb->expr()->in($backendField, $value));
}
return $this;
}
示例2:
function it_throws_an_error_if_an_option_code_is_unknown_on_attribute_data_set($attrOptionRepository, ProductInterface $product, AttributeInterface $attribute)
{
$attribute->getCode()->willReturn('attributeCode');
$data = ['unknown code'];
$attrOptionRepository->findOneBy(['code' => 'unknown code', 'attribute' => $attribute])->shouldBeCalledTimes(1)->willReturn(null);
$this->shouldThrow(InvalidArgumentException::arrayInvalidKey('attributeCode', 'code', 'The option does not exist', 'adder', 'multi select', 'unknown code'))->during('addAttributeData', [$product, $attribute, $data, ['locale' => 'fr_FR', 'scope' => 'mobile']]);
}
示例3:
function it_throws_an_error_if_an_option_code_is_unknown($attrOptionRepository, AttributeInterface $attribute)
{
$attribute->getCode()->willReturn('attributeCode');
$data = ['unknown code'];
$attrOptionRepository->findOneBy(['code' => 'unknown code', 'attribute' => $attribute])->shouldBeCalledTimes(1)->willReturn(null);
$this->shouldThrow(InvalidArgumentException::arrayInvalidKey('attributeCode', 'code', 'The option does not exist', 'setter', 'multi select', 'unknown code'))->during('setValue', [[], $attribute, $data, 'fr_FR', 'mobile']);
}
示例4:
function it_fails_if_the_group_code_is_not_found($groupRepository, ProductInterface $product, GroupInterface $pack, GroupTypeInterface $nonVariantType)
{
$groupRepository->findOneByIdentifier('not valid code')->willReturn(null);
$pack->getType()->willReturn($nonVariantType);
$nonVariantType->isVariant()->willReturn(false);
$this->shouldThrow(InvalidArgumentException::expected('variant_group', 'existing variant group code', 'setter', 'variant_group', 'not valid code'))->during('setFieldData', [$product, 'variant_group', 'not valid code']);
}
示例5:
function it_throws_an_error_if_data_value_does_not_contain_valid_currency($currencyManager, AttributeInterface $attribute)
{
$attribute->getCode()->willReturn('attributeCode');
$currencyManager->getActiveCodes()->willReturn(['EUR', 'USD']);
$data = [['data' => 123, 'currency' => 'invalid currency']];
$this->shouldThrow(InvalidArgumentException::arrayInvalidKey('attributeCode', 'currency', 'The currency does not exist', 'setter', 'prices collection', 'invalid currency'))->during('setValue', [[], $attribute, $data, 'fr_FR', 'mobile']);
}
示例6: addAttributeFilter
/**
* {@inheritdoc}
*/
public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
{
try {
$options = $this->resolver->resolve($options);
} catch (\Exception $e) {
throw InvalidArgumentException::expectedFromPreviousException($e, $attribute->getCode(), 'filter', 'option');
}
$this->checkLocaleAndScope($attribute, $locale, $scope, 'option');
$field = $options['field'];
if (Operators::IS_EMPTY !== $operator) {
$this->checkValue($field, $value);
}
$joinAlias = $this->getUniqueAlias('filter' . $attribute->getCode(), true);
// prepare join value condition
$optionAlias = $joinAlias . '.option';
if (Operators::IS_EMPTY === $operator) {
$this->qb->leftJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope));
$this->qb->andWhere($this->qb->expr()->isNull($optionAlias));
} else {
// inner join to value
$condition = $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope);
if (FieldFilterHelper::getProperty($field) === FieldFilterHelper::CODE_PROPERTY) {
$value = $this->objectIdResolver->getIdsFromCodes('option', $value);
}
$condition .= ' AND ( ' . $this->qb->expr()->in($optionAlias, $value) . ' ) ';
$this->qb->innerJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $condition);
}
return $this;
}
示例7:
function it_throws_an_exception_when_unit_families_are_not_consistent($attrValidatorHelper, AttributeInterface $fromAttribute, AttributeInterface $toAttribute)
{
$e = new \LogicException('Metric families are not the same for attributes: "fromCode" and "toCode".');
$fromAttribute->getCode()->willReturn('fromCode');
$toAttribute->getCode()->willReturn('toCode');
$attrValidatorHelper->validateUnitFamilies($fromAttribute, $toAttribute)->willThrow($e);
$this->shouldThrow(InvalidArgumentException::expectedFromPreviousException($e, 'fromCode && toCode', 'copier', 'concrete'))->during('testUnitFamily', [$fromAttribute, $toAttribute]);
}
示例8:
function it_throws_an_error_if_attribute_data_unit_does_not_exist(AttributeInterface $attribute, ProductInterface $product, $measureManager)
{
$attribute->getCode()->willReturn('attributeCode');
$attribute->getMetricFamily()->willReturn('Weight');
$data = ['data' => 42, 'unit' => 'incorrect unit'];
$measureManager->getUnitSymbolsForFamily('Weight')->shouldBeCalled()->willReturn(['KILOGRAM' => 'kg', 'GRAM' => 'g']);
$this->shouldThrow(InvalidArgumentException::arrayInvalidKey('attributeCode', 'unit', 'The unit does not exist', 'setter', 'metric', 'incorrect unit'))->during('setAttributeData', [$product, $attribute, $data, ['locale' => 'fr_FR', 'scope' => 'mobile']]);
}
示例9: checkUnitFamily
/**
* Check that unit families of 2 attributes are consistent.
*
* @param AttributeInterface $fromAttribute
* @param AttributeInterface $toAttribute
* @param string $type
*
* @throws \Pim\Bundle\CatalogBundle\Exception\InvalidArgumentException
*/
protected function checkUnitFamily(AttributeInterface $fromAttribute, AttributeInterface $toAttribute, $type)
{
try {
$this->attrValidatorHelper->validateUnitFamilies($fromAttribute, $toAttribute);
} catch (\LogicException $e) {
throw InvalidArgumentException::expectedFromPreviousException($e, $fromAttribute->getCode() . ' && ' . $toAttribute->getCode(), 'copier', $type);
}
}
示例10:
function it_fails_if_one_of_the_associated_group_does_not_exist($productBuilder, $groupRepository, ProductInterface $product, AssociationInterface $xsellAssociation)
{
$product->getAssociations()->willReturn([$xsellAssociation]);
$productBuilder->addMissingAssociations($product)->shouldBeCalled();
$product->getAssociationForTypeCode('xsell')->willReturn($xsellAssociation);
$groupRepository->findOneByIdentifier('not existing group')->willReturn(null);
$this->shouldThrow(InvalidArgumentException::expected('associations', 'existing group code', 'adder', 'association', 'not existing group'))->during('addFieldData', [$product, 'associations', ['xsell' => ['groups' => ['not existing group'], 'products' => []]]]);
}
示例11: checkValue
/**
* {@inheritdoc}
*/
protected function checkValue($field, $value, $locale, $scope)
{
if (!is_numeric($value)) {
throw InvalidArgumentException::numericExpected($field, 'filter', 'completeness', gettype($value));
}
if (null === $scope) {
throw new InvalidArgumentException('Scope expected for completeness filter. None given.');
}
}
示例12: checkValue
/**
* Check if value is valid
*
* @param string $field
* @param mixed $value
* @param string|null $locale
* @param string|null $scope
*/
protected function checkValue($field, $value, $locale, $scope)
{
if (!is_numeric($value)) {
throw InvalidArgumentException::numericExpected($field, 'filter', 'completeness', gettype($value));
}
if (null === $locale || null === $scope) {
throw InvalidArgumentException::localeAndScopeExpected($field, 'filter', 'completeness');
}
}
示例13: checkLocaleAndScope
/**
* Check locale and scope are valid
*
* @param AttributeInterface $attribute
* @param string $locale
* @param string $scope
* @param string $type
*
* @throws \Pim\Bundle\CatalogBundle\Exception\InvalidArgumentException
*/
protected function checkLocaleAndScope(AttributeInterface $attribute, $locale, $scope, $type)
{
try {
$this->attrValidatorHelper->validateLocale($attribute, $locale);
$this->attrValidatorHelper->validateScope($attribute, $scope);
} catch (\LogicException $e) {
throw InvalidArgumentException::expectedFromPreviousException($e, $attribute->getCode(), 'copier', $type);
}
}
示例14: checkData
/**
* Check if data is valid
*
* @param AttributeInterface $attribute
* @param mixed $data
*/
protected function checkData(AttributeInterface $attribute, $data)
{
if (null === $data) {
return;
}
if (!is_string($data)) {
throw InvalidArgumentException::stringExpected($attribute->getCode(), 'setter', 'simple select', gettype($data));
}
}
示例15: addFieldFilter
/**
* {@inheritdoc}
*/
public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
{
if (!is_bool($value)) {
throw InvalidArgumentException::booleanExpected($field, 'filter', 'boolean', gettype($value));
}
$field = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, FieldFilterHelper::getCode($field));
$this->qb->field($field)->equals($value);
return $this;
}