|
|
@ -18,12 +18,39 @@ class Pool implements \Yggverse\Yoda\Interface\Model\Pool |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function get( |
|
|
|
public function init( |
|
|
|
|
|
|
|
string $key, |
|
|
|
|
|
|
|
int $size = 0xfffff, |
|
|
|
|
|
|
|
string $flags = 'c', |
|
|
|
|
|
|
|
int $mode = 0644, |
|
|
|
|
|
|
|
): ?\Shmop |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (isset($this->_data[$key])) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
throw new \Exception; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this->_data[$key] = shmop_open( |
|
|
|
|
|
|
|
crc32( |
|
|
|
|
|
|
|
$this->_namespace . $key |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
$flags, |
|
|
|
|
|
|
|
$mode, |
|
|
|
|
|
|
|
$size |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function read( |
|
|
|
string $key, |
|
|
|
string $key, |
|
|
|
int $start = 0, |
|
|
|
int $start = 0, |
|
|
|
int $count = 0 |
|
|
|
int $count = 0 |
|
|
|
): ?string |
|
|
|
): ?string |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (!isset($this->_data[$key])) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
throw new \Exception; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (empty($this->_data[$key])) |
|
|
|
if (empty($this->_data[$key])) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return null; |
|
|
|
return null; |
|
|
@ -38,26 +65,17 @@ class Pool implements \Yggverse\Yoda\Interface\Model\Pool |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function set( |
|
|
|
public function write( |
|
|
|
string $key, |
|
|
|
string $key, |
|
|
|
?string $value = null, |
|
|
|
string $value, |
|
|
|
string $flags = 'c', |
|
|
|
int $offset = 0 |
|
|
|
int $offset = 0, |
|
|
|
|
|
|
|
int $mode = 0644, |
|
|
|
|
|
|
|
?string $encoding = null |
|
|
|
|
|
|
|
): int |
|
|
|
): int |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (empty($value)) |
|
|
|
if (!isset($this->_data[$key])) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// @TODO delete from memory |
|
|
|
throw new \Exception; |
|
|
|
|
|
|
|
|
|
|
|
$this->_data[$key] = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($this->_data[$key] = shmop_open(crc32($this->_namespace . $key), $flags, $mode, mb_strlen($value, $encoding))) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return shmop_write( |
|
|
|
return shmop_write( |
|
|
|
$this->_data[$key], |
|
|
|
$this->_data[$key], |
|
|
|
$value, |
|
|
|
$value, |
|
|
@ -65,19 +83,57 @@ class Pool implements \Yggverse\Yoda\Interface\Model\Pool |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function delete( |
|
|
|
|
|
|
|
string $key |
|
|
|
|
|
|
|
): bool |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!isset($this->_data[$key])) |
|
|
|
|
|
|
|
{ |
|
|
|
throw new \Exception; |
|
|
|
throw new \Exception; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function reset(): void |
|
|
|
$result = shmop_delete( |
|
|
|
{ |
|
|
|
$this->_data[$key] |
|
|
|
foreach ($this->_data as $data) |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->_data[$key] = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function get( |
|
|
|
|
|
|
|
string $key |
|
|
|
|
|
|
|
): string |
|
|
|
{ |
|
|
|
{ |
|
|
|
if ($data) |
|
|
|
return trim( |
|
|
|
|
|
|
|
strval( |
|
|
|
|
|
|
|
$this->read( |
|
|
|
|
|
|
|
$key |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function set( |
|
|
|
|
|
|
|
string $key, |
|
|
|
|
|
|
|
?string $value = null |
|
|
|
|
|
|
|
): void |
|
|
|
{ |
|
|
|
{ |
|
|
|
shmop_delete( |
|
|
|
$this->write( |
|
|
|
$data |
|
|
|
$key, |
|
|
|
|
|
|
|
strval( |
|
|
|
|
|
|
|
$value |
|
|
|
|
|
|
|
) |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function reset(): void |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
foreach ($this->_data as $key => $shmop) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$this->delete( |
|
|
|
|
|
|
|
$key |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$this->_data = []; |
|
|
|
$this->_data = []; |
|
|
|