PHPackages                             blackcube/yii-bridge-model - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. blackcube/yii-bridge-model

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

blackcube/yii-bridge-model
==========================

Bridged FormModel for Yii framework

1.0.0(1mo ago)014↓16.7%2BSD-3-ClausePHPPHP ^8.1

Since Apr 4Pushed 1mo agoCompare

[ Source](https://github.com/blackcubeio/yii-bridge-model)[ Packagist](https://packagist.org/packages/blackcube/yii-bridge-model)[ Docs](https://github.com/blackcubeio/yii-bridge-model)[ RSS](/packages/blackcube-yii-bridge-model/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (17)Versions (3)Used By (2)

Blackcube 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.

[![License](https://camo.githubusercontent.com/6cb285b57819f8de0acfb34923298f4f569f962544e8fe35331da2d163f4e485/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4253442d2d332d2d436c617573652d626c75652e737667)](LICENSE.md)[![Packagist Version](https://camo.githubusercontent.com/cb86c44f1f0aaa695bba424be50f09da7ed49fdbe6ac558c12e8c4c9897bd0d6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626c61636b637562652f7969692d6272696467652d6d6f64656c2e737667)](https://packagist.org/packages/blackcube/yii-bridge-model)[![Warning](https://camo.githubusercontent.com/f6bc4777f4b5c33df3e4f07b00623d3231016d0291e5ce1bf40b0dc084c71145/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f426c61636b637562652d5761726e696e672d6f72616e6765)](BLACKCUBE_WARNING.md)

Installation
------------

[](#installation)

```
composer require blackcube/yii-bridge-model
```

Why Bridge?
-----------

[](#why-bridge)

ApproachProblemManual mappingBoilerplate hell, copy-paste errorsAuto-hydrationBreaks 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
------------

[](#how-it-works)

### The Bridge Attribute

[](#the-bridge-attribute)

```
#[Bridge]                           // Auto-detect target getter/setter
#[Bridge(name: 'title')]            // Map to different name
#[Bridge(format: 'Y-m-d')]          // Date format for conversion
#[Bridge(getter: 'getX', setter: 'setX')]  // Explicit target methods
```

### Data Flow

[](#data-flow)

```
┌─────────────────────────────────────────────────────────────────┐
│                         DATA FLOW                                │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│  AR (native types)  ──────────────────►  FormModel (strings)     │
│                      createFromModel()                           │
│                      initFromModel()                             │
│                                                                  │
│  FormModel (strings) ──────────────────►  AR (native types)      │
│                       populateModel()                            │
│                                                                  │
│  #[Bridge] = mapping instruction                                 │
│  Mapper = automatic DateTimeImmutable ↔ string conversion        │
│  Scenarios = field filtering                                     │
│                                                                  │
└─────────────────────────────────────────────────────────────────┘

```

Quick Start
-----------

[](#quick-start)

### 1. Create your ActiveRecord

[](#1-create-your-activerecord)

```
