2020-05-08 00:37:29 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Automata\Storage;
|
|
|
|
|
|
|
|
use Automata\Tool;
|
2020-05-10 13:55:25 +02:00
|
|
|
use InvalidArgumentException;
|
2020-05-08 00:37:29 +02:00
|
|
|
|
|
|
|
class ToolMemory
|
|
|
|
{
|
|
|
|
/** @var Tool[] */
|
|
|
|
private array $memory = [];
|
|
|
|
|
|
|
|
|
|
|
|
public function save(Tool $tool): void
|
|
|
|
{
|
2020-05-10 13:55:25 +02:00
|
|
|
$this->guardInvalidToolNumber($tool->T);
|
2020-05-08 00:37:29 +02:00
|
|
|
$this->memory[$tool->T] = $tool;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function read(int $T): ?Tool
|
|
|
|
{
|
|
|
|
return @$this->memory[$T];
|
|
|
|
}
|
2020-05-10 13:55:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
private function guardInvalidToolNumber(int $T): void
|
|
|
|
{
|
|
|
|
if ($T < 1 || $T > 64) {
|
|
|
|
throw new InvalidArgumentException('Tool number must be in range 1 - 64');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-08 00:37:29 +02:00
|
|
|
}
|