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: Feature/php71 (#53)

- Removed: support for lesser then php7
- Added: strong and string types
- Changed: ConfigFactory removed and method make form array moved to Config
- Changed: MariaDbGtidLogDTO replaced getSequenceNumber with getMariaDbGtid
- Fixed: Insert NULL in a boolean column returns no rows
- Fixed: float problem about time field type
- Fixed: column order
- Changed: getFields and getMasterStatus returns no VO
- Changed: Column to ColumnDTO and added ColumnDTOCollection
- Changed: replaced getFields with getColumnDTOCollection in TableMap
- Added: more compatibility for mysql 5.5, 5.6, 5.7, maria 10 and 8.0
- Removed: makeConfigFromArray
Date: 4 years ago
Size: 1,498 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);

namespace
MySQLReplication\Gtid;

use
MySQLReplication\BinaryDataReader\BinaryDataReader;

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

   
/**
     * @throws GtidException
     */
   
public function __construct(string $gtid)
    {
        if (
false === (bool)preg_match('/^([0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12})((?::[0-9-]+)+)$/', $gtid, $matches)) {
            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) {
            if (
count($interval) !== 1) {
               
$buffer .= BinaryDataReader::pack64bit((int)$interval[0]);
               
$buffer .= BinaryDataReader::pack64bit((int)$interval[1]);
            } else {
               
$buffer .= BinaryDataReader::pack64bit((int)$interval[0]);
               
$buffer .= BinaryDataReader::pack64bit($interval[0] + 1);
            }
        }

        return
$buffer;
    }

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