Browse Source

add nullable values support

PHP-GTK3
yggverse 5 months ago
parent
commit
04238c3d6c
  1. 2
      src/Interface/Model/Pool.php
  2. 22
      src/Model/Pool.php

2
src/Interface/Model/Pool.php

@ -20,7 +20,7 @@ interface Pool @@ -20,7 +20,7 @@ interface Pool
public function set(
string $key,
string $value = '',
?string $value = null,
string $flags = 'c',
int $offset = 0,
int $mode = 0644,

22
src/Model/Pool.php

@ -24,8 +24,11 @@ class Pool implements \Yggverse\Yoda\Interface\Model\Pool @@ -24,8 +24,11 @@ class Pool implements \Yggverse\Yoda\Interface\Model\Pool
int $count = 0
): ?string
{
if (isset($this->_data[$key]))
if (empty($this->_data[$key]))
{
return null;
}
return shmop_read(
$this->_data[$key],
$start,
@ -35,18 +38,24 @@ class Pool implements \Yggverse\Yoda\Interface\Model\Pool @@ -35,18 +38,24 @@ class Pool implements \Yggverse\Yoda\Interface\Model\Pool
);
}
return null;
}
public function set(
string $key,
string $value = '',
?string $value = null,
string $flags = 'c',
int $offset = 0,
int $mode = 0644,
?string $encoding = null
): 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)))
{
return shmop_write(
@ -62,11 +71,14 @@ class Pool implements \Yggverse\Yoda\Interface\Model\Pool @@ -62,11 +71,14 @@ class Pool implements \Yggverse\Yoda\Interface\Model\Pool
public function reset(): void
{
foreach ($this->_data as $data)
{
if ($data)
{
shmop_delete(
$data
);
}
}
$this->_data = [];
}

Loading…
Cancel
Save