Skip to content

Commit

Permalink
Drop PHP 7.1 and PeclPacker, require rybakit/msgpack and symfony/uid
Browse files Browse the repository at this point in the history
Fixes #77.
  • Loading branch information
rybakit committed Mar 28, 2022
1 parent bbf452e commit b055683
Show file tree
Hide file tree
Showing 19 changed files with 102 additions and 328 deletions.
14 changes: 1 addition & 13 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,22 @@ jobs:
matrix:
operating-system: [ubuntu-latest]
env:
- PHP_IMAGE: php:7.1-cli
- PHP_IMAGE: php:7.1-cli
TNT_PACKER: pecl
- PHP_IMAGE: php:7.1-cli
TNT_LISTEN_URI: /tmp/tarantool_client.sock

- PHP_IMAGE: php:7.2-cli
- PHP_IMAGE: php:7.2-cli
TNT_PACKER: pecl
- PHP_IMAGE: php:7.2-cli
TNT_LISTEN_URI: /tmp/tarantool_client.sock

- PHP_IMAGE: php:7.3-cli
QA: 1
- PHP_IMAGE: php:7.3-cli
TNT_PACKER: pecl
- PHP_IMAGE: php:7.3-cli
TNT_LISTEN_URI: /tmp/tarantool_client.sock

- PHP_IMAGE: php:8.0-cli
- PHP_IMAGE: php:8.0-cli
TNT_PACKER: pecl
- PHP_IMAGE: php:8.0-cli
TNT_LISTEN_URI: /tmp/tarantool_client.sock

- COVERAGE_FILE: coverage.clover
- COVERAGE_FILE: coverage.clover
TNT_PACKER: pecl
EXT_DISABLE_DECIMAL: true
- COVERAGE_FILE: coverage.clover
TNT_LISTEN_URI: /tmp/tarantool_client.sock

