Ejemplo n.º 1
0
 function testMagicMethods()
 {
     $obj = new \Rocker\Object\PlainObject('testo', 1);
     self::$f->applyMetaData($obj);
     $obj->meta()->key = 'value';
     $this->assertEquals('value', $obj->meta()->key);
     $this->assertTrue($obj->meta()->has('key'));
     $this->assertEquals(null, $obj->meta()->unknownKey);
     self::$f->saveMetaData($obj);
     self::$f->applyMetaData($obj);
     $obj->meta()->key = 'value';
     $this->assertEquals('value', $obj->meta()->key);
     $obj->meta()->key = null;
     $this->assertFalse($obj->meta()->has('key'));
     self::$f->saveMetaData($obj);
     self::$f->applyMetaData($obj);
     $this->assertNull($obj->meta()->key);
     $this->assertFalse($obj->meta()->has('key'));
 }
 /**
  * @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;
 }