5 use InvalidArgumentException;
6 use UnexpectedValueException;
60 if ( preg_match(
'!^(.+)\.(\d+)/(\d+)$!', $position, $m ) ) {
61 $this->binLog = $m[1];
62 $this->logPos = [ self::CORD_INDEX => (int)$m[2], self::CORD_EVENT => (
int)$m[3] ];
65 $gtids = array_filter( array_map(
'trim', explode(
',', $position ) ) );
66 foreach (
$gtids as $gtid ) {
69 throw new InvalidArgumentException(
"Invalid GTID '$gtid'." );
72 list( $domain, $pos ) = $components;
73 if ( isset( $this->gtids[$domain] ) ) {
78 if ( $pos > $otherPos ) {
79 $this->gtids[$domain] = $gtid;
82 $this->gtids[$domain] = $gtid;
85 if ( is_int( $domain ) ) {
91 if ( !$this->gtids ) {
92 throw new InvalidArgumentException(
"GTID set cannot be empty." );
104 if ( !( $pos instanceof
self ) ) {
105 throw new InvalidArgumentException(
"Position not an instance of " . __CLASS__ );
110 $thatPosByDomain = $pos->getActiveGtidCoordinates();
111 if ( $thisPosByDomain && $thatPosByDomain ) {
114 foreach ( $thatPosByDomain as $domain => $thatPos ) {
115 if ( isset( $thisPosByDomain[$domain] ) ) {
116 $comparisons[] = ( $thatPos <= $thisPosByDomain[$domain] );
123 return ( $comparisons && !in_array(
false, $comparisons,
true ) );
128 $thatBinPos = $pos->getBinlogCoordinates();
129 if ( $thisBinPos && $thatBinPos && $thisBinPos[
'binlog'] === $thatBinPos[
'binlog'] ) {
130 return ( $thisBinPos[
'pos'] >= $thatBinPos[
'pos'] );
138 if ( !( $pos instanceof
self ) ) {
139 throw new InvalidArgumentException(
"Position not an instance of " . __CLASS__ );
144 $thatPosDomains = array_keys( $pos->getActiveGtidCoordinates() );
145 if ( $thisPosDomains && $thatPosDomains ) {
150 return array_intersect( $thatPosDomains, $thisPosDomains ) ?
true :
false;
155 $thatBinPos = $pos->getBinlogCoordinates();
157 return ( $thisBinPos && $thatBinPos && $thisBinPos[
'binlog'] === $thatBinPos[
'binlog'] );
181 return $this->gtids ? null :
"{$this->binLog}.{$this->logPos[self::CORD_INDEX]}";
205 $this->activeDomain = (int)$id;
222 $this->activeServerId = (int)$id;
239 $this->activeServerUUID = $id;
251 return array_values( array_intersect_key(
266 foreach ( $this->gtids as $domain => $gtid ) {
271 if ( $this->style === self::GTID_MARIA && $this->activeDomain !==
null ) {
275 if ( $this->style === self::GTID_MARIA && $this->activeServerId !==
null ) {
277 } elseif ( $this->style === self::GTID_MYSQL && $this->activeServerUUID !==
null ) {
282 $gtidInfos[$domain] = $pos;
295 if ( preg_match(
'!^(\d+)-(\d+)-(\d+)$!', $id, $m ) ) {
297 return [ (int)$m[1], (
int)$m[3], (int)$m[2] ];
298 } elseif ( preg_match(
'!^(\w{8}-\w{4}-\w{4}-\w{4}-\w{12}):(?:\d+-|)(\d+)$!', $id, $m ) ) {
303 return [ $m[1], (int)$m[2], $m[1] ];
315 return ( $this->binLog !==
null && $this->logPos !==
null )
323 'activeDomain' => $this->activeDomain,
324 'activeServerId' => $this->activeServerId,
325 'activeServerUUID' => $this->activeServerUUID,
332 if ( !is_array( $data ) ) {
333 throw new UnexpectedValueException( __METHOD__ .
": cannot unserialize position" );
336 $this->
init( $data[
'position'], $data[
'asOfTime'] );
337 if ( isset( $data[
'activeDomain'] ) ) {
340 if ( isset( $data[
'activeServerId'] ) ) {
343 if ( isset( $data[
'activeServerUUID'] ) ) {
353 ? implode(
',', $this->gtids )
354 : $this->
getLogFile() .
"/{$this->logPos[self::CORD_EVENT]}";