Skip to content

Commit

Permalink
Merge pull request #26 from mrok/master
Browse files Browse the repository at this point in the history
Added possibility define the port for mysql connection
  • Loading branch information
arvenil committed Feb 26, 2016
2 parents 91dd4ec + 5164ea6 commit 1165c85
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/NinjaMutex/Lock/MySqlLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class MySqlLock extends LockAbstract
protected $user;
protected $password;
protected $host;
protected $port;
protected $classname;

/**
Expand All @@ -36,15 +37,17 @@ class MySqlLock extends LockAbstract
* @param string $user
* @param string $password
* @param string $host
* @param int $port
* @param string $classname class name to create as PDO connection
*/
public function __construct($user, $password, $host, $classname = 'PDO')
public function __construct($user, $password, $host, $port = 3306, $classname = 'PDO')
{
parent::__construct();

$this->user = $user;
$this->password = $password;
$this->host = $host;
$this->port = $port;
$this->classname = $classname;
}

Expand Down Expand Up @@ -153,7 +156,8 @@ protected function setupPDO($name)
return true;
}

$this->pdo[$name] = new $this->classname(sprintf('mysql:host=%s', $this->host), $this->user, $this->password);
$dsn = sprintf('mysql:host=%s;port=%d', $this->host, $this->port);
$this->pdo[$name] = new $this->classname($dsn, $this->user, $this->password);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/NinjaMutex/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected function provideFlockMockLock()
*/
protected function provideMysqlMockLock()
{
return array(new MySqlLock('', '', '', 'NinjaMutex\Mock\MockPDO'));
return array(new MySqlLock('', '', '', 3306, 'NinjaMutex\Mock\MockPDO'));
}

/**
Expand Down

0 comments on commit 1165c85

Please sign in to comment.