/** * Initializes the object if not already set * - if a data link identifier is set, read the object from the data link and remove it from * $array * - if the object is a link class and the link class identifier properties values are set, * read the object from the data link * * @param $array array the source array * @param $object object the object to complete (if set) or to build (if null) * This object is always set at the end of execution of initObject() * @return array if read from a link object, this is the search properties that identify it */ private function initObject(&$array, &$object) { if (!isset($object)) { if (isset($array['id']) && $array['id']) { $object = Dao::read($array['id'], $this->class->name); } else { foreach ($this->class->getAnnotations('before_build_array') as $before) { call_user_func_array([$this->class->name, $before->value], [&$array]); } $link_search = $this->initLinkObject($array, $object); if (!isset($object)) { $object = $this->class->newInstance(); } } if (isset($array['id'])) { unset($array['id']); } } return isset($link_search) ? $link_search : null; }
/** * @param $property Reflection_Property * @return Reflection_Class */ private function getForeignClass(Reflection_Property $property) { $type = $property->getType(); $foreign_class_name = Builder::className($type->getElementTypeAsString()); if ($property instanceof PHP\Reflection_Property) { $foreign_class = PHP\Reflection_Class::of($foreign_class_name); } else { $reflection_class = new Reflection\Reflection_Class(get_class($property->getDeclaringClass())); $foreign_class = $reflection_class->newInstance($foreign_class_name); } return $foreign_class; }