diff --git a/composer.json b/composer.json index f2515c7f..d8e51e77 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "JVM emulator by PHP", "type": "library", "license": "MIT", - "version": "0.0.7.0-dev", + "version": "0.0.7.1-dev", "authors": [ { "name": "memory" diff --git a/src/Core/JVM/AttributePool.php b/src/Core/JVM/AttributePool.php index 475aee11..4e8316bc 100644 --- a/src/Core/JVM/AttributePool.php +++ b/src/Core/JVM/AttributePool.php @@ -6,7 +6,7 @@ use PHPJava\Kernel\Attributes\AttributeInfo; use PHPJava\Utilities\DebugTool; -class AttributePool implements \ArrayAccess, \Countable +class AttributePool implements \ArrayAccess, \Countable, \IteratorAggregate { private $entries = []; private $reader; @@ -58,4 +58,9 @@ public function offsetUnset($offset) { throw new ReadOnlyException('You cannot rewrite datum. The Attribute Pool is read-only.'); } + + public function getIterator() + { + return new \ArrayIterator($this->entries); + } } diff --git a/src/Core/JVM/ConstantPool.php b/src/Core/JVM/ConstantPool.php index 62fa6478..69a4cef2 100644 --- a/src/Core/JVM/ConstantPool.php +++ b/src/Core/JVM/ConstantPool.php @@ -20,7 +20,7 @@ use PHPJava\Kernel\Structures\_Utf8; use PHPJava\Kernel\Structures\StructureInterface; -class ConstantPool implements \ArrayAccess, \Countable +class ConstantPool implements \ArrayAccess, \Countable, \IteratorAggregate { private $entries = []; private $reader; @@ -116,4 +116,9 @@ public function offsetUnset($offset) { throw new ReadOnlyException('You cannot rewrite datum. The Constant Pool is read-only.'); } + + public function getIterator() + { + return new \ArrayIterator($this->entries); + } } diff --git a/src/Core/JVM/FieldPool.php b/src/Core/JVM/FieldPool.php index 7d09a121..94a75d37 100644 --- a/src/Core/JVM/FieldPool.php +++ b/src/Core/JVM/FieldPool.php @@ -7,7 +7,7 @@ use PHPJava\Kernel\Structures\_FieldInfo; use PHPJava\Utilities\DebugTool; -class FieldPool implements \ArrayAccess, \Countable +class FieldPool implements \ArrayAccess, \Countable, \IteratorAggregate { private $entries = []; private $reader; @@ -56,4 +56,9 @@ public function offsetUnset($offset) { throw new ReadOnlyException('You cannot rewrite datum. The Field Pool is read-only.'); } + + public function getIterator() + { + return new \ArrayIterator($this->entries); + } } diff --git a/src/Core/JVM/InterfacePool.php b/src/Core/JVM/InterfacePool.php index 87757024..a2a66ca0 100644 --- a/src/Core/JVM/InterfacePool.php +++ b/src/Core/JVM/InterfacePool.php @@ -6,7 +6,7 @@ use PHPJava\Exceptions\ReadOnlyException; use PHPJava\Utilities\DebugTool; -class InterfacePool implements \ArrayAccess, \Countable +class InterfacePool implements \ArrayAccess, \Countable, \IteratorAggregate { private $entries = []; private $reader; @@ -52,4 +52,9 @@ public function offsetUnset($offset) { throw new ReadOnlyException('You cannot rewrite datum. The Interface Pool is read-only.'); } + + public function getIterator() + { + return new \ArrayIterator($this->entries); + } } diff --git a/src/Core/JVM/MethodPool.php b/src/Core/JVM/MethodPool.php index 790ae25d..dc874542 100644 --- a/src/Core/JVM/MethodPool.php +++ b/src/Core/JVM/MethodPool.php @@ -6,7 +6,7 @@ use PHPJava\Kernel\Structures\_MethodInfo; use PHPJava\Utilities\DebugTool; -class MethodPool implements \ArrayAccess, \Countable +class MethodPool implements \ArrayAccess, \Countable, \IteratorAggregate { private $entries = []; private $reader; @@ -55,4 +55,9 @@ public function offsetUnset($offset) { throw new ReadOnlyException('You cannot rewrite datum. The Interface Pool is read-only.'); } + + public function getIterator() + { + return new \ArrayIterator($this->entries); + } } diff --git a/src/Core/JavaClass.php b/src/Core/JavaClass.php index cc8f6ab0..c4c117c8 100644 --- a/src/Core/JavaClass.php +++ b/src/Core/JavaClass.php @@ -14,6 +14,7 @@ use PHPJava\Exceptions\ValidatorException; use PHPJava\Kernel\Attributes\AttributeInterface; use PHPJava\Kernel\Attributes\InnerClassesAttribute; +use PHPJava\Kernel\Attributes\SourceFileAttribute; use PHPJava\Kernel\Maps\FieldAccessFlag; use PHPJava\Kernel\Structures\_Utf8; use PHPJava\Utilities\ClassResolver; @@ -248,11 +249,22 @@ public function __destruct() public function getClassName(bool $shortName = false): string { + $className = $this->className->getString(); if ($shortName === true) { - $split = explode('$', $this->className->getString()); + $split = explode('$', $className); return $split[count($split) - 1]; } - return $this->className->getString(); + return $className; + } + + + public function getPackageName(): ?string + { + $className = dirname($this->className->getString()); + if ($className === '') { + return null; + } + return str_replace('/', '.', $className); } public function getInnerClasses(): array diff --git a/src/Core/PHPJava.php b/src/Core/PHPJava.php index 8bc91468..3b63ca73 100644 --- a/src/Core/PHPJava.php +++ b/src/Core/PHPJava.php @@ -12,5 +12,5 @@ final class PHPJava /** * As same as composer version. */ - const VERSION = 0x000070; + const VERSION = 0x000071; }