本文整理汇总了PHP中Pim\Component\Catalog\Exception\InvalidArgumentException::numericExpected方法的典型用法代码示例。如果您正苦于以下问题:PHP InvalidArgumentException::numericExpected方法的具体用法?PHP InvalidArgumentException::numericExpected怎么用?PHP InvalidArgumentException::numericExpected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Component\Catalog\Exception\InvalidArgumentException
的用法示例。
在下文中一共展示了InvalidArgumentException::numericExpected方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addFieldFilter
/**
* {@inheritdoc}
*/
public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
{
switch ($operator) {
case Operators::SINCE_LAST_JOB:
if (!is_string($value)) {
throw InvalidArgumentException::stringExpected($field, 'filter', 'updated', gettype($value));
}
$this->addUpdatedSinceLastJob($field, $value);
break;
case Operators::SINCE_LAST_N_DAYS:
if (!is_numeric($value)) {
throw InvalidArgumentException::numericExpected($field, 'filter', 'updated', gettype($value));
}
$this->addSinceLastNDays($field, $value);
break;
case Operators::NOT_BETWEEN:
$values = $this->formatValues($field, $value);
$field = current($this->qb->getRootAliases()) . '.' . $field;
$this->applyNotBetweenFilter($field, $values);
break;
default:
$value = Operators::IS_EMPTY === $operator ? null : $this->formatValues($field, $value);
$field = current($this->qb->getRootAliases()) . '.' . $field;
$this->qb->andWhere($this->prepareCriteriaCondition($field, $operator, $value));
}
return $this;
}
示例2: addFieldFilter
/**
* {@inheritdoc}
*/
public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
{
if (Operators::IS_EMPTY !== $operator && Operators::IS_NOT_EMPTY !== $operator && Operators::SINCE_LAST_JOB !== $operator && Operators::SINCE_LAST_N_DAYS !== $operator) {
$value = $this->formatValues($field, $value);
}
if (Operators::SINCE_LAST_JOB === $operator) {
if (!is_string($value)) {
throw InvalidArgumentException::stringExpected($field, 'filter', 'updated', gettype($value));
}
$jobInstance = $this->jobInstanceRepository->findOneBy(['code' => $value]);
$lastCompletedJobExecution = $this->jobRepository->getLastJobExecution($jobInstance, BatchStatus::COMPLETED);
if (null === $lastCompletedJobExecution) {
return $this;
}
$lastJobStartTime = $lastCompletedJobExecution->getStartTime()->setTimezone(new \DateTimeZone('UTC'));
$value = $lastJobStartTime->getTimestamp();
$operator = Operators::GREATER_THAN;
}
if (Operators::SINCE_LAST_N_DAYS === $operator) {
if (!is_numeric($value)) {
throw InvalidArgumentException::numericExpected($field, 'filter', 'updated', gettype($value));
}
$fromDate = new \DateTime(sprintf('%s days ago', $value), new \DateTimeZone('UTC'));
$value = $fromDate->getTimestamp();
$operator = Operators::GREATER_THAN;
}
$field = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, $field);
$this->applyFilter($field, $operator, $value);
return $this;
}
示例3: 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');
}
}
示例4: 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;
}
示例5: 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));
}
}
示例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:
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']]);
}
示例8: 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']);
}
示例9: gettype
function it_throws_an_exception_if_content_of_array_is_not_integer_or_empty()
{
$this->shouldThrow(InvalidArgumentException::numericExpected('groups', 'filter', 'groups', gettype('WRONG')))->during('addFieldFilter', ['groups.id', 'IN', [1, 2, 'WRONG']]);
}
示例10: 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('not numeric')))->during('addAttributeFilter', [$attribute, 'IN', [123, 'not numeric'], null, null, ['field' => 'options_code.id']]);
}
示例11: 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']);
}
示例12:
function it_throws_an_exception_if_value_is_not_a_numeric_for_since_last_n_days()
{
$this->shouldThrow(InvalidArgumentException::numericExpected('updated', 'filter', 'updated', 'string'))->during('addFieldFilter', ['updated', 'SINCE LAST N DAYS', 'csv_product_export', null, null]);
}