method init documentation in bbn\Db\Sync
function(bbn\Db $db, array $sync_cfg = [], array $tables = [], string $sync_table = '')
{
if (self::$is_init) {
throw new \Exception("Impossible to init twice the dbsync class");
}
self::$current_connection = $db;
if (!empty($sync_table)) {
self::$sync_table = $sync_table;
}
if (!Str::checkName(self::$sync_table)) {
throw new \Exception(X::_("Table name not allowed"));
}
if (empty($sync_cfg)) {
self::$sync_connection = new Db(self::$default_cfg);
}
elseif (isset($sync_cfg['connection'])) {
if (is_object($sync_cfg['connection']) && (is_a($sync_cfg['connection'], '\\bbn\\Db')
|| is_subclass_of($sync_cfg['connection'], '\\bbn\\Db'))
) {
self::$sync_connection = $sync_cfg['connection'];
}
else {
throw new \Exception(X::_("Invalid connection given to the synchronization class"));
}
}
elseif (isset($sync_cfg['engine'])) {
if (($sync_cfg['engine'] === 'sqlite')
|| ($sync_cfg['engine'] !== self::$current_connection->getEngine())
) {
self::$sync_connection = new Db($sync_cfg);
}
elseif (isset($sync_cfg['db']) && !isset($sync_cfg['user'])) {
self::$sync_connection =& self::$current_connection;
self::$sync_table = self::$sync_connection->tfn($sync_cfg['db'].'.'.self::$sync_table);
}
}
elseif (isset($sync_cfg['db']) && !isset($sync_cfg['user'])) {
self::$sync_connection =& self::$current_connection;
self::$sync_table = self::$sync_connection->tfn($sync_cfg['db'].'.'.self::$sync_table);
}
self::$tables = $tables;
self::$is_init = true;
if (\count(self::$tables) === 0) {
self::$tables = self::$current_connection->getTables();
}
if (\is_array(self::$tables)) {
foreach (self::$tables as $i => $t){
self::$tables[$i] = self::$current_connection->tfn($t);
}
self::$current_connection->setTrigger(
'\\bbn\Db\\sync::trigger',
['delete', 'update', 'insert'],
['before', 'after'],
self::$tables
);
}
}
BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2024
BBN Solutions