Skip to content

Commit

Permalink
Merge pull request #48 from allok/8.0
Browse files Browse the repository at this point in the history
PHP 8+ support
  • Loading branch information
Sanikovich Aleksey authored May 24, 2022
2 parents 820c38b + 21a0842 commit 75cdb6b
Show file tree
Hide file tree
Showing 40 changed files with 224 additions and 222 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
composer.lock
vendor/
phpunit.xml
.phpunit.result.cache
Vagrantfile
puphpet/
.vagrant/
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ sudo: required
php:
- 7.1
- 7.2
- 8.0
- nightly

services:
Expand Down
14 changes: 9 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@
{
"name": "Mitrofanov Nikolay",
"email": "[email protected]"
},
{
"name": "Sanikovich Aleksey",
"email": "[email protected]"
}
],
"require": {
"php": "^7.1",
"ext-PDO": "*",
"php": "^7.1 || ^8.0",
"ext-pdo": "*",
"ext-pcre": "*",
"doctrine/dbal": "^2.7",
"smi2/phpClickHouse": "^1.0"
"smi2/phpclickhouse": "^1.0"
},
"require-dev": {
"doctrine/coding-standard": "^4.0",
"phpunit/phpunit": "^7.0"
"doctrine/coding-standard": "^4.0 || ^9.0",
"phpunit/phpunit": "^7.0 || ^9.0"
},
"autoload": {
"psr-4": {
Expand Down
41 changes: 18 additions & 23 deletions src/ClickHouseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand All @@ -35,11 +35,6 @@ class ClickHouseConnection implements Connection, PingableConnection, ServerInfo
/** @var AbstractPlatform */
protected $platform;

/**
* Connection constructor
*
* @param mixed[] $params
*/
public function __construct(
array $params,
string $username,
Expand All @@ -60,15 +55,15 @@ public function __construct(
/**
* {@inheritDoc}
*/
public function prepare($prepareString)
public function prepare($prepareString) : ClickHouseStatement
{
return new ClickHouseStatement($this->smi2CHClient, $prepareString, $this->platform);
}

/**
* {@inheritDoc}
*/
public function query()
public function query() : ClickHouseStatement
{
$args = func_get_args();
$stmt = $this->prepare($args[0]);
Expand Down Expand Up @@ -105,73 +100,73 @@ public function exec($statement) : int
*/
public function lastInsertId($name = null)
{
throw new \LogicException('Unable to get last insert id in ClickHouse');
throw ClickHouseException::notSupported('Unable to get last insert id in ClickHouse');
}

/**
* {@inheritDoc}
*/
public function beginTransaction()
public function beginTransaction() : bool
{
throw new \LogicException('Transactions are not allowed in ClickHouse');
throw ClickHouseException::notSupported('Transactions are not allowed in ClickHouse');
}

/**
* {@inheritDoc}
*/
public function commit()
public function commit() : bool
{
throw new \LogicException('Transactions are not allowed in ClickHouse');
throw ClickHouseException::notSupported('Transactions are not allowed in ClickHouse');
}

/**
* {@inheritDoc}
*/
public function rollBack()
public function rollBack() : bool
{
throw new \LogicException('Transactions are not allowed in ClickHouse');
throw ClickHouseException::notSupported('Transactions are not allowed in ClickHouse');
}

/**
* {@inheritDoc}
*/
public function errorCode()
public function errorCode() : ?string
{
throw new \LogicException('You need to implement ClickHouseConnection::errorCode()');
throw ClickHouseException::notSupported('You need to implement ClickHouseConnection::errorCode()');
}

/**
* {@inheritDoc}
*/
public function errorInfo()
public function errorInfo() : array
{
throw new \LogicException('You need to implement ClickHouseConnection::errorInfo()');
throw ClickHouseException::notSupported('You need to implement ClickHouseConnection::errorInfo()');
}

/**
* {@inheritDoc}
*/
public function ping()
public function ping() : bool
{
return $this->smi2CHClient->ping();
}

/**
* {@inheritDoc}
*/
public function getServerVersion()
public function getServerVersion() : string
{
try {
return $this->smi2CHClient->getServerVersion();
} catch (TransportException $exception) {
} catch (TransportException $e) {
return '';
}
}

/**
* {@inheritDoc}
*/
public function requiresQueryForServerVersion()
public function requiresQueryForServerVersion() : bool
{
return true;
}
Expand Down
10 changes: 8 additions & 2 deletions src/ClickHouseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOD\DBALClickHouse;

use Doctrine\DBAL\Exception;

/**
* Specific Exception for ClickHouse
*/
class ClickHouseException extends \Exception
class ClickHouseException extends Exception
{
public static function notSupported($method) : ClickHouseException
{
return new self(sprintf("Operation '%s' is not supported by platform.", $method));
}
}
2 changes: 1 addition & 1 deletion src/ClickHouseKeywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
*
* For the full copyright and license inflormation, please view the LICENSE
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

Expand Down
Loading

0 comments on commit 75cdb6b

Please sign in to comment.