Prepare to store events for the current transaction.

@param  \Illuminate\Database\ConnectionInterface  $connection
@return void
963120
protected function prepareTransaction($connection)
    {
        $connectionId = $connection->getName();
        $this->transactionLevel = $this->transactionLevel > 0 ? $this->transactionLevel + 1 : 1;

        // Now we prepare a new array level for this transaction in the current
        // transaction level. It allows nested transactions to rollback and
        // their events discarded without affecting previous transactions.
        $this->pendingEvents[$connectionId][$this->transactionLevel][] = [];
    }
171218
protected function addUnsecuredConnection(ConnectionInterface $connection)
    {
        $this->getRemote($connection)->then(
            function($remote) use($connection) {
                $this->initializeConnection($remote, $connection);
            },
            function($error) use($connection) {
                $this->emitConnectionError($error, $connection);
            }
        );
    }
940236
public function on($connection)
    {
        $this->setDatabase($connection);
        $this->_connection = null;

        $this->setDatabaseConnection($this->getDatabase());

        return $this;
    }
1013551
public function setConnection($connection)
	{
		if (is_string($connection)) {
			$connection = Yii::$app->{$connection};
		}
		$this->_connection = $connection;
	}
89185
public function handle(EventInterface $event)
    {
        try {
            $this->getApplicationServer()->getSystemLogger()->info($event->getName());
        } catch (\Exception $e) {
             $this->getApplicationServer()->getSystemLogger()->error($e->__toString());
        }
    }
588124
public function onGatewayClose($connection)
    {
        $addr = $connection->remoteAddress;
        unset($this->gatewayConnections[$addr], $this->_connectingGatewayAddresses[$addr]);
        if (isset($this->_gatewayAddresses[$addr]) && !isset($this->_waitingConnectGatewayAddresses[$addr])) {
            Timer::add(1, array($this, 'tryToConnectGateway'), array($addr), false);
            $this->_waitingConnectGatewayAddresses[$addr] = $addr;
        }
    }
463706
public function rollback(ConnectionInterface $connection)
    {
        $connectionId = $connection->getName();

        if ($this->transactionLevel > 1) {
            array_pop($this->pendingEvents[$connectionId][$this->transactionLevel]);
        } else {
            unset($this->pendingEvents[$connectionId]);
        }

        $this->transactionLevel--;
    }
205605
private function processMigration($connection, $class)
    {
        // Verbose.
        $this->info('Migrating...');
        $this->line('');

        // Migrate the database.
        $migration = new $class($connection);
        $migration->up($connection);
    }
1302758
protected function setOutput(Connection $connection)
	{
		$output = php_sapi_name() == 'cli' ? new ConsoleOutput : new NullOutput;

		$connection->setOutput($output);
	}
1080119
protected function addActiveConnection(ConnectionInterface $connection)
    {
        if (!$this->activeConnections) {
            $this->activeConnections = new \SplObjectStorage;
        }
        $this->activeConnections->attach($connection);
    }
472720
public function execute(DataSetInterface $dataSet): void
    {
        $storeTransfer = $this->getStoreByName($dataSet[MerchantRelationshipSalesOrderThresholdDataSetInterface::COLUMN_STORE]);
        $currencyTransfer = $this->getCurrencyByCode($dataSet[MerchantRelationshipSalesOrderThresholdDataSetInterface::COLUMN_CURRENCY]);
        $merchantRelationshipTransfer = $this->getMerchantRelationshipByKey(
            $dataSet[MerchantRelationshipSalesOrderThresholdDataSetInterface::COLUMN_MERCHANT_RELATIONSHIP_KEY]
        );

        if ($dataSet[MerchantRelationshipSalesOrderThresholdDataSetInterface::COLUMN_SALES_ORDER_THRESHOLD_TYPE_KEY] && $dataSet[MerchantRelationshipSalesOrderThresholdDataSetInterface::COLUMN_THRESHOLD]) {
            $merchantRelationshipSalesOrderThresholdTransfer = $this->createMerchantRelationshipSalesOrderThresholdTransfer(
                $dataSet[MerchantRelationshipSalesOrderThresholdDataSetInterface::COLUMN_SALES_ORDER_THRESHOLD_TYPE_KEY],
                $merchantRelationshipTransfer,
                $storeTransfer,
                $currencyTransfer,
                (int)$dataSet[MerchantRelationshipSalesOrderThresholdDataSetInterface::COLUMN_THRESHOLD],
                (int)$dataSet[MerchantRelationshipSalesOrderThresholdDataSetInterface::COLUMN_FEE],
                $dataSet[MerchantRelationshipSalesOrderThresholdDataSetInterface::COLUMN_MESSAGE_GLOSSARY_KEY]
            );

            $this->merchantRelationshipSalesOrderThresholdFacade->saveMerchantRelationshipSalesOrderThreshold(
                $merchantRelationshipSalesOrderThresholdTransfer
            );
        }
    }
228178
public static function setup(Settings $settings, ConnectionInterface $connection = null)
    {
        return static::getInstance($settings)->load($connection);
    }
1294344
public function onWorkerConnect($connection)
    {
        $connection->maxSendBufferSize = $this->sendToWorkerBufferSize;
        $connection->authorized = $this->secretKey ? false : true;
    }
1298553
private function isTransactionalEvent(ConnectionInterface $connection, $event)
    {
        if ($this->isPrepared($connection) && $this->transactionLevel > 0) {
            return $this->shouldHandle($event);
        }

        return false;
    }
1003367
public function prepare($connectionId, Credentials $credentials)
    {
        $connection = Connection::fromCredentials($credentials);

        $this->store($connectionId, $connection);
    }
485119
public function onConnection(ConnectionInterface $connection)
    {
        $this->log('New connection from ' . $connection->getRemoteAddress());

        $buffer = '';
        $connection->on('data', function ($data) use (&$buffer, &$connection) {
            $buffer .= $data;

            if (strpos($buffer, Client::END_OF_COMMAND)) {
                $chunks = explode(Client::END_OF_COMMAND, $buffer);
                $count = count($chunks);
                $buffer = $chunks[$count - 1];

                for ($i = 0; $i < $count - 1; $i++) {
                    $command = json_decode($chunks[$i], true);
                    $this->runCommand($command, $connection);
                }
            }
        });
    }
1192689
protected function ensureConnectionIsEstablished($connection)
    {
        if (!$this->isConnectionEstablished($connection)) {
            $message = $this->createConnectionErrorMessage($connection);

            throw new ConnectionException($message);
        }
    }