本文整理汇总了PHP中Pim\Bundle\CatalogBundle\Exception\InvalidArgumentException::numericExpected方法的典型用法代码示例。如果您正苦于以下问题:PHP InvalidArgumentException::numericExpected方法的具体用法?PHP InvalidArgumentException::numericExpected怎么用?PHP InvalidArgumentException::numericExpected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Bundle\CatalogBundle\Exception\InvalidArgumentException
的用法示例。
在下文中一共展示了InvalidArgumentException::numericExpected方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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.');
}
}
示例2: 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');
}
}
示例3: addAttributeFilter
/**
* {@inheritdoc}
*/
public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
{
$this->checkLocaleAndScope($attribute, $locale, $scope, 'number');
if (!is_numeric($value) && null !== $value) {
throw InvalidArgumentException::numericExpected($attribute->getCode(), 'filter', 'number', gettype($value));
}
$field = ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $locale, $scope);
$field = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, $field);
$this->applyFilter($operator, $value, $field);
return $this;
}
示例4: checkIdentifier
/**
* Check if value is a valid identifier
*
* @param string $field
* @param mixed $value
* @param string $filter
*/
public static function checkIdentifier($field, $value, $filter)
{
$invalidIdField = static::hasProperty($field) && static::getProperty($field) === 'id' && !is_numeric($value);
$invalidDefaultField = !static::hasProperty($field) && !is_numeric($value);
if ($invalidIdField || $invalidDefaultField) {
throw InvalidArgumentException::numericExpected(static::getCode($field), 'filter', $filter, gettype($value));
}
$invalidStringField = static::hasProperty($field) && static::getProperty($field) !== 'id' && !is_string($value);
if ($invalidStringField) {
throw InvalidArgumentException::stringExpected(static::getCode($field), 'filter', $filter, gettype($value));
}
}
示例5: setValue
/**
* {@inheritdoc}
*/
public function setValue(array $products, AttributeInterface $attribute, $data, $locale = null, $scope = null)
{
if (null === $this->productBuilder) {
throw new \RuntimeException('The product builder should be set.');
}
$this->checkLocaleAndScope($attribute, $locale, $scope, 'number');
if (!is_numeric($data) && null !== $data) {
throw InvalidArgumentException::numericExpected($attribute->getCode(), 'setter', 'number', gettype($data));
}
foreach ($products as $product) {
$this->setData($attribute, $product, $data, $locale, $scope);
}
}
示例6: addAttributeFilter
/**
* {@inheritdoc}
*/
public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
{
$this->checkLocaleAndScope($attribute, $locale, $scope, 'number');
if (!is_numeric($value) && null !== $value) {
throw InvalidArgumentException::numericExpected($attribute->getCode(), 'filter', 'number', gettype($value));
}
$joinAlias = $this->getUniqueAlias('filter' . $attribute->getCode());
$backendField = sprintf('%s.%s', $joinAlias, $attribute->getBackendType());
if ($operator === Operators::IS_EMPTY) {
$this->qb->leftJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope));
$this->qb->andWhere($this->prepareCriteriaCondition($backendField, $operator, $value));
} else {
$condition = $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope);
$condition .= ' AND ' . $this->prepareCriteriaCondition($backendField, $operator, $value);
$this->qb->innerJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $condition);
}
return $this;
}
示例7: gettype
function it_throws_an_exception_if_the_content_of_value_are_not_numeric(AttributeInterface $attribute)
{
$attribute->getCode()->willReturn('options_code');
$this->shouldThrow(InvalidArgumentException::numericExpected('options_code', 'filter', 'options', gettype('WRONG')))->during('addAttributeFilter', [$attribute, 'IN', [123, 'not numeric'], null, null, ['field' => 'options_code.id']]);
}
示例8:
function it_throws_an_exception_if_value_is_not_a_valid_array(AttributeInterface $attribute)
{
$attribute->getId()->willReturn(1);
$attribute->getCode()->willReturn('color');
$value = 'string';
$this->shouldThrow(InvalidArgumentException::arrayExpected('color', 'filter', 'reference_data', $value))->during('addAttributeFilter', [$attribute, '=', $value, null, null, ['field' => 'color']]);
$value = ['foo'];
$this->shouldThrow(InvalidArgumentException::numericExpected('color', 'filter', 'reference_data', 'string'))->during('addAttributeFilter', [$attribute, '=', $value, null, null, ['field' => 'color']]);
}
示例9: gettype
function it_throws_an_exception_if_value_is_not_an_integer()
{
$this->shouldThrow(InvalidArgumentException::numericExpected('completeness', 'filter', 'completeness', gettype('123')))->during('addFieldFilter', ['completeness', '=', '12a3', 'fr_FR', 'mobile']);
}
示例10: gettype
function it_throws_an_exception_if_content_of_array_is_not_integer_or_empty()
{
$this->shouldThrow(InvalidArgumentException::numericExpected('family', 'filter', 'family', gettype('WRONG')))->during('addFieldFilter', ['family', 'IN', [1, 2, 'WRONG']]);
}
示例11: gettype
function it_throws_an_error_if_data_is_not_a_number_or_null(AttributeInterface $attribute)
{
$attribute->getCode()->willReturn('attributeCode');
$data = 'not a number';
$this->shouldThrow(InvalidArgumentException::numericExpected('attributeCode', 'setter', 'number', gettype($data)))->during('setValue', [[], $attribute, $data, 'fr_FR', 'mobile']);
}
示例12: gettype
function it_throws_an_exception_if_value_is_not_a_numeric(AttributeInterface $attribute)
{
$attribute->getCode()->willReturn('number_code');
$this->shouldThrow(InvalidArgumentException::numericExpected('number_code', 'filter', 'number', gettype('WRONG')))->during('addAttributeFilter', [$attribute, '=', 'WRONG']);
}