Expand Down
1 change: 0 additions & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ build:
version: 7.4
pecl_extensions:
- decimal
- msgpack
nodes:
analysis:
tests:
Expand Down
41 changes: 13 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ A pure PHP client for [Tarantool](https://www.tarantool.io/en/developers/) 1.7.1
* Supports SQL protocol
* Supports user-defined types (decimals and UUIDs are included)
* Highly customizable
* [Thoroughly tested](https://github.com/tarantool-php/client/actions?query=workflow%3AQA) on PHP 7.1-8.0 and Tarantool 1.7-2.8
* Being used in a number of projects, including [Queue](https://github.com/tarantool-php/queue), [Mapper](https://github.com/tarantool-php/mapper), [Web Admin](https://github.com/basis-company/tarantool-admin) and [others](https://github.com/tarantool-php).
* [Thoroughly tested](https://github.com/tarantool-php/client/actions?query=workflow%3AQA)
* Being used in a number of projects, including [Queue](https://github.com/tarantool-php/queue),
[Mapper](https://github.com/tarantool-php/mapper), [Web Admin](https://github.com/basis-company/tarantool-admin)
and [others](https://github.com/tarantool-php).


## Table of contents
Expand All @@ -42,23 +44,10 @@ The recommended way to install the library is through [Composer](http://getcompo
composer require tarantool/client
```

In addition, you need to install one of the supported msgpack packages
(either [rybakit/msgpack.php](https://github.com/rybakit/msgpack.php#installation)
or [msgpack/msgpack-php](https://github.com/msgpack/msgpack-php#install)).

Note that the [Decimal](https://www.tarantool.io/en/doc/latest/dev_guide/internals/msgpack_extensions/#the-decimal-type) type
that was added in Tarantool 2.3 is only supported by the `rybakit/msgpack.php` package. In order to use decimals with
this package, you additionally need to install the [decimal](http://php-decimal.io/#installation) extension. The same
applies to the [UUID](https://www.tarantool.io/en/doc/latest/dev_guide/internals/msgpack_extensions/#the-uuid-type) type that
is available since Tarantool 2.4, install the [symfony/uid](https://symfony.com/doc/master/components/uid.html#installation)
package to be able to work with this type (for better performance you can additionally install
the [uuid](https://pecl.php.net/package/uuid) extension).

> *Although it is recommended to use pecl extensions for such complex MessagePack data structures,
> this is not mandatory, and their support can be relatively easily implemented in pure php
> using well-established pure php libraries, or by writing your own implementation.
> See the section "[User-defined types](https://github.com/tarantool-php/client#user-defined-types)"
> for more information.*
In order to use the [Decimal](https://www.tarantool.io/en/doc/latest/dev_guide/internals/msgpack_extensions/#the-decimal-type)
type that was added in Tarantool 2.3, you additionally need to install the [decimal](http://php-decimal.io/#installation)
extension. Also, to improve performance when working with the [UUID](https://www.tarantool.io/en/doc/latest/dev_guide/internals/msgpack_extensions/#the-uuid-type)
type, which is available since Tarantool 2.4, it is recommended to additionally install the [uuid](https://pecl.php.net/package/uuid) extension.


## Creating a client
Expand Down Expand Up @@ -669,21 +658,17 @@ $space->insert([42, Money::EUR(500)]);
[[$id, $money]] = $space->select(Criteria::key([42]));
```

The [PeclPacker](src/Packer/PeclPacker.php) supports object serialization out of the box, no extra configuration
is needed (however, please note that it does not support [MessagePack extensions](https://github.com/msgpack/msgpack/blob/master/spec.md#ext-format-family)
which are required, for example, to handle decimal numbers or UUIDs).

For the [PurePacker](src/Packer/PurePacker.php) you will need to write an extension that converts your objects to
and from MessagePack structures (for more details, read the msgpack.php's [README](https://github.com/rybakit/msgpack.php#type-transformers)).
Once you have implemented your extension, you should register it with the packer object:
This can be achieved by extending the MessagePack type system with your own types. To do this, you need to write
a MessagePack extension that converts your objects into MessagePack structures and back (for more details, read
the msgpack.php's [README](https://github.com/rybakit/msgpack.php#custom-types)). Once you have implemented
your extension, you should register it with the packer object:

```php
$packer = PurePacker::fromExtensions(new MoneyExtension());
$client = new Client(new DefaultHandler($connection, $packer));
```

> *A working example of using the user-defined types can be found in the [examples](examples/user_defined_type) folder.*
> *A working example of using the user-defined types can be found in the [examples](examples/user_defined_type) folder.*

## Tests
Expand Down
15 changes: 6 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,23 @@
}
],
"require": {
"php": "^7.1|^8"
"php": "^7.2.5|^8",
"rybakit/msgpack": "^0.9",
"symfony/uid": "^5.1|^6"
},
"require-dev": {
"ext-json": "*",
"ext-msgpack": "*",
"ext-sockets": "*",
"friendsofphp/php-cs-fixer": "^2.19",
"monolog/monolog": "^1.24|^2.0",
"psr/log": "^1.1",
"rybakit/msgpack": "^0.9",
"symfony/uid": "^5.1",
"tarantool/phpunit-extras": "^0.1.2",
"tarantool/phpunit-extras": "^0.1.9",
"vimeo/psalm": "^3.9|^4"
},
"suggest": {
"ext-decimal": "For using decimals with Tarantool 2.3+",
"ext-msgpack": "For using Pecl packer",
"psr/log": "For using LoggingMiddleware",
"rybakit/msgpack": "For using Pure packer (version 0.9 or above is required)",
"symfony/uid": "For using UUIDs with Tarantool 2.4+"
"ext-uuid": "For better performance when using UUIDs with Tarantool 2.4+",
"psr/log": "For using LoggingMiddleware"
},
"autoload": {
"psr-4": {
Expand Down
14 changes: 2 additions & 12 deletions dockerfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ if [[ -z "$PHP_IMAGE" ]]; then
PHP_IMAGE='php:7.4-cli'
fi

if [[ -z "$TNT_PACKER" ]]; then
TNT_PACKER='pure'
fi

if [[ -z "$TNT_LISTEN_URI" ]]; then
TNT_LISTEN_URI='tarantool:3301'
fi
Expand All @@ -22,25 +18,19 @@ if [[ -z "$EXT_DISABLE_DECIMAL" || "0" == "$EXT_DISABLE_DECIMAL" || "false" == "
RUN_CMDS="$RUN_CMDS && \\\\\n pecl install decimal && docker-php-ext-enable decimal"
fi

COMPOSER_REMOVE=''
if [[ "$PHP_IMAGE" =~ 7.1 ]]; then
COMPOSER_REMOVE='symfony/uid'
fi

echo -e "
FROM $PHP_IMAGE
RUN apt-get update && \\
apt-get install -y curl git uuid-dev unzip && \\
docker-php-ext-install sockets && \\
pecl install msgpack && docker-php-ext-enable msgpack && \\
pecl install uuid && docker-php-ext-enable uuid${RUN_CMDS}
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
ENV PATH=~/.composer/vendor/bin:\$PATH
ENV TNT_PACKER=$TNT_PACKER TNT_LISTEN_URI=$TNT_LISTEN_URI
ENV TNT_LISTEN_URI=$TNT_LISTEN_URI
CMD if [ ! -f composer.lock ]; then ${COMPOSER_REMOVE:+composer remove --dev --no-update }$COMPOSER_REMOVE${COMPOSER_REMOVE:+ && }composer install; fi && \\
CMD if [ ! -f composer.lock ]; then composer install; fi && \\
vendor/bin/phpunit ${COVERAGE_FILE:+ --coverage-text --coverage-clover=}$COVERAGE_FILE
"
3 changes: 1 addition & 2 deletions examples/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Tarantool\Client\Connection\StreamConnection;
use Tarantool\Client\Handler\DefaultHandler;
use Tarantool\Client\Packer\Packer;
use Tarantool\Client\Packer\PackerFactory;
use Tarantool\Client\Packer\PurePacker;

return require __DIR__.'/../vendor/autoload.php';
Expand All @@ -26,7 +25,7 @@ function create_client(?Packer $packer = null) : Client
? StreamConnection::create($_SERVER['argv'][1])
: StreamConnection::createTcp();

return new Client(new DefaultHandler($connection, $packer ?? PackerFactory::create()));
return new Client(new DefaultHandler($connection, $packer ?? PurePacker::fromAvailableExtensions()));
}

function server_version_at_least(string $version, Client $client) : bool
Expand Down
8 changes: 4 additions & 4 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Tarantool\Client\Middleware\Middleware;
use Tarantool\Client\Middleware\RetryMiddleware;
use Tarantool\Client\Packer\Packer;
use Tarantool\Client\Packer\PackerFactory;
use Tarantool\Client\Packer\PurePacker;
use Tarantool\Client\Request\CallRequest;
use Tarantool\Client\Request\EvaluateRequest;
use Tarantool\Client\Request\ExecuteRequest;
Expand All @@ -48,7 +48,7 @@ public static function fromDefaults() : self
{
return new self(new DefaultHandler(
StreamConnection::createTcp(),
PackerFactory::create()
PurePacker::fromAvailableExtensions()
));
}

Expand Down Expand Up @@ -80,7 +80,7 @@ public static function fromOptions(array $options, ?Packer $packer = null) : sel
? StreamConnection::create($options['uri'], $connectionOptions)
: StreamConnection::createTcp(StreamConnection::DEFAULT_TCP_URI, $connectionOptions);

$handler = new DefaultHandler($connection, $packer ?? PackerFactory::create());
$handler = new DefaultHandler($connection, $packer ?? PurePacker::fromAvailableExtensions());

return $middleware
? new self(MiddlewareHandler::append($handler, $middleware))
Expand Down Expand Up @@ -117,7 +117,7 @@ public static function fromDsn(string $dsn, ?Packer $packer = null) : self
? StreamConnection::createTcp($dsn->getConnectionUri(), $connectionOptions)
: StreamConnection::createUds($dsn->getConnectionUri(), $connectionOptions);

$handler = new DefaultHandler($connection, $packer ?? PackerFactory::create());
$handler = new DefaultHandler($connection, $packer ?? PurePacker::fromAvailableExtensions());

return $middleware
? new self(MiddlewareHandler::append($handler, $middleware))
Expand Down
33 changes: 0 additions & 33 deletions src/Packer/PackerFactory.php

This file was deleted.

66 changes: 0 additions & 66 deletions src/Packer/PeclPacker.php

This file was deleted.

8 changes: 2 additions & 6 deletions src/Packer/PurePacker.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use MessagePack\Packer;
use MessagePack\PackOptions;
use MessagePack\UnpackOptions;
use Symfony\Component\Uid\Uuid;
use Tarantool\Client\Keys;
use Tarantool\Client\Packer\Extension\DecimalExtension;
use Tarantool\Client\Packer\Extension\ErrorExtension;
Expand All @@ -38,7 +37,7 @@ final class PurePacker implements ClientPacker
public function __construct(?Packer $packer = null, ?BufferUnpacker $unpacker = null)
{
$this->packer = $packer ?: new Packer(PackOptions::FORCE_STR);
$this->unpacker = $unpacker ?: new BufferUnpacker();
$this->unpacker = $unpacker ?: new BufferUnpacker('', \extension_loaded('decimal') ? UnpackOptions::BIGINT_AS_DEC : null);
}

public static function fromExtensions(Extension $extension, Extension ...$extensions) : self
Expand All @@ -53,10 +52,7 @@ public static function fromExtensions(Extension $extension, Extension ...$extens

public static function fromAvailableExtensions() : self
{
$extensions = [new ErrorExtension()];
if (\class_exists(Uuid::class)) {
$extensions[] = new UuidExtension();
}
$extensions = [new UuidExtension(), new ErrorExtension()];
if (\extension_loaded('decimal')) {
$extensions[] = new DecimalExtension();

Expand Down
Loading

0 comments on commit b055683

Please sign in to comment.