@@ -12,37 +12,37 @@ |
||
12 | 12 | */ |
13 | 13 | class Wordlift_Entity_Property_Service extends Wordlift_Simple_Property_Service { |
14 | 14 | |
15 | - /** |
|
16 | - * {@inheritdoc} |
|
17 | - */ |
|
18 | - public function get( $id, $meta_key, $type ) { |
|
19 | - |
|
20 | - $entity_service = Wordlift_Entity_Service::get_instance(); |
|
21 | - |
|
22 | - // Map each returned value to a Wordlift_Property_Entity_Reference. |
|
23 | - return array_map( |
|
24 | - function ( $item ) use ( $entity_service ) { |
|
25 | - |
|
26 | - $regex = '/^(post|term)_(\d+)$/m'; |
|
27 | - if ( preg_match( $regex, $item, $matches ) ) { |
|
28 | - |
|
29 | - $object_type = Object_Type_Enum::from_string( $matches[1] ); |
|
30 | - $identifier = (int) $matches[2]; |
|
31 | - if ( Object_Type_Enum::POST === $object_type ) { |
|
32 | - return new Post_Reference( $identifier ); |
|
33 | - } elseif ( Object_Type_Enum::TERM === $object_type ) { |
|
34 | - return new Term_Reference( $identifier ); |
|
35 | - } |
|
36 | - } |
|
37 | - |
|
38 | - // If the $item is a number and it's an existing post, return the |
|
39 | - // URI of the referenced entity. Otherwise return the value. |
|
40 | - return is_numeric( $item ) && null !== get_post( $item ) |
|
41 | - ? new Wordlift_Property_Entity_Reference( $entity_service->get_uri( $item ), (int) $item ) |
|
42 | - : $item; |
|
43 | - }, |
|
44 | - parent::get( $id, $meta_key, $type ) |
|
45 | - ); |
|
46 | - } |
|
15 | + /** |
|
16 | + * {@inheritdoc} |
|
17 | + */ |
|
18 | + public function get( $id, $meta_key, $type ) { |
|
19 | + |
|
20 | + $entity_service = Wordlift_Entity_Service::get_instance(); |
|
21 | + |
|
22 | + // Map each returned value to a Wordlift_Property_Entity_Reference. |
|
23 | + return array_map( |
|
24 | + function ( $item ) use ( $entity_service ) { |
|
25 | + |
|
26 | + $regex = '/^(post|term)_(\d+)$/m'; |
|
27 | + if ( preg_match( $regex, $item, $matches ) ) { |
|
28 | + |
|
29 | + $object_type = Object_Type_Enum::from_string( $matches[1] ); |
|
30 | + $identifier = (int) $matches[2]; |
|
31 | + if ( Object_Type_Enum::POST === $object_type ) { |
|
32 | + return new Post_Reference( $identifier ); |
|
33 | + } elseif ( Object_Type_Enum::TERM === $object_type ) { |
|
34 | + return new Term_Reference( $identifier ); |
|
35 | + } |
|
36 | + } |
|
37 | + |
|
38 | + // If the $item is a number and it's an existing post, return the |
|
39 | + // URI of the referenced entity. Otherwise return the value. |
|
40 | + return is_numeric( $item ) && null !== get_post( $item ) |
|
41 | + ? new Wordlift_Property_Entity_Reference( $entity_service->get_uri( $item ), (int) $item ) |
|
42 | + : $item; |
|
43 | + }, |
|
44 | + parent::get( $id, $meta_key, $type ) |
|
45 | + ); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | } |