Skip to content

Commit bfdc73d

Browse files
committed
add getDefaultParameters
1 parent 4ee0913 commit bfdc73d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Ubiquity/attributes/items/BaseAttribute.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ public function getNamespace(): string {
2727
return (new \ReflectionClass($this))->getNamespaceName();
2828
}
2929

30+
protected function getDefaultParameters(): array {
31+
$r = new \ReflectionMethod(get_class($this), '__construct');
32+
$result = [];
33+
foreach ($r->getParameters() as $param) {
34+
if ($param->isOptional() && $param->isDefaultValueAvailable()) {
35+
$result[$param->getName()] = $param->getDefaultValue();
36+
}
37+
}
38+
return $result;
39+
}
40+
3041
public function __toString(): string {
3142
$fields = $this->getPropertiesAndValues();
3243
$extsStr = UArray::asPhpAttribute($fields);

0 commit comments

Comments
 (0)