Exemplo n.º 1
0
 /**
  * Returns true if the object has no set properties (ie was created with Null_Object:create())
  *
  * @param $object     object
  * @param $class_name string you can set a class name of a parent class to get a partial isNull()
  * @return boolean
  */
 public static function isNull($object, $class_name = null)
 {
     if (!isset($object)) {
         return true;
     }
     if (!isset($class_name)) {
         $class_name = get_class($object);
     }
     $is_null = true;
     $getter_ignore = Getter::$ignore;
     Getter::$ignore = true;
     foreach ((new Reflection_Class($class_name))->accessProperties() as $property) {
         if (!$property->isStatic()) {
             $value = $property->getValue($object);
             if (is_object($value) && !self::isNull($value) || !is_object($value) && !is_null($value)) {
                 $is_null = false;
                 break;
             }
         }
     }
     Getter::$ignore = $getter_ignore;
     return $is_null;
 }
Exemplo n.º 2
0
 /**
  * @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);
         }
     }
 }