PHP Classes

yii2-arsync: Add new behaviors to active record actions

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 18 All time: 11,390 This week: 455Up
Version License PHP version Categories
yii2-arsync 1.0MIT/X Consortium ...5PHP 5, Databases, Design Patterns
Description 

Author

This package can add new behaviors to active record actions.

It provides a class that extends the YII framework behavior class to allow the definition of a map of active record field values that will synchronize specific fields between master and slave active record objects.

It also allows applications to register callback functions to customize the actions that will be done when certain active record functions are called.

Currently, this class can add behaviors using callback functions where:

- There is an error saving an object

- There is an error deleting an object

Innovation Award
PHP Programming Innovation award nominee
December 2022
Number 8
ActiveRecord is a popular software design pattern many applications and frameworks use to store and retrieve objects in relational tables.

Often applications that use the active record design pattern define hierarchies of class objects and establish relations between enslaver and enslaved person objects.

This package can help applications that use the active record design pattern implementation with the YII framework to automate the process of updating slave objects based on the changes in master objects.

Manuel Lemos
Picture of Insolita
  Performance   Level  
Innovation award
Innovation award
Nominee: 18x

 

Documentation

ActiveRecord Synchronization Behavior

This behavior for automatic or manual sync data between two models, without declaration relation. This behavior must be attached on master model. Main purposes - for sync rarely modified data from more reliable database storage to redis storage for frequently access; Support actual data state in some development cases;

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist insolita/yii2-arsync "*"

or add

"insolita/yii2-arsync": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by : See more in code

public function behaviors(){
    return [
       'ArSyncBehavior'=>[
       				'class'      => ArSyncBehavior::class,
       				'slaveModel' => \your\model\namespase\Slave::className(),
       				'slaveScenario'=>'sync',
       				'errorSaveCallback'=>function($slave){
                          Yii::error(VarDumper::export($slave->errors));
                          throw new InvalidConfigException('fail save ');
                    },
                    'errorDeleteCallback'=>function($slave){
                        Yii::error('fail delete '.$slave->getPrimaryKey());
                     },
       				'fieldMap' => [
       					'id'=>'id',
       					'title' => 'name',
       					'foo'   => 'foo',
       					'bar'   => 'bar',
       					'baz'   => function($master)
       					{
       						return $master->baz * 2;
       					},
       				],
       			]
    ];
}

  Files folder image Files (11)  
File Role Description
Files folder imagetests (1 directory)
Plain text file ArSyncBehavior.php Class Class source
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:18
This week:0
All time:11,390
This week:455Up