本文整理汇总了PHP中Pim\Component\Catalog\Exception\InvalidArgumentException::stringExpected方法的典型用法代码示例。如果您正苦于以下问题:PHP InvalidArgumentException::stringExpected方法的具体用法?PHP InvalidArgumentException::stringExpected怎么用?PHP InvalidArgumentException::stringExpected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Component\Catalog\Exception\InvalidArgumentException
的用法示例。
在下文中一共展示了InvalidArgumentException::stringExpected方法的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: 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', 'reference data', gettype($data));
}
}
示例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: gettype
function it_throws_an_exception_if_value_is_not_a_string(AttributeInterface $attribute)
{
$attribute->getCode()->willReturn('attributeCode');
$this->shouldThrow(InvalidArgumentException::stringExpected('attributeCode', 'filter', 'string', gettype(123)))->during('addAttributeFilter', [$attribute, '=', 123, null, null, ['field' => 'attributeCode']]);
}
示例6: gettype
function it_throws_an_exception_if_value_is_not_valid(AttributeInterface $attribute)
{
$attribute->getCode()->willReturn('media_code');
$value = ['data' => 132, 'unit' => 'foo'];
$this->shouldThrow(InvalidArgumentException::stringExpected('media_code', 'filter', 'media', gettype($value)))->during('addAttributeFilter', [$attribute, '=', $value]);
}
示例7: checkData
/**
* Check if data are valid
*
* @param string $field
* @param mixed $data
*/
protected function checkData($field, $data)
{
if (!is_string($data) && null !== $data && '' !== $data) {
throw InvalidArgumentException::stringExpected($field, 'setter', 'family', gettype($data));
}
}
示例8: checkValue
/**
* @param AttributeInterface $attribute
* @param mixed $value
*/
protected function checkValue(AttributeInterface $attribute, $value)
{
if (!is_string($value)) {
throw InvalidArgumentException::stringExpected($attribute->getCode(), 'filter', 'media', gettype($value));
}
}
示例9: checkScalarValue
/**
* @param string $field
* @param mixed $value
*/
protected function checkScalarValue($field, $value)
{
if (!is_string($value) && null !== $value) {
throw InvalidArgumentException::stringExpected($field, 'filter', 'string', gettype($value));
}
}
示例10:
function it_checks_valid_data_format(ProductInterface $product)
{
$this->shouldThrow(InvalidArgumentException::stringExpected('variant_group', 'setter', 'variant_group', 'array'))->during('setFieldData', [$product, 'variant_group', ['not a string']]);
}
示例11: gettype
function it_throws_an_error_if_attribute_data_is_not_a_string_or_null(AttributeInterface $attribute, ProductInterface $product)
{
$attribute->getCode()->willReturn('attributeCode');
$data = ['some', 'random', 'stuff'];
$this->shouldThrow(InvalidArgumentException::stringExpected('attributeCode', 'setter', 'simple select', gettype($data)))->duringSetAttributeData($product, $attribute, $data, ['locale' => 'fr_FR', 'scope' => 'mobile']);
}
示例12:
function it_throws_an_exception_if_value_is_not_a_string_for_since_last_export()
{
$this->shouldThrow(InvalidArgumentException::stringExpected('updated', 'filter', 'updated', 'integer'))->during('addFieldFilter', ['updated', 'SINCE LAST JOB', 42, null, null]);
}