/
IsFieldEmpty.php
56 lines (49 loc) · 1.5 KB
/
IsFieldEmpty.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace Netgen\EzPlatformSearchExtra\API\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications;
use InvalidArgumentException;
/**
* IsFieldEmpty criterion matches Content field based on if its value is empty or not.
*/
class IsFieldEmpty extends Criterion
{
/**
* Indicates that the field value should be empty.
*
* @var int
*/
const IS_EMPTY = 0;
/**
* Indicates that the field value shouldn't be empty.
*
* @var int
*/
const IS_NOT_EMPTY = 1;
/**
* @param string $fieldDefinitionIdentifier
* @param int $value Field value constant, one of self::IS_EMPTY and self::IS_NOT_EMPTY
*
* @throws \InvalidArgumentException
*/
public function __construct($fieldDefinitionIdentifier, $value)
{
if ($value !== self::IS_EMPTY && $value !== self::IS_NOT_EMPTY) {
throw new InvalidArgumentException(
"Invalid has field content value {$value}"
);
}
parent::__construct($fieldDefinitionIdentifier, null, $value);
}
public function getSpecifications(): array
{
return [
new Specifications(
Operator::EQ,
Specifications::FORMAT_SINGLE,
Specifications::TYPE_INTEGER
),
];
}
}