Download the PHP package blackcube/yii-bridge-model without Composer
On this page you can find all versions of the php package blackcube/yii-bridge-model. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download blackcube/yii-bridge-model
More information about blackcube/yii-bridge-model
Files in blackcube/yii-bridge-model
Package yii-bridge-model
Short Description Bridged FormModel for Yii framework
License BSD-3-Clause
Homepage https://github.com/blackcubeio/yii-bridge-model
Informations about the package yii-bridge-model
Blackcube Yii Bridge Model
⚠️ Blackcube Warning
This is not auto-hydration. It's a declared, typed, scenario-filtered bridge between FormModel and ActiveRecord.
You put
#[Bridge]on what transfers in FormModel. You control the direction, the format, the scope. Nothing moves without your say-so.
Bidirectional data bridge between FormModel and ActiveRecord for Yii framework.
Installation
Why Bridge?
| Approach | Problem |
|---|---|
| Manual mapping | Boilerplate hell, copy-paste errors |
| Auto-hydration | Breaks on type mismatch, no control |
| Bridge | None of the above |
You declare mappings with attributes. Bridge handles the rest.
Type conversion is automatic. DateTimeImmutable ↔ string just works.
Scenarios filter what transfers. Edit form ≠ Create form ≠ API form.
Elastic properties are transparent. Dynamic JSON Schema fields work like regular properties.
How It Works
The Bridge Attribute
Data Flow
Quick Start
1. Create your ActiveRecord
2. Create your FormModel
Usage
Load from ActiveRecord
Save to ActiveRecord
Scenarios
Control which fields are active for validation and transfer:
Date Conversion
DateTimeImmutable ↔ string conversion is automatic when you specify a format:
Type Override
When reflection can't detect the type (mixed, inherited, etc.):
Elastic Integration
Bridge works transparently with elastic dynamic properties.
AR with Elastic
FormModel with Elastic
Elastic properties are auto-discovered from the JSON Schema:
Elastic Constants
| Constant | Effect |
|---|---|
ALL_ELASTIC_ATTRIBUTES |
Include all elastic fields in scenario |
NO_ELASTIC_ATTRIBUTES |
Exclude all elastic fields from scenario |
Bridge Resolution
Bridge auto-detects target accessors in this order:
| Source | Target Detection Order |
|---|---|
Property $name |
setName() → getName()/isName() → $name |
Getter getName() |
setName() → $name |
Setter setName() |
getName()/isName() → $name |
Explicit attributes always win:
API Reference
BridgeFormModel
| Method | Description |
|---|---|
createFromModel($model) |
Factory: create and populate from AR |
initFromModel($model) |
Populate from AR |
populateModel($model) |
Transfer to AR (filtered by scenario) |
load($data, $scope) |
Hydrate from array (POST data) |
validate() |
Validate with filtered rules |
setScenario($scenario) |
Set active scenario |
getScenario() |
Get active scenario |
getProperties() |
Get all Bridge components |
getRules() |
Get rules filtered by scenario |
Bridge Attribute
| Parameter | Type | Description |
|---|---|---|
name |
?string |
Canonical name (for fusion) |
type |
?string |
Override detected type |
format |
?string |
Date format for conversion |
property |
?string |
Explicit target property |
getter |
?string |
Explicit target getter |
setter |
?string |
Explicit target setter |
Let's be honest
No magic
Bridge doesn't guess. If you don't put #[Bridge], the property is ignored.
One AR per FormModel (usually)
Multi-AR forms are possible (call initFromModel() multiple times) but think twice. Complex forms often mean complex problems.
Elastic requires ElasticHydrator
Yii's default Hydrator doesn't handle elastics. Bridge includes ElasticHydrator that does.
Rules
- Always use
#[Bridge]— unmarked properties don't transfer - Specify format for dates — or get "Y-m-d H:i:s" default
- Use scenarios — don't transfer everything everywhere
- Always add rules — Bridge doesn't transfer Form -> AR if property has no validation rules
- Validate before populate — Bridge doesn't validate, it transfers
License
BSD-3-Clause. See LICENSE.md.
Author
Philippe Gaultier [email protected]
All versions of yii-bridge-model with dependencies
yiisoft/active-record Version ^1.0
yiisoft/db Version ^2.0
yiisoft/form-model Version ^1.1
yiisoft/hydrator Version ^1.6
blackcube/active-record Version ^1.0
php Version ^8.1
blackcube/injector Version ^1.0