/**
  * Add meta data belonging to given object
  * @param \Rocker\Object\MetaInterface $obj
  */
 function applyMetaData(MetaInterface $obj)
 {
     $meta_values = $this->cache->fetch($this->cachePrefix . $obj->getId());
     if (!is_array($meta_values)) {
         $meta_values = array();
         $sql = $this->db->prepare("SELECT name, value FROM " . $this->dbTable . " WHERE object=?");
         $sql->execute(array($obj->getId()));
         while ($row = $sql->fetch()) {
             if (is_numeric($row['value'])) {
                 $int = intval($row['value']);
                 if (strlen((string) $int) === strlen($row['value'])) {
                     $meta_values[$row['name']] = $int;
                 } elseif (is_float($float = (double) $row['value'])) {
                     $meta_values[$row['name']] = $float;
                 } else {
                     $meta_values[$row['name']] = $row['value'];
                 }
             } elseif ($this->isSerialized($row['value'])) {
                 $meta_values[$row['name']] = unserialize($row['value']);
             } else {
                 $meta_values[$row['name']] = $row['value'];
             }
         }
         $this->cache->store($this->cachePrefix . $obj->getId(), $meta_values);
     }
     $obj->setMeta(new MetaData($meta_values));
 }
 /**
  * @param int|string $id Name or user id
  * @return \Rocker\Object\ObjectInterface
  */
 protected function loadObject($id)
 {
     $col = is_numeric($id) ? 'id' : 'name';
     $cacheID = $col == 'id' ? $this->cachePrefix . $id : $this->cachePrefix . 'name_' . $id;
     $data = $this->cache->fetch($cacheID);
     if (empty($data)) {
         $sql = $this->db->prepare('SELECT name, id FROM ' . $this->tableName . ' WHERE ' . $col . '=?');
         $sql->execute(array($id));
         $data = $sql->fetch();
         if (isset($data['name'])) {
             $this->cache->store($cacheID, $data);
         } else {
             return null;
         }
     }
     $objClass = $this->objectClassName();
     $obj = new $objClass($data['name'], $data['id'], $this->objectTypeName());
     $this->metaFactory->applyMetaData($obj);
     return $obj;
 }
示例#3
0
 /**
  * @inheritdoc
  */
 public function exec(Server $server, ConnectionInterface $db, CacheInterface $cache)
 {
     $cache->clear();
     return new OperationResponse(204);
 }