Skip to content

Commit

Permalink
minor fixes, refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
krowinski committed Feb 27, 2016
1 parent b84cc2a commit 8bae5bb
Show file tree
Hide file tree
Showing 14 changed files with 293 additions and 258 deletions.
4 changes: 2 additions & 2 deletions example/benchmark.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
include __DIR__ . '/../vendor/autoload.php';
date_default_timezone_set('UTC');
error_reporting(E_ALL);
ini_set('display_errors', 1);
date_default_timezone_set('UTC');
include __DIR__ . '/../vendor/autoload.php';

use Doctrine\DBAL\DriverManager;
use MySQLReplication\BinLogStream;
Expand Down
5 changes: 2 additions & 3 deletions example/dump_events.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
date_default_timezone_set('UTC');
ini_set('memory_limit', '8M');

include __DIR__ . '/../vendor/autoload.php';

use MySQLReplication\BinLogStream;
Expand All @@ -27,6 +26,6 @@
// all events got JsonSerializable implementation
//echo json_encode($result, JSON_PRETTY_PRINT);

//echo 'Memory usage ' . round(memory_get_usage() / 1048576, 2) . ' MB' . PHP_EOL;
echo 'Memory usage ' . round(memory_get_usage() / 1048576, 2) . ' MB' . PHP_EOL;
}
}
7 changes: 6 additions & 1 deletion src/MySQLReplication/Event/DTO/DeleteRowsDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
*/
class DeleteRowsDTO extends RowsDTO
{
/**
* @var string
*/
protected $type = ConstEventsNames::DELETE;

/**
* @return string
*/
public function getType()
{
return ConstEventsNames::DELETE;
return $this->type;
}
}
6 changes: 5 additions & 1 deletion src/MySQLReplication/Event/DTO/GTIDLogDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class GTIDLogDTO extends EventDTO implements \JsonSerializable
* @var string
*/
private $gtid;
/**
* @var string
*/
private $type = ConstEventsNames::GTID;

