File tree 7 files changed +30
-166
lines changed
7 files changed +30
-166
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ class EntityFieldEqualFilter extends EntityFieldFilter
9
9
* @param mixed $value
10
10
* @return bool
11
11
*/
12
- public function validate ($ value )
12
+ protected function validate ($ value )
13
13
{
14
14
return $ value === $ this ->getEntityFieldValue ();
15
15
}
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ public function isFilterValid($entity)
46
46
}
47
47
48
48
$ value = PropertyAccess::createPropertyAccessor ()->getValue ($ entity , $ this ->getEntityFieldName ());
49
- if (!is_scalar ($ value )) {
49
+ if (!empty ( $ value ) && ! is_scalar ($ value )) {
50
50
if (method_exists ($ value , '__toString ' )) {
51
51
$ value = call_user_func ([$ value , '__toString ' ]);
52
52
} else {
Original file line number Diff line number Diff line change @@ -12,19 +12,21 @@ class ArrayField extends Field
12
12
*/
13
13
public function getDocumentFieldValue ($ entity )
14
14
{
15
+ $ result = [];
15
16
$ entityValue = $ this ->getEntityFieldValue ($ entity );
16
- if (is_scalar ($ entityValue )) {
17
- $ entityValue = [ $ entityValue ];
18
- } elseif (
19
- !is_array ($ entityValue ) &&
20
- ((!$ entityValue instanceof \Iterator) && (!$ entityValue instanceof \IteratorAggregate))
21
- ) {
22
- throw new InvalidFieldValueException ('Field value must be \Iterator or \IteratorAggregate instance ' );
23
- }
17
+ if (!is_null ($ entityValue )) {
18
+ if (is_scalar ($ entityValue )) {
19
+ $ entityValue = [ $ entityValue ];
20
+ } elseif (
21
+ !is_array ($ entityValue ) &&
22
+ ((!$ entityValue instanceof \Iterator) && (!$ entityValue instanceof \IteratorAggregate))
23
+ ) {
24
+ throw new InvalidFieldValueException ('Field value must be \Iterator or \IteratorAggregate instance ' );
25
+ }
24
26
25
- $ result = [];
26
- foreach ( $ entityValue as $ value ) {
27
- $ result [] = strval ( $ value );
27
+ foreach ( $ entityValue as $ value ) {
28
+ $ result [] = strval ( $ value );
29
+ }
28
30
}
29
31
30
32
return $ result ;
Original file line number Diff line number Diff line change @@ -10,22 +10,25 @@ class DateField extends Field
10
10
11
11
/**
12
12
* @param object $entity
13
- * @return string
13
+ * @return string|null
14
14
*/
15
15
public function getDocumentFieldValue ($ entity )
16
16
{
17
+ $ result = null ;
17
18
$ entityValue = $ this ->getEntityFieldValue ($ entity );
18
-
19
- if (!$ entityValue instanceof \DateTime) {
20
- throw new InvalidFieldValueException (
21
- sprintf (
22
- '"%s" field value of "%s" must be a DateTime instance ' ,
23
- $ this ->getEntityFieldName (),
24
- get_class ($ entity )
25
- )
26
- );
19
+ if (!is_null ($ entityValue )) {
20
+ if (!$ entityValue instanceof \DateTime) {
21
+ throw new InvalidFieldValueException (
22
+ sprintf (
23
+ '"%s" field value of "%s" must be a DateTime instance ' ,
24
+ $ this ->getEntityFieldName (),
25
+ get_class ($ entity )
26
+ )
27
+ );
28
+ }
29
+ $ result = $ entityValue ->format (self ::FORMAT );
27
30
}
28
31
29
- return $ entityValue -> format ( self :: FORMAT ) ;
32
+ return $ result ;
30
33
}
31
34
}
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ public function getDocumentFieldValue($entity)
13
13
$ entityValue = $ this ->getEntityFieldValue ($ entity );
14
14
$ documentValue = '' ;
15
15
if (is_scalar ($ entityValue )) {
16
- $ documentValue = $ entityValue ;
16
+ $ documentValue = strval ( $ entityValue) ;
17
17
} elseif (is_array ($ entityValue ) || $ entityValue instanceof \Iterator || $ entityValue instanceof \IteratorAggregate) {
18
18
$ documentValue = [];
19
19
foreach ($ entityValue as $ value ) {
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments