예제 #1
0
파일: Link.php 프로젝트: TuxBoy/Demo-saf
 /**
  * @param $object   object
  * @param $property Reflection_Property
  * @param $map      object[]
  */
 private function writeMap($object, Reflection_Property $property, $map)
 {
     // old map
     $class = new Link_Class(get_class($object));
     $composite_property_name = $class->getAnnotation('link')->value ? $class->getCompositeProperty()->name : null;
     $old_object = Search_Object::create(Link_Class::linkedClassNameOf($object));
     $this->setObjectIdentifier($old_object, $this->getObjectIdentifier($object, $composite_property_name));
     $aop_getter_ignore = Getter::$ignore;
     Getter::$ignore = false;
     $old_map = $property->getValue($old_object);
     Getter::$ignore = $aop_getter_ignore;
     // map properties : write each of them
     $insert_builder = new Map_Insert($property);
     $id_set = [];
     foreach ($map as $element) {
         $id = $this->getObjectIdentifier($element) ?: $this->getObjectIdentifier($this->write($element));
         if (!isset($old_map[$id])) {
             $query = $insert_builder->buildQuery($object, $element);
             $this->connection->query($query);
         } else {
             $id_set[$id] = true;
         }
     }
     // remove old unused elements
     $delete_builder = new Map_Delete($property);
     foreach ($old_map as $old_element) {
         $id = $this->getObjectIdentifier($old_element);
         if (!isset($id_set[$id])) {
             $query = $delete_builder->buildQuery($object, $old_element);
             $this->connection->query($query);
         }
     }
 }
예제 #2
0
 /**
  * Create a table in database, using a data class structure
  *
  * @param $mysqli     Contextual_Mysqli
  * @param $class_name string
  */
 private function createTable(Contextual_Mysqli $mysqli, $class_name)
 {
     $builder = new Table_Builder_Class();
     foreach ($builder->build($class_name) as $table) {
         $last_context = $mysqli->context;
         $mysqli->context = $builder->dependencies_context;
         $mysqli->query((new Create_Table($table))->build());
         $mysqli->context = $last_context;
     }
 }