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
 /**
  * Gets URI parameter as an object
  *
  * Object is of class $parameter name, and is read from current data link using the parameter
  * value as identifier.
  *
  * @param $parameter_name string
  * @return object
  */
 public function getObject($parameter_name)
 {
     if (isset($this->objects[$parameter_name])) {
         // parameter is in cache
         $object = $this->objects[$parameter_name];
     } elseif (is_numeric($this->getRawParameter($parameter_name))) {
         if (isset($parameter_name[0]) && ctype_upper($parameter_name[0])) {
             $class_name = $parameter_name;
         }
         if (isset($class_name) && @class_exists($class_name)) {
             // object parameter
             $object = $this->getRawParameter($parameter_name) + 0;
             Mapper\Getter::getObject($object, $class_name);
             $this->objects[$parameter_name] = $object;
         } else {
             // free parameter
             $object = $this->getRawParameter($parameter_name);
             $this->objects[$parameter_name] = $object;
         }
     } else {
         // text parameter
         $object = $this->getRawParameter($parameter_name);
         if (is_string($object) && $object && $object[0] === SL) {
             $object = new Uri($object);
         }
         $this->objects[$parameter_name] = $object;
     }
     if (empty($object)) {
         $built_parameter_name = Builder::className($parameter_name);
         if ($built_parameter_name != $parameter_name) {
             return $this->getObject(Builder::className($parameter_name));
         }
     }
     return $object;
 }
Exemplo n.º 3
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);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * @return object
  */
 public function getObject()
 {
     Getter::getObject($this->object, $this->class_name);
     return $this->object;
 }