@@ -46,6 +46,11 @@ inference, dynamic method resolution, and comprehensive property reflection.
46
46
- Support for custom component configurations.
47
47
- User component with ` identity ` , ` id ` , ` isGuest ` property types.
48
48
49
+ ✅ ** Behavior Integration**
50
+ - Behavior configuration via ServiceMap (see the Behaviors section below).
51
+ - Hierarchical type resolution: model properties take precedence over behavior properties.
52
+ - Property and method resolution from attached behaviors.
53
+
49
54
✅ ** Dependency Injection Container**
50
55
- Service map integration for custom services.
51
56
- Support for closures, singletons, and nested definitions.
@@ -102,6 +107,13 @@ Create a PHPStan-specific config file (`config/phpstan-config.php`).
102
107
declare(strict_types=1);
103
108
104
109
return [
110
+ // PHPStan only: used by this extension for behavior property/method type inference
111
+ 'behaviors' => [
112
+ app\models\User::class => [
113
+ app\behaviors\SoftDeleteBehavior::class,
114
+ yii\behaviors\TimestampBehavior::class,
115
+ ],
116
+ ],
105
117
'components' => [
106
118
'db' => [
107
119
'class' => yii\db\Connection::class,
@@ -161,6 +173,38 @@ if (Yii::$app->user->isGuest === false) {
161
173
}
162
174
```
163
175
176
+ #### Behaviors
177
+
178
+ ``` php
179
+ // Behaviors are attached via the `phpstan-config.php` behaviors map (PHPStan only)
180
+
181
+ /**
182
+ * @property string $slug
183
+ * @property-read int $created_at
184
+ *
185
+ * Note: `created_at` is provided by `TimestampBehavior`.
186
+ */
187
+ class SoftDeleteBehavior extends \yii\base\Behavior
188
+ {
189
+ public function softDelete(): bool { /* ... */ }
190
+ }
191
+
192
+ // ✅ Typed based on your configuration
193
+ $user = new User();
194
+
195
+ // ✅ Typed as string (inferred from behavior property)
196
+ $slug = $user->getAttribute('slug');
197
+
198
+ // ✅ Direct property access is also inferred (behavior property)
199
+ $slug2 = $user->slug;
200
+
201
+ // ✅ Typed as int (inferred from behavior property)
202
+ $createdAt = $user->getAttribute('created_at');
203
+
204
+ // ✅ Typed as bool (method defined in attached behavior)
205
+ $result = $user->softDelete();
206
+ ```
207
+
164
208
#### Dependency injection
165
209
166
210
``` php
0 commit comments