/** * Build SQL WHERE section for an object * * @param $path string Base property path pointing to the object * @param $object object The value is an object, which will be used for search * @return string */ private function buildObject($path, $object) { $class = new Link_Class(get_class($object)); $id = $this->sql_link->getObjectIdentifier($object, $class->getAnnotation('link')->value ? $class->getCompositeProperty()->name : null); if ($id) { // object is linked to stored data : search with object identifier return $this->buildValue($path, $id, $path == 'id' ? '' : 'id_'); } // object is a search object : each property is a search entry, and must join table $this->joins->add($path); $array = []; $class = new Reflection_Class(get_class($object)); foreach ($class->accessProperties() as $property_name => $property) { if (isset($object->{$property_name})) { $sub_path = $property_name; $array[$sub_path] = $object->{$property_name}; } } $sql = $this->buildArray($path, $array, 'AND'); if (!$sql) { $sql = 'FALSE'; } return $sql; }
/** * Used to get an object's identifier * * A null value will be returned for an object that is not linked to data link. * If $object is already an identifier, the identifier is returned. * * @param $object object an object to get data link identifier from * @param $property_name string a property name to get data link identifier from instead of object * @return mixed you can test if an object identifier is set with empty($of_this_result) */ public function getObjectIdentifier($object, $property_name = null) { return isset($property_name) ? parent::getObjectIdentifier($object, $property_name) : ($this->getLinkObjectIdentifier($object) ?: parent::getObjectIdentifier($object)); }
/** * Changes an object into an array associating properties and their values * This has specific features and is intended for internal use only : * - If the object has an object identifier, only ['id' => $id] will be set, not others properties * - If $object is an array, it keeps and replaces Reflection_Property_Value element by its value * * @param $object array|object|null if already an array, nothing will be done * @return mixed[] indices ar properties paths */ private function objectToProperties($object) { if (is_object($object)) { $id = $this->link->getObjectIdentifier($object); $object = isset($id) ? ['id' => $id] : get_object_vars($object); } elseif (is_array($object)) { foreach ($object as $path => $value) { if ($value instanceof Reflection_Property_Value) { $object[$path] = $value->value(); } } } return $object; }