diff --git a/CHANGELOG.md b/CHANGELOG.md
index cd369fc..dc371be 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,9 @@ Yii Framework 2 apidoc extension Change Log
- Enh #347: Add PHPDoc types for class properties (mspirkov)
- Enh #348: Inherit descriptions of the parent class (mspirkov)
- Enh #349: Add support for constants in interfaces and traits (mspirkov)
+- Enh #349: Add inheritance of constants in interfaces (mspirkov)
+- Enh #349: Add inheritance of trait constants in classes (mspirkov)
+- Enh #261: Add inheritance of interface constants in classes (mspirkov)
3.0.8 November 24, 2025
diff --git a/models/Context.php b/models/Context.php
index 5e52708..9e3b33a 100644
--- a/models/Context.php
+++ b/models/Context.php
@@ -146,21 +146,7 @@ public function updateReferences()
}
// update implementedBy and usedBy for interfaces
foreach ($this->classes as $class) {
- foreach ($class->interfaces as $interface) {
- if (!isset($this->interfaces[$interface])) {
- continue;
- }
- $this->interfaces[$interface]->implementedBy[] = $class->name;
- if (!$class->isAbstract) {
- continue;
- }
- // add not implemented interface methods
- foreach ($this->interfaces[$interface]->methods as $method) {
- if (!isset($class->methods[$method->name])) {
- $class->methods[$method->name] = $method;
- }
- }
- }
+ $this->handleInterfaceInheritance($class);
}
foreach ($this->interfaces as $interface) {
$this->updateSubInterfaceInheritance($interface);
@@ -228,6 +214,41 @@ protected function handleTraitInheritance($class)
$class->methods[$method->name] = $method;
}
}
+
+ foreach ($trait->constants as $constant) {
+ if (!isset($class->constants[$constant->name])) {
+ $class->constants[$constant->name] = $constant;
+ }
+ }
+ }
+ }
+
+ /**
+ * @param ClassDoc $class
+ */
+ private function handleInterfaceInheritance($class)
+ {
+ foreach ($class->interfaces as $interface) {
+ if (!isset($this->interfaces[$interface])) {
+ continue;
+ }
+
+ $this->interfaces[$interface]->implementedBy[] = $class->name;
+
+ foreach ($this->interfaces[$interface]->constants as $constant) {
+ if (!isset($class->constants[$constant->name])) {
+ $class->constants[$constant->name] = $constant;
+ }
+ }
+
+ // add not implemented interface methods
+ if ($class->isAbstract) {
+ foreach ($this->interfaces[$interface]->methods as $method) {
+ if (!isset($class->methods[$method->name])) {
+ $class->methods[$method->name] = $method;
+ }
+ }
+ }
}
}
@@ -274,6 +295,7 @@ protected function updateSubInterfaceInheritance($interface)
$subInterface = $this->interfaces[$name];
$subInterface->methods = array_merge($interface->methods, $subInterface->methods);
+ $subInterface->constants = array_merge($interface->constants, $subInterface->constants);
$this->updateSubInterfaceInheritance($subInterface);
}
}
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__10.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__10.html
index ee20b8f..4aaa242 100644
--- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__10.html
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__10.html
@@ -63,6 +63,8 @@
AssetBundle
AssetManager
ErrorAction
+SomeInterface
+SomeSubInterface
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__11.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__11.html
index aa59f42..d108c04 100644
--- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__11.html
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__11.html
@@ -63,6 +63,8 @@
AssetBundle
AssetManager
ErrorAction
+
SomeInterface
+
SomeSubInterface
@@ -209,6 +211,22 @@
Constants
Defined By |
+
+ | FIRST_CONST |
+ 'firstConst' |
+
+
+ |
+ yiiunit\apidoc\data\api\db\ActiveQueryInterface |
+
+
+ | SECOND_CONST |
+ 'secondConst' |
+
+
+ |
+ yiiunit\apidoc\data\api\db\ActiveQueryInterface |
+
| SOME_CLASS_CONST |
'someClassConst' |
@@ -216,6 +234,14 @@ Constants
yiiunit\apidoc\data\api\db\ActiveQuery |
+
+
+ | SOME_TRAIT_CONST |
+ 'someTraitConst' |
+
+
+ |
+ yiiunit\apidoc\data\api\db\ActiveRelationTrait |
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__12.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__12.html
index 9f494ca..259b1ba 100644
--- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__12.html
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__12.html
@@ -63,6 +63,8 @@
AssetBundle
AssetManager
ErrorAction
+SomeInterface
+SomeSubInterface
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__13.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__13.html
index 538b36d..2b1d429 100644
--- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__13.html
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__13.html
@@ -63,6 +63,8 @@
AssetBundle
AssetManager
ErrorAction
+
SomeInterface
+
SomeSubInterface
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__14.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__14.html
index 35cfcee..f102416 100644
--- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__14.html
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__14.html
@@ -63,6 +63,8 @@
AssetBundle
AssetManager
ErrorAction
+
SomeInterface
+
SomeSubInterface
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__15.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__15.html
index c3418cb..7128ee8 100644
--- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__15.html
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__15.html
@@ -63,6 +63,8 @@
AssetBundle
AssetManager
ErrorAction
+
SomeInterface
+
SomeSubInterface
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__16.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__16.html
index 8eb527c..8fd29b4 100644
--- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__16.html
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__16.html
@@ -63,6 +63,8 @@
AssetBundle
AssetManager
ErrorAction
+
SomeInterface
+
SomeSubInterface
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__17.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__17.html
index f48e0c7..acd1eea 100644
--- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__17.html
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__17.html
@@ -63,6 +63,8 @@
AssetBundle
AssetManager
ErrorAction
+
SomeInterface
+
SomeSubInterface
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__18.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__18.html
index c231c94..911e53d 100644
--- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__18.html
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__18.html
@@ -63,6 +63,8 @@
AssetBundle
AssetManager
ErrorAction
+
SomeInterface
+
SomeSubInterface
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__19.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__19.html
index 22e5dde..a227df2 100644
--- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__19.html
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__19.html
@@ -63,6 +63,8 @@
AssetBundle
AssetManager
ErrorAction
+
SomeInterface
+
SomeSubInterface
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__20.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__20.html
index a561eb9..5da6b3d 100644
--- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__20.html
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__20.html
@@ -63,6 +63,8 @@
AssetBundle
AssetManager
ErrorAction
+
SomeInterface
+
SomeSubInterface
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__21.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__21.html
new file mode 100644
index 0000000..7bf03db
--- /dev/null
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__21.html
@@ -0,0 +1,321 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
SomeInterface, yiiunit\apidoc\data\api\web\SomeInterface - Yii Framework 2.0 API Documentation
+
+
+
+
+
+
+
+
+
+
+
+
Interface yiiunit\apidoc\data\api\web\SomeInterface
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Method Details
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__22.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__22.html
new file mode 100644
index 0000000..9a75a7c
--- /dev/null
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__22.html
@@ -0,0 +1,332 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
SomeSubInterface, yiiunit\apidoc\data\api\web\SomeSubInterface - Yii Framework 2.0 API Documentation
+
+
+
+
+
+
+
+
+
+
+
+
Interface yiiunit\apidoc\data\api\web\SomeSubInterface
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Method Details
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__3.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__3.html
index 6ffc504..32701a3 100644
--- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__3.html
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__3.html
@@ -63,6 +63,8 @@
AssetBundle
AssetManager
ErrorAction
+
SomeInterface
+
SomeSubInterface
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__4.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__4.html
index 032bd69..655346e 100644
--- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__4.html
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__4.html
@@ -63,6 +63,8 @@
AssetBundle
AssetManager
ErrorAction
+
SomeInterface
+
SomeSubInterface
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__5.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__5.html
index 772f737..567c490 100644
--- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__5.html
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__5.html
@@ -63,6 +63,8 @@
AssetBundle
AssetManager
ErrorAction
+
SomeInterface
+
SomeSubInterface
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__6.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__6.html
index ebe2746..4e53c38 100644
--- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__6.html
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__6.html
@@ -63,6 +63,8 @@
AssetBundle
AssetManager
ErrorAction
+
SomeInterface
+
SomeSubInterface
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__7.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__7.html
index f4f7dd1..4857577 100644
--- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__7.html
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__7.html
@@ -63,6 +63,8 @@
AssetBundle
AssetManager
ErrorAction
+
SomeInterface
+
SomeSubInterface
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__8.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__8.html
index ed629ef..325751d 100644
--- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__8.html
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__8.html
@@ -63,6 +63,8 @@
AssetBundle
AssetManager
ErrorAction
+
SomeInterface
+
SomeSubInterface
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__9.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__9.html
index b12dc46..db7f1f5 100644
--- a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__9.html
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__9.html
@@ -63,6 +63,8 @@
AssetBundle
AssetManager
ErrorAction
+
SomeInterface
+
SomeSubInterface
diff --git a/tests/data/api/web/SomeInterface.php b/tests/data/api/web/SomeInterface.php
new file mode 100644
index 0000000..b63e2ae
--- /dev/null
+++ b/tests/data/api/web/SomeInterface.php
@@ -0,0 +1,22 @@
+