Download the PHP package blackcube/magic-compose without Composer
On this page you can find all versions of the php package blackcube/magic-compose. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download blackcube/magic-compose
More information about blackcube/magic-compose
Files in blackcube/magic-compose
Package magic-compose
Short Description Simple solution for magic methods and method composition using attributes
License BSD-3-Clause
Homepage https://github.com/blackcubeio/magic-compose
Informations about the package magic-compose
Blackcube Magic Compose
⚠️ Blackcube Warning
PHP says one
__getper class. Blackcube says no.Multiple traits, each with their own magic handlers, dispatched by priority via attributes. It's not a hack — it's composition where PHP forgot to provide it.
Simple solution for magic methods and method composition using attributes.
Installation
Problem
PHP traits can't compose magic methods. When multiple traits define __get, only one wins:
Solution
Mark handlers with attributes, let MagicComposeTrait dispatch:
Attributes
| Attribute | Magic method | Handler signature |
|---|---|---|
#[MagicGetter] |
__get |
(string $name): mixed |
#[MagicSetter] |
__set |
(string $name, mixed $value): void |
#[MagicIsset] |
__isset |
(string $name): bool |
#[MagicUnset] |
__unset |
(string $name): void |
#[MagicCall] |
__call |
(string $name, array $arguments): mixed |
Priority
Handlers are sorted by priority (highest first):
Constants: CRITICAL (100), HIGH (90), NORMAL (50), LOW (10).
MagicExtend
Intercept parent class methods with chainable $this->next():
ActiveRecord Integration
For Yii ActiveRecord, use MagicComposeActiveRecordTrait:
Pre-wired methods: propertyValuesInternal, refreshInternal, populateProperty, deleteInternal, populateRecord.
Handler Flow
- Handlers discovered via reflection (cached)
- Sorted by priority DESC
- First handler that doesn't throw
MagicNotHandledExceptionwins - If all throw → fallback to parent or PHP error
License
BSD-3-Clause. See LICENSE.md.
Author
Philippe Gaultier [email protected]