|
| 1 | +<?php |
| 2 | +namespace PHPJava\Core\JVM; |
| 3 | + |
| 4 | +use PHPJava\Core\Stream\Reader\ReaderInterface; |
| 5 | +use PHPJava\Exceptions\ReadOnlyException; |
| 6 | +use PHPJava\Kernel\Attributes\AttributeInfo; |
| 7 | +use PHPJava\Utilities\DebugTool; |
| 8 | + |
| 9 | +class AttributePool implements \ArrayAccess, \Countable |
| 10 | +{ |
| 11 | + private $entries = []; |
| 12 | + private $reader; |
| 13 | + |
| 14 | + public function __construct( |
| 15 | + ReaderInterface $reader, |
| 16 | + int $entries, |
| 17 | + ConstantPool $constantPool, |
| 18 | + DebugTool $debugTool |
| 19 | + ) { |
| 20 | + $this->reader = $reader; |
| 21 | + for ($i = 0; $i < $entries; $i++) { |
| 22 | + // not implemented, read only |
| 23 | + $entry = (new AttributeInfo($reader)) |
| 24 | + ->setConstantPool($constantPool) |
| 25 | + ->setDebugTool($debugTool); |
| 26 | + $entry->execute(); |
| 27 | + |
| 28 | + $this->entries[] = $entry; |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + public function getEntries() |
| 33 | + { |
| 34 | + return $this->entries; |
| 35 | + } |
| 36 | + |
| 37 | + public function offsetExists($offset) |
| 38 | + { |
| 39 | + return isset($this->entries[$offset]); |
| 40 | + } |
| 41 | + |
| 42 | + public function offsetGet($offset) |
| 43 | + { |
| 44 | + return $this->entries[$offset]; |
| 45 | + } |
| 46 | + |
| 47 | + public function count() |
| 48 | + { |
| 49 | + return count($this->entries); |
| 50 | + } |
| 51 | + |
| 52 | + public function offsetSet($offset, $value) |
| 53 | + { |
| 54 | + throw new ReadOnlyException('You cannot rewrite datum. The Attribute Pool is read-only.'); |
| 55 | + } |
| 56 | + |
| 57 | + public function offsetUnset($offset) |
| 58 | + { |
| 59 | + throw new ReadOnlyException('You cannot rewrite datum. The Attribute Pool is read-only.'); |
| 60 | + } |
| 61 | +} |
0 commit comments