PHP Classes

File: src/MySQLReplication/Config/ConfigBuilder.php

Recommend this page to a friend!
  Classes of Kacper Rowinski   PHP MySQL Replication   src/MySQLReplication/Config/ConfigBuilder.php   Download  
File: src/MySQLReplication/Config/ConfigBuilder.php
Role: Configuration script
Content type: text/plain
Description: Configuration script
Class: PHP MySQL Replication
Client to get MySQL replication events in pure PHP
Author: By
Last change: Add regular expression matching support for `checkDatabasesOnly` or `checkTablesOnly` (#129)

New release (#104)

* - Change: drop support for < 8.2
- Change: moved to enums, promoted properties
- Added: logger for more socket info
- Added: slave_uuid support
- Change: config no longer static
- Chore: typos in README/code
- Chore: replace/remove old urls from code
- Chore: changed variables to underscore
- Added: support caching_sha2_password
- Change: BinLogServerInfo static calls removed also added method getServerInfo to MySQLReplicationFactory
Date: 12 days ago
Size: 4,433 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

namespace
MySQLReplication\Config;

class
ConfigBuilder
{
    private
string $user = '';

    private
string $host = 'localhost';

    private
int $port = 3306;

    private
string $password = '';

    private
string $charset = 'utf8';

    private
string $gtid = '';

    private
int $slaveId = 666;

    private
string $binLogFileName = '';

    private
string $binLogPosition = '';

    private array
$eventsOnly = [];

    private array
$eventsIgnore = [];

    private array
$tablesOnly = [];

    private array
$databasesOnly = [];

    private array
$tablesRegex = [];

    private array
$databasesRegex = [];

    private
string $mariaDbGtid = '';

    private
int $tableCacheSize = 128;

    private array
$custom = [];

    private
float $heartbeatPeriod = 0.0;

    private
string $slaveUuid = '0015d2b6-8a06-4e5e-8c07-206ef3fbd274';

    public function
withSlaveUuid(string $slaveUuid): self
   
{
       
$this->slaveUuid = $slaveUuid;

        return
$this;
    }

    public function
withUser(string $user): self
   
{
       
$this->user = $user;

        return
$this;
    }

    public function
withHost(string $host): self
   
{
       
$this->host = $host;

        return
$this;
    }

    public function
withPort(int $port): self
   
{
       
$this->port = $port;

        return
$this;
    }

    public function
withPassword(string $password): self
   
{
       
$this->password = $password;

        return
$this;
    }

    public function
withCharset(string $charset): self
   
{
       
$this->charset = $charset;

        return
$this;
    }

    public function
withGtid(string $gtid): self
   
{
       
$this->gtid = $gtid;

        return
$this;
    }

    public function
withSlaveId(int $slaveId): self
   
{
       
$this->slaveId = $slaveId;

        return
$this;
    }

    public function
withBinLogFileName(string $binLogFileName): self
   
{
       
$this->binLogFileName = $binLogFileName;

        return
$this;
    }

    public function
withBinLogPosition(string $binLogPosition): self
   
{
       
$this->binLogPosition = $binLogPosition;

        return
$this;
    }

    public function
withEventsOnly(array $eventsOnly): self
   
{
       
$this->eventsOnly = $eventsOnly;

        return
$this;
    }

   
/**
     * @param array<int, int> $eventsIgnore
     */
   
public function withEventsIgnore(array $eventsIgnore): self
   
{
       
$this->eventsIgnore = $eventsIgnore;

        return
$this;
    }

    public function
withTablesOnly(array $tablesOnly): self
   
{
       
$this->tablesOnly = $tablesOnly;

        return
$this;
    }

    public function
withDatabasesOnly(array $databasesOnly): self
   
{
       
$this->databasesOnly = $databasesOnly;

        return
$this;
    }

    public function
withDatabasesRegex(array $databasesRegex): self
   
{
       
$this->databasesRegex = $databasesRegex;
        return
$this;
    }

    public function
withTablesRegex(array $tablesRegex): self
   
{
       
$this->tablesRegex = $tablesRegex;
        return
$this;
    }

    public function
withMariaDbGtid(string $mariaDbGtid): self
   
{
       
$this->mariaDbGtid = $mariaDbGtid;

        return
$this;
    }

    public function
withTableCacheSize(int $tableCacheSize): self
   
{
       
$this->tableCacheSize = $tableCacheSize;

        return
$this;
    }

    public function
withCustom(array $custom): self
   
{
       
$this->custom = $custom;

        return
$this;
    }

   
/**
     * @see https://dev.mysql.com/doc/refman/5.6/en/change-master-to.html
     */
   
public function withHeartbeatPeriod(float $heartbeatPeriod): self
   
{
       
$this->heartbeatPeriod = $heartbeatPeriod;

        return
$this;
    }

    public function
build(): Config
   
{
        return new
Config(
           
$this->user,
           
$this->host,
           
$this->port,
           
$this->password,
           
$this->charset,
           
$this->gtid,
           
$this->mariaDbGtid,
           
$this->slaveId,
           
$this->binLogFileName,
           
$this->binLogPosition,
           
$this->eventsOnly,
           
$this->eventsIgnore,
           
$this->tablesOnly,
           
$this->databasesOnly,
           
$this->tableCacheSize,
           
$this->custom,
           
$this->heartbeatPeriod,
           
$this->slaveUuid,
           
$this->tablesRegex,
           
$this->databasesRegex,
        );
    }
}