lithium\storage\session\strategy\Encrypt::delete PHP Метод

delete() публичный Метод

Delete encryption method.
public delete ( mixed $data, array $options = [] ) : string
$data mixed The data to be encrypted.
$options array Options for this method.
Результат string Returns the deleted data in cleartext.
    public function delete($data, array $options = array())
    {
        $class = $options['class'];
        $futureData = $this->read(null, array('key' => null) + $options) ?: array();
        unset($futureData[$options['key']]);
        $payload = empty($futureData) ? null : $this->_encrypt($futureData);
        $class::write('__encrypted', $payload, array('strategies' => false) + $options);
        return $data;
    }

Usage Example

 public function testDelete()
 {
     $encrypt = new Encrypt(array('secret' => $this->secret));
     $key = 'fookey';
     $value = 'barvalue';
     $result = $encrypt->write($value, array('class' => $this->mock, 'key' => $key));
     $this->assertTrue($result);
     $cookie = MockCookieSession::data();
     $result = $encrypt->read($key, array('class' => $this->mock, 'key' => $key));
     $this->assertEqual($value, $result);
     $result = $encrypt->delete($key, array('class' => $this->mock, 'key' => $key));
     $cookie = MockCookieSession::data();
     $this->assertTrue(empty($cookie['__encrypted']));
     $result = $encrypt->read($key, array('class' => $this->mock));
     $this->assertFalse($result);
 }