/**
* GTIDLogEventDTO constructor.
Expand Down Expand Up @@ -58,7 +62,7 @@ public function getGtid()
*/
public function getType()
{
return ConstEventsNames::GTID;
return $this->type;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/MySQLReplication/Event/DTO/QueryDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ class QueryDTO extends EventDTO implements \JsonSerializable
*/
private $query;
/**
* @var
* @var string
*/
private $database;
/**
* @var string
*/
private $type = ConstEventsNames::QUERY;

/**
* QueryEventDTO constructor.
Expand Down Expand Up @@ -73,7 +77,7 @@ public function getQuery()
*/
public function getType()
{
return ConstEventsNames::QUERY;
return $this->type;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/MySQLReplication/Event/DTO/RotateDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class RotateDTO extends EventDTO implements \JsonSerializable
* @var string
*/
private $next_binlog;
/**
* @var string
*/
private $type = ConstEventsNames::ROTATE;

/**
* RotateDTO constructor.
Expand Down Expand Up @@ -58,7 +62,7 @@ public function getNextBinlog()
*/
public function getType()
{
return ConstEventsNames::ROTATE;
return $this->type;
}

/**
Expand Down
69 changes: 16 additions & 53 deletions src/MySQLReplication/Event/DTO/RowsDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,90 +3,53 @@
namespace MySQLReplication\Event\DTO;

use MySQLReplication\Event\EventInfo;
use MySQLReplication\Event\RowEvent\TableMap;

/**
* Class RowsDTO
* @package MySQLReplication\DTO
*/
class RowsDTO extends EventDTO implements \JsonSerializable
abstract class RowsDTO extends EventDTO implements \JsonSerializable
{
/**
* @var array
*/
private $values;
/**
* @var string
*/
private $database;
/**
* @var string
*/
private $table;
/**
* @var int
*/
private $affected;
private $changedRows;
/**
* @var int
* @var TableMap
*/
private $changedRows;
private $tableMap;

/**
* GTIDLogEventDTO constructor.
* @param EventInfo $eventInfo
* @param $database
* @param $table
* @param $affected
* @param TableMap $tableMap
* @param $changedRows
* @param array $values
*/
public function __construct(
EventInfo $eventInfo,
$database,
$table,
$affected,
TableMap $tableMap,
$changedRows,
array $values
) {
parent::__construct($eventInfo);

$this->database = $database;
$this->table = $table;
$this->affected = $affected;
$this->changedRows = $changedRows;
$this->values = $values;
$this->tableMap = $tableMap;
}

/**
* @return array
*/
public function getValues()
{
return $this->values;
}

/**
* @return string
*/
public function getDatabase()
{
return $this->database;
}

/**
* @return string
*/
public function getTable()
{
return $this->table;
}

/**
* @return int
* @return TableMap
*/
public function getAffected()
public function getTableMap()
{
return $this->affected;
return $this->tableMap;
}

/**
Expand All @@ -98,11 +61,11 @@ public function getChangedRows()
}

/**
* @return string
* @return array
*/
public function getType()
public function getValues()
{
return '';
return $this->values;
}

/**
Expand All @@ -115,8 +78,8 @@ public function __toString()
'Date: ' . $this->eventInfo->getDateTime() . PHP_EOL .
'Log position: ' . $this->eventInfo->getPos() . PHP_EOL .
'Event size: ' . $this->eventInfo->getSize() . PHP_EOL .
'Table: ' . $this->table . PHP_EOL .
'Affected columns: ' . $this->affected . PHP_EOL .
'Table: ' . $this->tableMap->getTable() . PHP_EOL .
'Affected columns: ' . $this->tableMap->getColumnsAmount() . PHP_EOL .
'Changed rows: ' . $this->changedRows . PHP_EOL .
'Values: ' . print_r($this->values, true) . PHP_EOL;
}
Expand Down
92 changes: 26 additions & 66 deletions src/MySQLReplication/Event/DTO/TableMapDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,107 +4,59 @@

use MySQLReplication\Definitions\ConstEventsNames;
use MySQLReplication\Event\EventInfo;
use MySQLReplication\Event\RowEvent\TableMap;

/**
* Class TableMapDTO
* @package MySQLReplication\DTO
*/
class TableMapDTO extends EventDTO implements \JsonSerializable
{
/**
* @var int
*/
private $tableId;
/**
* @var string
*/
private $database;
/**
* @var string
*/
private $table;
private $type = ConstEventsNames::TABLE_MAP;
/**
* @var
* @var TableMap
*/
private $columns;
private $tableMap;

/**
* TableMapDTO constructor.
* @param EventInfo $eventInfo
* @param $tableId
* @param $database
* @param $table
* @param $columns
* @param TableMap $tableMap
*/
public function __construct(
EventInfo $eventInfo,
$tableId,
$database,
$table,
$columns
TableMap $tableMap
) {
parent::__construct($eventInfo);

$this->tableId = $tableId;
$this->database = $database;
$this->table = $table;
$this->columns = $columns;
}

/**
* @return int
*/
public function getTableId()
{
return $this->tableId;
}

/**
* @return string
*/
public function getDatabase()
{
return $this->database;
$this->tableMap = $tableMap;
}

/**
* @return string
*/
public function getTable()
{
return $this->table;
}

/**
* @return int
*/
public function getColumns()
public function __toString()
{
return $this->columns;
return PHP_EOL .
'=== Event ' . $this->getType() . ' === ' . PHP_EOL .
'Date: ' . $this->eventInfo->getDateTime() . PHP_EOL .
'Log position: ' . $this->eventInfo->getPos() . PHP_EOL .
'Event size: ' . $this->eventInfo->getSize() . PHP_EOL .
'Table: ' . $this->tableMap->getTable() . PHP_EOL .
'Database: ' . $this->tableMap->getDatabase() . PHP_EOL .
'Table Id: ' . $this->tableMap->getTableId() . PHP_EOL .
'Columns amount: ' . $this->tableMap->getColumnsAmount() . PHP_EOL;
}

/**
* @return string
*/
public function getType()
{
return ConstEventsNames::TABLE_MAP;
}

/**
* @return string
*/
public function __toString()
{
return PHP_EOL .
'=== Event ' . $this->getType() . ' === ' . PHP_EOL .
'Date: ' . $this->eventInfo->getDateTime() . PHP_EOL .
'Log position: ' . $this->eventInfo->getPos() . PHP_EOL .
'Event size: ' . $this->eventInfo->getSize() . PHP_EOL .
'Table: ' . $this->table . PHP_EOL .
'Database: ' . $this->database . PHP_EOL .
'Table Id: ' . $this->tableId . PHP_EOL .
'Columns: ' . print_r($this->columns, true) . PHP_EOL;
return $this->type;
}

/**
Expand All @@ -118,4 +70,12 @@ public function jsonSerialize()
{
return get_object_vars($this);
}

/**
* @return TableMap
*/
public function getTableMap()
{
return $this->tableMap;
}
}
7 changes: 6 additions & 1 deletion src/MySQLReplication/Event/DTO/UpdateRowsDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
*/
class UpdateRowsDTO extends RowsDTO
{
/**
* @var string
*/
protected $type = ConstEventsNames::UPDATE;

/**
* @return string
*/
public function getType()
{
return ConstEventsNames::UPDATE;
return $this->type;
}
}
Loading

0 comments on commit 8bae5bb

Please sign in to comment.