Author: Tom Walder (twalder@gmail.com)
示例#1
0
 /**
  * Write to Datastore
  *
  * @param $str_id
  * @param $str_session_data
  */
 private function persist($str_id, $str_session_data)
 {
     // syslog(LOG_WARNING, __METHOD__ . "() Writing to Datastore");
     try {
         $obj_store = $this->getStore();
         $str_now = date('Y-m-d H:i:s');
         if ($this->obj_session_entity instanceof Entity) {
             $this->obj_session_entity->data = $str_session_data;
             $this->obj_session_entity->updated = $str_now;
         } else {
             $this->obj_session_entity = $obj_store->createEntity(['data' => $str_session_data, 'created' => $str_now, 'updated' => $str_now]);
             $this->obj_session_entity->setKeyName($str_id);
         }
         $obj_store->upsert($this->obj_session_entity);
     } catch (\Exception $obj_ex) {
         syslog(LOG_WARNING, __METHOD__ . "() Unable to write to Datastore: " . $obj_ex->getMessage());
     }
 }
示例#2
0
 /**
  * Create a fully qualified Key path
  *
  * @equivalent ProtoBuf::configureKey() ?
  *
  * @param Entity $obj_gds_entity
  * @param bool $bol_first_node
  * @return array
  * @throws \Exception
  */
 public function buildKeyPath(Entity $obj_gds_entity, $bol_first_node = true)
 {
     $str_kind = $obj_gds_entity->getKind();
     if (null === $str_kind) {
         if ($bol_first_node) {
             if ($this->obj_schema instanceof Schema) {
                 $str_kind = $this->obj_schema->getKind();
             } else {
                 throw new \Exception('Could not build full key path, no Schema set on Mapper and no Kind set on Entity');
             }
         } else {
             throw new \Exception('Could not build full key path, no Kind set on (nth node) GDS Entity');
         }
     }
     // Build the first node in the Key Path from this entity
     $arr_full_path = [$this->createKeyPathElement(['kind' => $str_kind, 'id' => $obj_gds_entity->getKeyId(), 'name' => $obj_gds_entity->getKeyName()])];
     // Add any ancestors to the Key Path
     $mix_ancestry = $obj_gds_entity->getAncestry();
     if (is_array($mix_ancestry)) {
         $arr_ancestor_path = [];
         foreach ($mix_ancestry as $arr_ancestor_element) {
             $arr_ancestor_path[] = $this->createKeyPathElement($arr_ancestor_element);
         }
         $arr_full_path = array_merge($arr_ancestor_path, $arr_full_path);
     } elseif ($mix_ancestry instanceof Entity) {
         $arr_full_path = array_merge($this->buildKeyPath($mix_ancestry, false), $arr_full_path);
     }
     return $arr_full_path;
 }
 /**
  * Create a fully qualified Key path
  *
  * @equivalent ProtoBuf::configureKey() ?
  *
  * @param Entity $obj_gds_entity
  * @param bool $bol_first_node
  * @return array
  * @throws \Exception
  */
 private function buildKeyPath(Entity $obj_gds_entity, $bol_first_node = TRUE)
 {
     $str_kind = $obj_gds_entity->getKind();
     if (null === $str_kind) {
         if ($bol_first_node) {
             $str_kind = $this->obj_schema->getKind();
         } else {
             throw new \Exception('Could not build full key path, no Kind set on (nth node) GDS Entity');
         }
     }
     // Build the first node in the Key Path from this entity
     $arr_full_path = [$this->createKeyPathElement(['kind' => $str_kind, 'id' => $obj_gds_entity->getKeyId(), 'name' => $obj_gds_entity->getKeyName()])];
     // Add any ancestors to the Key Path
     $mix_ancestry = $obj_gds_entity->getAncestry();
     if (is_array($mix_ancestry)) {
         foreach ((array) $obj_gds_entity->getAncestry() as $arr_ancestor_element) {
             array_unshift($arr_full_path, $this->createKeyPathElement($arr_ancestor_element));
         }
     } elseif ($mix_ancestry instanceof Entity) {
         $arr_full_path = array_merge($this->buildKeyPath($mix_ancestry, FALSE), $arr_full_path);
     }
     return $arr_full_path;
 }
 /**
  * Populate a ProtoBuf Key from a GDS Entity
  *
  * @param Key $obj_key
  * @param Entity $obj_gds_entity
  * @return Key
  */
 public function configureGoogleKey(Key $obj_key, Entity $obj_gds_entity)
 {
     // Add any ancestors FIRST
     $mix_ancestry = $obj_gds_entity->getAncestry();
     if (is_array($mix_ancestry)) {
         // @todo Get direction right!
         foreach ($mix_ancestry as $arr_ancestor_element) {
             $this->configureGoogleKeyPathElement($obj_key->addPathElement(), $arr_ancestor_element);
         }
     } elseif ($mix_ancestry instanceof Entity) {
         // Recursive
         $this->configureGoogleKey($obj_key, $mix_ancestry);
     }
     // Root Key (must be the last in the chain)
     $this->configureGoogleKeyPathElement($obj_key->addPathElement(), ['kind' => $obj_gds_entity->getKind(), 'id' => $obj_gds_entity->getKeyId(), 'name' => $obj_gds_entity->getKeyName()]);
     return $obj_key;
 }
示例#5
0
 public function __set($key, $value)
 {
     $definition = $this->getDefinition();
     if (isset($definition[$key])) {
         parent::__set($key, $value);
     } else {
         throw new Exception('Error ' . $key . ' is not settable.');
     }
 }