PHP Classes

File: src/MySQLReplication/Gtid/Gtid.php

Recommend this page to a friend!
  Classes of Kacper Rowinski   PHP MySQL Replication   src/MySQLReplication/Gtid/Gtid.php   Download  
File: src/MySQLReplication/Gtid/Gtid.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: 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: 11 days ago
Size: 1,433 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

namespace
MySQLReplication\Gtid;

use
MySQLReplication\BinaryDataReader\BinaryDataReader;

class
Gtid
{
    private array
$intervals = [];
    private
string $sid;

    public function
__construct(string $gtid)
    {
        if ((bool)
preg_match(
           
'/^([0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12})((?::[0-9-]+)+)$/',
           
$gtid,
           
$matches
       
) === false) {
            throw new
GtidException(GtidException::INCORRECT_GTID_MESSAGE, GtidException::INCORRECT_GTID_CODE);
        }

       
$this->sid = $matches[1];
        foreach (
array_filter(explode(':', $matches[2])) as $k) {
           
$this->intervals[] = explode('-', $k);
        }
       
$this->sid = str_replace('-', '', $this->sid);
    }

    public function
getEncoded(): string
   
{
       
$buffer = pack('H*', $this->sid);
       
$buffer .= BinaryDataReader::pack64bit(count($this->intervals));

        foreach (
$this->intervals as $interval) {
           
$buffer .= BinaryDataReader::pack64bit((int)$interval[0]);
            if (
count($interval) !== 1) {
               
$buffer .= BinaryDataReader::pack64bit((int)$interval[1]);
            } else {
               
$buffer .= BinaryDataReader::pack64bit($interval[0] + 1);
            }
        }

        return
$buffer;
    }

    public function
getEncodedLength(): int
   
{
        return
40 * count($this->intervals);
    }
}