mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 09:35:28 +00:00
add nullable values support
This commit is contained in:
parent
59d1c8cb06
commit
04238c3d6c
2 changed files with 26 additions and 14 deletions
|
|
@ -20,7 +20,7 @@ interface Pool
|
||||||
|
|
||||||
public function set(
|
public function set(
|
||||||
string $key,
|
string $key,
|
||||||
string $value = '',
|
?string $value = null,
|
||||||
string $flags = 'c',
|
string $flags = 'c',
|
||||||
int $offset = 0,
|
int $offset = 0,
|
||||||
int $mode = 0644,
|
int $mode = 0644,
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,11 @@ class Pool implements \Yggverse\Yoda\Interface\Model\Pool
|
||||||
int $count = 0
|
int $count = 0
|
||||||
): ?string
|
): ?string
|
||||||
{
|
{
|
||||||
if (isset($this->_data[$key]))
|
if (empty($this->_data[$key]))
|
||||||
{
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return shmop_read(
|
return shmop_read(
|
||||||
$this->_data[$key],
|
$this->_data[$key],
|
||||||
$start,
|
$start,
|
||||||
|
|
@ -35,18 +38,24 @@ class Pool implements \Yggverse\Yoda\Interface\Model\Pool
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set(
|
public function set(
|
||||||
string $key,
|
string $key,
|
||||||
string $value = '',
|
?string $value = null,
|
||||||
string $flags = 'c',
|
string $flags = 'c',
|
||||||
int $offset = 0,
|
int $offset = 0,
|
||||||
int $mode = 0644,
|
int $mode = 0644,
|
||||||
?string $encoding = null
|
?string $encoding = null
|
||||||
): int
|
): int
|
||||||
{
|
{
|
||||||
|
if (empty($value))
|
||||||
|
{
|
||||||
|
// @TODO delete from memory
|
||||||
|
|
||||||
|
$this->_data[$key] = null;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->_data[$key] = shmop_open(crc32($this->_namespace . $key), $flags, $mode, mb_strlen($value, $encoding)))
|
if ($this->_data[$key] = shmop_open(crc32($this->_namespace . $key), $flags, $mode, mb_strlen($value, $encoding)))
|
||||||
{
|
{
|
||||||
return shmop_write(
|
return shmop_write(
|
||||||
|
|
@ -62,11 +71,14 @@ class Pool implements \Yggverse\Yoda\Interface\Model\Pool
|
||||||
public function reset(): void
|
public function reset(): void
|
||||||
{
|
{
|
||||||
foreach ($this->_data as $data)
|
foreach ($this->_data as $data)
|
||||||
|
{
|
||||||
|
if ($data)
|
||||||
{
|
{
|
||||||
shmop_delete(
|
shmop_delete(
|
||||||
$data
|
$data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->_data = [];
|
$this->_data = [];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue