Skip to content

Commit dff9abf

Browse files
committed
Add IteratorAggregate to *Pool and add getPackageName method into JavaClass
1 parent 4e53dff commit dff9abf

File tree

6 files changed

+44
-7
lines changed

6 files changed

+44
-7
lines changed

src/Core/JVM/AttributePool.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use PHPJava\Kernel\Attributes\AttributeInfo;
77
use PHPJava\Utilities\DebugTool;
88

9-
class AttributePool implements \ArrayAccess, \Countable
9+
class AttributePool implements \ArrayAccess, \Countable, \IteratorAggregate
1010
{
1111
private $entries = [];
1212
private $reader;
@@ -58,4 +58,9 @@ public function offsetUnset($offset)
5858
{
5959
throw new ReadOnlyException('You cannot rewrite datum. The Attribute Pool is read-only.');
6060
}
61+
62+
public function getIterator()
63+
{
64+
return new \ArrayIterator($this->entries);
65+
}
6166
}

src/Core/JVM/ConstantPool.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use PHPJava\Kernel\Structures\_Utf8;
2121
use PHPJava\Kernel\Structures\StructureInterface;
2222

23-
class ConstantPool implements \ArrayAccess, \Countable
23+
class ConstantPool implements \ArrayAccess, \Countable, \IteratorAggregate
2424
{
2525
private $entries = [];
2626
private $reader;
@@ -116,4 +116,9 @@ public function offsetUnset($offset)
116116
{
117117
throw new ReadOnlyException('You cannot rewrite datum. The Constant Pool is read-only.');
118118
}
119+
120+
public function getIterator()
121+
{
122+
return new \ArrayIterator($this->entries);
123+
}
119124
}

src/Core/JVM/FieldPool.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use PHPJava\Kernel\Structures\_FieldInfo;
88
use PHPJava\Utilities\DebugTool;
99

10-
class FieldPool implements \ArrayAccess, \Countable
10+
class FieldPool implements \ArrayAccess, \Countable, \IteratorAggregate
1111
{
1212
private $entries = [];
1313
private $reader;
@@ -56,4 +56,9 @@ public function offsetUnset($offset)
5656
{
5757
throw new ReadOnlyException('You cannot rewrite datum. The Field Pool is read-only.');
5858
}
59+
60+
public function getIterator()
61+
{
62+
return new \ArrayIterator($this->entries);
63+
}
5964
}

src/Core/JVM/InterfacePool.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use PHPJava\Exceptions\ReadOnlyException;
77
use PHPJava\Utilities\DebugTool;
88

9-
class InterfacePool implements \ArrayAccess, \Countable
9+
class InterfacePool implements \ArrayAccess, \Countable, \IteratorAggregate
1010
{
1111
private $entries = [];
1212
private $reader;
@@ -52,4 +52,9 @@ public function offsetUnset($offset)
5252
{
5353
throw new ReadOnlyException('You cannot rewrite datum. The Interface Pool is read-only.');
5454
}
55+
56+
public function getIterator()
57+
{
58+
return new \ArrayIterator($this->entries);
59+
}
5560
}

src/Core/JVM/MethodPool.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use PHPJava\Kernel\Structures\_MethodInfo;
77
use PHPJava\Utilities\DebugTool;
88

9-
class MethodPool implements \ArrayAccess, \Countable
9+
class MethodPool implements \ArrayAccess, \Countable, \IteratorAggregate
1010
{
1111
private $entries = [];
1212
private $reader;
@@ -55,4 +55,9 @@ public function offsetUnset($offset)
5555
{
5656
throw new ReadOnlyException('You cannot rewrite datum. The Interface Pool is read-only.');
5757
}
58+
59+
public function getIterator()
60+
{
61+
return new \ArrayIterator($this->entries);
62+
}
5863
}

src/Core/JavaClass.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPJava\Exceptions\ValidatorException;
1515
use PHPJava\Kernel\Attributes\AttributeInterface;
1616
use PHPJava\Kernel\Attributes\InnerClassesAttribute;
17+
use PHPJava\Kernel\Attributes\SourceFileAttribute;
1718
use PHPJava\Kernel\Maps\FieldAccessFlag;
1819
use PHPJava\Kernel\Structures\_Utf8;
1920
use PHPJava\Utilities\ClassResolver;
@@ -248,11 +249,22 @@ public function __destruct()
248249

249250
public function getClassName(bool $shortName = false): string
250251
{
252+
$className = $this->className->getString();
251253
if ($shortName === true) {
252-
$split = explode('$', $this->className->getString());
254+
$split = explode('$', $className);
253255
return $split[count($split) - 1];
254256
}
255-
return $this->className->getString();
257+
return $className;
258+
}
259+
260+
261+
public function getPackageName(): ?string
262+
{
263+
$className = dirname($this->className->getString());
264+
if ($className === '') {
265+
return null;
266+
}
267+
return str_replace('/', '.', $className);
256268
}
257269

258270
public function getInnerClasses(): array

0 commit comments

Comments
 (0)