diff --git a/src/Environment/Parameters.yml b/src/Environment/Parameters.yml index 3b84af4b..03a19581 100644 --- a/src/Environment/Parameters.yml +++ b/src/Environment/Parameters.yml @@ -5,5 +5,6 @@ parameters: neighborhoods.kojo.environment.parameters.database_password: '' neighborhoods.kojo.environment.parameters.database_adapter: '' neighborhoods.kojo.environment.parameters.database_host: '' + neighborhoods.kojo.environment.parameters.database_port: 0 neighborhoods.kojo.environment.parameters.database_name: '' neighborhoods.kojo.environment.parameters.lock_prefix: '' diff --git a/src/PDO/Builder.php b/src/PDO/Builder.php index 5eed0194..e5e6b3d6 100644 --- a/src/PDO/Builder.php +++ b/src/PDO/Builder.php @@ -12,13 +12,18 @@ class Builder implements BuilderInterface protected const PROP_DATA_SOURCE_NAME = 'data_source_name'; protected const PROP_USER_NAME = 'user_name'; protected const PROP_PASSWORD = 'password'; + protected const PROP_PORT = 'port'; protected const PROP_OPTIONS = 'options'; protected $_pdo; public function getPdo(): \PDO { if ($this->_pdo === null) { - $dsn = $this->_getDataSourceName(); + if ($this->_getPort() !== 0){ + $dsn = sprintf('%s;port=%d', $this->_getDataSourceName(),$this->_getPort()); + } else { + $dsn = $this->_getDataSourceName(); + } $userName = $this->_getUserName(); $password = $this->_getPassword(); if ($this->_hasOptions()) { @@ -87,4 +92,16 @@ protected function _hasOptions(): bool { return $this->_exists(self::PROP_OPTIONS); } -} \ No newline at end of file + + public function setPort(int $port): BuilderInterface + { + $this->_create(self::PROP_PORT, $port); + + return $this; + } + + protected function _getPort(): int + { + return $this->_read(self::PROP_PORT); + } +} diff --git a/src/PDO/Builder.yml b/src/PDO/Builder.yml index 6f7526e7..2c7915f4 100644 --- a/src/PDO/Builder.yml +++ b/src/PDO/Builder.yml @@ -7,6 +7,7 @@ services: - [setPassword, ['%neighborhoods.kojo.environment.parameters.database_password%']] - [setUserName, ['%neighborhoods.kojo.environment.parameters.database_user_name%']] - [setDataSourceName, ['%neighborhoods.kojo.environment.parameters.database_adapter%:dbname=%neighborhoods.kojo.environment.parameters.database_name%;host=%neighborhoods.kojo.environment.parameters.database_host%']] + - [setPort, ['%neighborhoods.kojo.environment.parameters.database_port%']] pdo.builder: alias: neighborhoods.kojo.pdo.builder - public: false \ No newline at end of file + public: false diff --git a/src/PDO/BuilderInterface.php b/src/PDO/BuilderInterface.php index 15b81246..8ae29c21 100644 --- a/src/PDO/BuilderInterface.php +++ b/src/PDO/BuilderInterface.php @@ -14,4 +14,6 @@ public function setUserName(string $userName): BuilderInterface; public function setPassword(string $password): BuilderInterface; public function setOptions(array $options): BuilderInterface; -} \ No newline at end of file + + public function setPort(int $port): BuilderInterface; +}