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,327 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  
Name: Insolita <contact>
Classes: 25 packages by
Country: Russian Federation Russian Federation
Age: 38
All time rank: 330590 in Russian Federation Russian Federation
Week rank: 46 Up4 in Russian Federation Russian Federation Up
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

  Files folder image Files (11)  /  tests  
File Role Description
Files folder imagecodeception (1 directory)

  Files folder image Files (11)  /  tests  /  codeception  
File Role Description
Files folder imagecommon (1 file, 2 directories)

  Files folder image Files (11)  /  tests  /  codeception  /  common  
File Role Description
Files folder imagemigrations (1 file)
Files folder imageunit (1 file, 2 directories)
  Plain text file PrivateTestTrait.php Class Class source

  Files folder image Files (11)  /  tests  /  codeception  /  common  /  migrations  
File Role Description
  Plain text file m160511_151843_synctest.php Class Class source

  Files folder image Files (11)  /  tests  /  codeception  /  common  /  unit  
File Role Description
Files folder imagebehaviors (1 file)
Files folder imagefixtures (4 files)
  Plain text file TestCase.php Class Class source

  Files folder image Files (11)  /  tests  /  codeception  /  common  /  unit  /  behaviors  
File Role Description
  Plain text file ArSyncBehaviorTest.php Class Class source

  Files folder image Files (11)  /  tests  /  codeception  /  common  /  unit  /  fixtures  
File Role Description
  Plain text file DbMaster.php Class Class source
  Plain text file DbSlave.php Class Class source
  Plain text file RedisMaster.php Class Class source
  Plain text file RedisSlave.php Class Class source

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,327
This week:455Up