mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
init shared memory buffer for async operations
This commit is contained in:
parent
d67589568c
commit
7212e44314
2 changed files with 136 additions and 31 deletions
|
|
@ -4,107 +4,183 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Yggverse\Yoda\Abstract\Model;
|
namespace Yggverse\Yoda\Abstract\Model;
|
||||||
|
|
||||||
|
use \Yggverse\Yoda\Model\Buffer;
|
||||||
|
|
||||||
abstract class Connection implements \Yggverse\Yoda\Interface\Model\Connection
|
abstract class Connection implements \Yggverse\Yoda\Interface\Model\Connection
|
||||||
{
|
{
|
||||||
// Status
|
private Buffer $_buffer;
|
||||||
private bool $_completed = false;
|
|
||||||
|
|
||||||
// Response
|
public function __construct(
|
||||||
private ?string $_title = null;
|
Buffer $buffer
|
||||||
private ?string $_subtitle = null;
|
) {
|
||||||
private ?string $_tooltip = null;
|
// Use shared memory for async operations
|
||||||
private ?string $_mime = null;
|
$this->_buffer = $buffer;
|
||||||
private ?string $_data = null;
|
|
||||||
private ?string $_redirect = null;
|
// Set defaults
|
||||||
private ?array $_request = null;
|
$this->_buffer->set(
|
||||||
|
'completed',
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->_buffer->set(
|
||||||
|
'title',
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->_buffer->set(
|
||||||
|
'subtitle',
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->_buffer->set(
|
||||||
|
'tooltip',
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->_buffer->set(
|
||||||
|
'mime',
|
||||||
|
null
|
||||||
|
);
|
||||||
|
$this->_buffer->set(
|
||||||
|
'data',
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->_buffer->set(
|
||||||
|
'redirect',
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->_buffer->set(
|
||||||
|
'request',
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function isCompleted(): bool
|
public function isCompleted(): bool
|
||||||
{
|
{
|
||||||
return $this->_completed;
|
return $this->_buffer->get(
|
||||||
|
'completed'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCompleted(
|
public function setCompleted(
|
||||||
bool $completed
|
bool $completed
|
||||||
): void
|
): void
|
||||||
{
|
{
|
||||||
$this->_completed = $completed;
|
$this->_buffer->set(
|
||||||
|
'completed',
|
||||||
|
$completed
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTitle(): ?string
|
public function getTitle(): ?string
|
||||||
{
|
{
|
||||||
return $this->_title;
|
return $this->_buffer->get(
|
||||||
|
'title'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTitle(
|
public function setTitle(
|
||||||
?string $title = null
|
?string $title = null
|
||||||
): void
|
): void
|
||||||
{
|
{
|
||||||
$this->_title = $title;
|
$this->_buffer->set(
|
||||||
|
'title',
|
||||||
|
$title
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSubtitle(): ?string
|
public function getSubtitle(): ?string
|
||||||
{
|
{
|
||||||
return $this->_subtitle;
|
return $this->_buffer->get(
|
||||||
|
'subtitle'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSubtitle(
|
public function setSubtitle(
|
||||||
?string $subtitle = null
|
?string $subtitle = null
|
||||||
): void
|
): void
|
||||||
{
|
{
|
||||||
$this->_subtitle = $subtitle;
|
$this->_buffer->set(
|
||||||
|
'subtitle',
|
||||||
|
$subtitle
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTooltip(): ?string
|
public function getTooltip(): ?string
|
||||||
{
|
{
|
||||||
return $this->_tooltip;
|
return $this->_buffer->get(
|
||||||
|
'tooltip'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTooltip(
|
public function setTooltip(
|
||||||
?string $tooltip = null
|
?string $tooltip = null
|
||||||
): void
|
): void
|
||||||
{
|
{
|
||||||
$this->_tooltip = $tooltip;
|
$this->_buffer->set(
|
||||||
|
'tooltip',
|
||||||
|
$tooltip
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMime(): ?string
|
public function getMime(): ?string
|
||||||
{
|
{
|
||||||
return $this->_mime;
|
return $this->_buffer->get(
|
||||||
|
'mime'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setMime(
|
public function setMime(
|
||||||
?string $mime = null
|
?string $mime = null
|
||||||
): void
|
): void
|
||||||
{
|
{
|
||||||
$this->_mime = $mime;
|
$this->_buffer->set(
|
||||||
|
'mime',
|
||||||
|
$mime
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getData(): ?string
|
public function getData(): ?string
|
||||||
{
|
{
|
||||||
return $this->_data;
|
return $this->_buffer->get(
|
||||||
|
'data'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setData(
|
public function setData(
|
||||||
?string $data = null
|
?string $data = null
|
||||||
): void
|
): void
|
||||||
{
|
{
|
||||||
$this->_data = $data;
|
$this->_buffer->set(
|
||||||
|
'data',
|
||||||
|
$data
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRedirect(): ?string
|
public function getRedirect(): ?string
|
||||||
{
|
{
|
||||||
return $this->_redirect;
|
return $this->_buffer->get(
|
||||||
|
'redirect'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setRedirect(
|
public function setRedirect(
|
||||||
?string $redirect = null
|
?string $redirect = null
|
||||||
): void
|
): void
|
||||||
{
|
{
|
||||||
$this->_redirect = $redirect;
|
$this->_buffer->set(
|
||||||
|
'redirect',
|
||||||
|
$redirect
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRequest(): ?array
|
public function getRequest(): ?array
|
||||||
{
|
{
|
||||||
return $this->_request;
|
return $this->_buffer->get(
|
||||||
|
'request'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setRequest(
|
public function setRequest(
|
||||||
|
|
@ -112,21 +188,29 @@ abstract class Connection implements \Yggverse\Yoda\Interface\Model\Connection
|
||||||
bool $visible = true
|
bool $visible = true
|
||||||
): void
|
): void
|
||||||
{
|
{
|
||||||
$this->_request = [
|
$this->_buffer->set(
|
||||||
'placeholder' => $placeholder,
|
'request',
|
||||||
'visible' => $visible
|
[
|
||||||
];
|
'placeholder' => $placeholder,
|
||||||
|
'visible' => $visible
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unsetRequest(): void
|
public function unsetRequest(): void
|
||||||
{
|
{
|
||||||
$this->_request = null;
|
$this->_buffer->set(
|
||||||
|
'request',
|
||||||
|
null
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLength(): ?int
|
public function getLength(): ?int
|
||||||
{
|
{
|
||||||
return mb_strlen(
|
return mb_strlen(
|
||||||
$this->_data
|
$this->_buffer->get(
|
||||||
|
'data'
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
21
src/Interface/Model/Buffer.php
Normal file
21
src/Interface/Model/Buffer.php
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Yggverse\Yoda\Interface\Model;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Shared memory API for async operations
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
interface Buffer
|
||||||
|
{
|
||||||
|
public function get(
|
||||||
|
string $key
|
||||||
|
): mixed;
|
||||||
|
|
||||||
|
public function set(
|
||||||
|
string $key,
|
||||||
|
mixed $value
|
||||||
|
): void;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue