本文整理汇总了PHP中Pim\Bundle\CatalogBundle\Exception\InvalidArgumentException::stringExpected方法的典型用法代码示例。如果您正苦于以下问题:PHP InvalidArgumentException::stringExpected方法的具体用法?PHP InvalidArgumentException::stringExpected怎么用?PHP InvalidArgumentException::stringExpected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Bundle\CatalogBundle\Exception\InvalidArgumentException
的用法示例。
在下文中一共展示了InvalidArgumentException::stringExpected方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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));
}
}
示例2: setValue
/**
* {@inheritdoc}
*/
public function setValue(array $products, AttributeInterface $attribute, $data, $locale = null, $scope = null)
{
$this->checkLocaleAndScope($attribute, $locale, $scope, 'text');
if (null !== $data && !is_string($data)) {
throw InvalidArgumentException::stringExpected($attribute->getCode(), 'setter', 'text', gettype($data));
}
foreach ($products as $product) {
$this->setData($attribute, $product, $data, $locale, $scope);
}
}
示例3: 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));
}
}
示例4: 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));
}
}
示例5: 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));
}
}
示例6: checkData
/**
* Check if data are valid
*
* @param string $field
* @param mixed $data
*/
protected function checkData($field, $data)
{
if (!is_string($data) && null !== $data) {
throw InvalidArgumentException::stringExpected($field, 'setter', 'variant_group', gettype($data));
}
}
示例7: gettype
function it_throws_an_exception_if_value_is_not_valid($image)
{
$image->getCode()->willReturn('media_code');
$value = ['data' => 132, 'unit' => 'foo'];
$this->shouldThrow(InvalidArgumentException::stringExpected('media_code', 'filter', 'media', gettype($value)))->during('addAttributeFilter', [$image, '=', $value]);
}
示例8: gettype
function it_throws_an_error_if_data_is_not_a_string_or_null(AttributeInterface $attribute)
{
$attribute->getCode()->willReturn('attributeCode');
$data = ['some', 'random', 'stuff'];
$this->shouldThrow(InvalidArgumentException::stringExpected('attributeCode', 'setter', 'simple select', gettype($data)))->duringSetValue([], $attribute, $data, 'fr_FR', 'mobile');
}
示例9: checkValue
/**
* Check if value is valid
*
* @param string $field
* @param mixed $value
*/
protected function checkValue($field, $value)
{
if (!is_string($value) && !is_array($value)) {
throw InvalidArgumentException::stringExpected($field, 'filter', 'string', gettype($value));
}
if (is_array($value)) {
foreach ($value as $stringValue) {
if (!is_string($stringValue)) {
throw InvalidArgumentException::stringExpected($field, 'filter', 'string', gettype($value));
}
}
}
}
示例10:
function it_checks_valid_data_format(ProductInterface $product)
{
$this->shouldThrow(InvalidArgumentException::stringExpected('family', 'setter', 'family', 'array'))->during('setFieldData', [$product, 'family', ['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: 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']]);
}
示例13: gettype
function it_throws_an_error_if_data_is_not_a_string(AttributeInterface $attribute)
{
$attribute->getCode()->willReturn('attributeCode');
$data = 42;
$this->shouldThrow(InvalidArgumentException::stringExpected('attributeCode', 'setter', 'text', gettype($data)))->during('setValue', [[], $attribute, $data, 'fr_FR', 'mobile']);
}