Gc\Session\SaveHandler\DbTableGateway::read PHP Method

read() public method

Read session data
public read ( string $id ) : string
$id string Id
return string
    public function read($id)
    {
        $rows = $this->tableGateway->select(array($this->options->getIdColumn() => $id, $this->options->getNameColumn() => $this->sessionName));
        if ($row = $rows->current()) {
            if ($row->{$this->options->getModifiedColumn()} + $row->{$this->options->getLifetimeColumn()} > time()) {
                return base64_decode($row->{$this->options->getDataColumn()});
            }
            $this->destroy($id);
        }
        return '';
    }

Usage Example

Example #1
0
 /**
  * Test
  *
  * @return void
  */
 public function testReadWithLifetimeExpired()
 {
     $this->object->open('savepath', 'sessionname');
     $id = '242';
     $this->assertTrue($this->object->write($id, serialize($this->testArray)));
     $this->adapter->update(array('lifetime' => 0), array('id' => $id));
     $data = $this->object->read($id);
     $this->assertEquals('', $data);
 }
DbTableGateway