PHP Classes

yii2-arsync: Add new behaviors to active record actions

Recommend this page to a friend!

  Author Author  
Picture of Insolita
Name: Insolita <contact>
Classes: 18 packages by
Country: Russian Federation Russian Federation
Innovation award
Innovation award
Nominee: 12x


  Detailed description   Download Download .zip .tar.gz  
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


Details

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;
       					},
       				],
       			]
    ];
}

  Classes of Insolita  >  yii2-arsync  >  Download Download .zip .tar.gz  >  Support forum Support forum  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: yii2-arsync
Base name: yii2-arsync
Description: Add new behaviors to active record actions
Version: -
PHP version: 5
License: MIT/X Consortium License
 
  Groups   Applications   Files Files  

  Groups  
Group folder image PHP 5 Classes using PHP 5 specific features View top rated classes
Group folder image Databases Database management, accessing and searching View top rated classes
Group folder image Design Patterns Implementations of well known design patterns View top rated classes


  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  Files folder image Files  
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  /  tests  
File Role Description
Files folder imagecodeception (1 directory)

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

  Files folder image Files  /  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  /  tests  /  codeception  /  common  /  migrations  
File Role Description
  Plain text file m160511_151843_synctest.php Class Class source

  Files folder image Files  /  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  /  tests  /  codeception  /  common  /  unit  /  behaviors  
File Role Description
  Plain text file ArSyncBehaviorTest.php Class Class source

  Files folder image Files  /  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

Download Download all files: yii2-arsync.tar.gz yii2-arsync.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
  Files folder image Files  
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  /  tests  
File Role Description
Files folder imagecodeception (1 directory)

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

  Files folder image Files  /  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  /  tests  /  codeception  /  common  /  migrations  
File Role Description
  Plain text file m160511_151843_synctest.php Class Class source

  Files folder image Files  /  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  /  tests  /  codeception  /  common  /  unit  /  behaviors  
File Role Description
  Plain text file ArSyncBehaviorTest.php Class Class source

  Files folder image Files  /  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

Download Download all files: yii2-arsync.tar.gz yii2-arsync.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.