philips-cnc6600-interpreter/src/Machine/Memory/ToolMemory.php

34 lines
523 B
PHP
Raw Normal View History

2020-05-08 00:37:29 +02:00
<?php
namespace Machine\Memory;
2020-05-08 00:37:29 +02:00
use InvalidArgumentException;
use Tool\Tool;
2020-05-08 00:37:29 +02:00
class ToolMemory
{
/** @var Tool[] */
2020-05-08 00:37:29 +02:00
private array $memory = [];
public function write(Tool $tool): void
2020-05-08 00:37:29 +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
2020-05-08 00:37:29 +02:00
{
return @$this->memory[$T];
}
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
}