1 | <?php |
||
18 | abstract class Entity implements EntityInterface { |
||
19 | |||
20 | /** |
||
21 | * The property map definition. |
||
22 | * |
||
23 | * @var \TheSportsDb\PropertyMapper\PropertyMapDefinition |
||
24 | */ |
||
25 | protected static $propertyMapDefinition; |
||
26 | |||
27 | /** |
||
28 | * Creates a new Entity object. |
||
29 | * |
||
30 | * @param \stdClass $values |
||
31 | * The entity data. |
||
32 | */ |
||
33 | public function __construct(\stdClass $values) { |
||
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | */ |
||
40 | 1 | public function raw() { |
|
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | 1 | public function update(\stdClass $values) { |
|
74 | |||
75 | /** |
||
76 | * {@inheritdoc} |
||
77 | */ |
||
78 | 1 | public static function getEntityType() { |
|
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | 1 | public static function getPropertyMapDefinition() { |
|
87 | 1 | if (!isset(static::$propertyMapDefinition)) { |
|
88 | static::$propertyMapDefinition = new PropertyMapDefinition(); |
||
89 | static::initPropertyMapDefinition(); |
||
90 | } |
||
91 | 1 | return static::$propertyMapDefinition; |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * Initialize the property map definition for this entity type. |
||
96 | * |
||
97 | * @return void |
||
98 | */ |
||
99 | protected static function initPropertyMapDefinition() {} |
||
100 | |||
101 | /** |
||
102 | * Reverse map a property that is an entity. |
||
103 | * |
||
104 | * @param array $entity |
||
105 | * The entity to reverse map. |
||
106 | * @param mixed $context |
||
107 | * The context for this mapping. Usually the raw entity this property is |
||
108 | * from. |
||
109 | * @param EntityManagerInterface $entityManager |
||
110 | * The entity manager. |
||
111 | * |
||
112 | * @return mixed |
||
113 | * The reverse mapped value for this property, usually the entity id. |
||
114 | */ |
||
115 | 1 | public static function reverse($entity, $context, EntityManagerInterface $entityManager) { |
|
119 | |||
120 | /** |
||
121 | * Reverse map a property that is an array of entities. |
||
122 | * |
||
123 | * @param array $entities |
||
124 | * The entities to reverse map. |
||
125 | * @param mixed $context |
||
126 | * The context for this mapping. Usually the raw entity. |
||
127 | * @param EntityManagerInterface $entityManager |
||
128 | * The entity manager. |
||
129 | * |
||
130 | * @return array |
||
131 | * The reverse mapped value for this property, usually an array of ids. |
||
132 | */ |
||
133 | 1 | public static function reverseArray(array $entities, $context, EntityManagerInterface $entityManager) { |
|
140 | |||
141 | /** |
||
142 | * Transforms a property value to an entity. |
||
143 | * |
||
144 | * @param mixed $value |
||
145 | * The value to transform. |
||
146 | * @param \stdClass $context |
||
147 | * The context for this mapping. Usually the raw entity as defined by the |
||
148 | * sportsdb api this property is from. |
||
149 | * @param EntityManagerInterface $entityManager |
||
150 | * The entity manager. |
||
151 | * @param string $entityType |
||
152 | * The enitity type to transform this value to. |
||
153 | * @param string $idName |
||
154 | * The name of the identifier property as defined by the sportsdb api. |
||
155 | * @param array $contextPropertyMap |
||
156 | * Extra properties to map from the context |
||
157 | * |
||
158 | * @return \TheSportsDb\Entity\EntityInterface |
||
159 | * The mapped entity. |
||
160 | */ |
||
161 | 1 | public static function transform($value, $context, EntityManagerInterface $entityManager, $entityType, $idName, array $contextPropertyMap = array()) { |
|
168 | |||
169 | /** |
||
170 | * Helper function to transform an entity. |
||
171 | * |
||
172 | * @param mixed $value |
||
173 | * The value to transform. |
||
174 | * @param \stdClass $context |
||
175 | * The context for this mapping. Usually the raw entity as defined by the |
||
176 | * sportsdb api this property is from. |
||
177 | * @param string $idName |
||
178 | * The name of the identifier property as defined by the sportsdb api. |
||
179 | * @param array $contextPropertyMap |
||
180 | * Extra properties to map from the context |
||
181 | * |
||
182 | * @return array |
||
183 | * An array with following keys: |
||
184 | * - object: The raw data representing the entity. |
||
185 | * - id: The id of the entity. |
||
186 | */ |
||
187 | 1 | public static function transformHelper($value, $context, $idName, array $contextPropertyMap = array()) { |
|
198 | } |
||
199 |