Skip to content

Commit c08240c

Browse files
fix(docs): Update README.md to include Behavior integration section and example usage. (#74)
1 parent 41d606a commit c08240c

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Bug #71: Update `.gitattributes` to exclude additional files from the package (@terabytesoftw)
66
- Bug #72: Exclude `phpstan-console.neon` from the package in `.gitattributes` (@terabytesoftw)
77
- Bug #73: Update workflow actions to use `v1` stable version instead of `main`, update `LICENSE.md` (@terabytesoftw)
8+
- Bug #74: Update `README.md` to include `Behavior` integration section and example usage (@terabytesoftw)
89

910
## 0.3.1 August 16, 2025
1011

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ inference, dynamic method resolution, and comprehensive property reflection.
4646
- Support for custom component configurations.
4747
- User component with `identity`, `id`, `isGuest` property types.
4848

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+
4954
**Dependency Injection Container**
5055
- Service map integration for custom services.
5156
- Support for closures, singletons, and nested definitions.
@@ -102,6 +107,13 @@ Create a PHPStan-specific config file (`config/phpstan-config.php`).
102107
declare(strict_types=1);
103108

104109
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+
],
105117
'components' => [
106118
'db' => [
107119
'class' => yii\db\Connection::class,
@@ -161,6 +173,38 @@ if (Yii::$app->user->isGuest === false) {
161173
}
162174
```
163175

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+
164208
#### Dependency injection
165209

166210
```php

0 commit comments

Comments
 (0)