-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from PavelJurasek/php8
Podpora PHP 8
- Loading branch information
Showing
21 changed files
with
342 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Package CI | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
checks: | ||
name: Checks | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php: [ 7.4, 8.0 ] | ||
redis-version: [4, 5, 6] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: redis | ||
|
||
- name: Start Redis | ||
uses: supercharge/[email protected] | ||
with: | ||
redis-version: ${{ matrix.redis-version }} | ||
|
||
- run: composer update --no-interaction --no-suggest --no-progress --prefer-dist | ||
|
||
- if: matrix.php == '8.0' | ||
run: make phpcs | ||
|
||
- if: matrix.php == '8.0' | ||
run: make lint | ||
|
||
- if: matrix.php == '8.0' | ||
run: make phpstan | ||
|
||
- run: make run-tests | ||
|
||
- if: matrix.php == '8.0' | ||
run: make coveralls || true |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
phpcs: | ||
vendor/bin/phpcs --standard=ruleset.xml --encoding=utf-8 -sp src tests | ||
|
||
lint: | ||
vendor/bin/parallel-lint -e php,phpt --exclude vendor . | ||
|
||
phpstan: | ||
vendor/bin/phpstan analyse -l 2 -c phpstan.neon src tests/KdybyTests | ||
|
||
run-tests: | ||
vendor/bin/tester -s -C ./tests/KdybyTests/ | ||
|
||
coveralls: | ||
vendor/bin/php-coveralls --verbose --config tests/.coveralls.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="Kdyby/Console"> | ||
<rule ref="vendor/kdyby/coding-standard/ruleset.xml"/> | ||
<ruleset name="Kdyby/Redis"> | ||
<rule ref="SlevomatCodingStandard.Files.LineLength"> | ||
<properties> | ||
<property name="lineLengthLimit" value="260"></property> | ||
</properties> | ||
</rule> | ||
</ruleset> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Kdyby\Redis\DI\Config; | ||
|
||
class ClientSchema implements \Nette\Schema\Schema | ||
{ | ||
|
||
private \Nette\DI\ContainerBuilder $builder; | ||
|
||
|
||
public function __construct(\Nette\DI\ContainerBuilder $builder) | ||
{ | ||
$this->builder = $builder; | ||
} | ||
|
||
public function normalize($value, \Nette\Schema\Context $context) | ||
{ | ||
if (\array_key_exists('host', $value) && $value['host'][0] === '/') { | ||
$value['port'] = NULL; // sockets have no ports | ||
|
||
} elseif ( ! \array_key_exists('port', $value)) { | ||
$value['port'] = \Kdyby\Redis\RedisClient::DEFAULT_PORT; | ||
} | ||
|
||
return $value; | ||
} | ||
|
||
|
||
public function merge($value, $base) | ||
{ | ||
return \Nette\Schema\Helpers::merge($value, $base); | ||
} | ||
|
||
|
||
public function complete($value, \Nette\Schema\Context $context) | ||
{ | ||
$value = $this->expandParameters($value); | ||
|
||
$value = $this->getSchema()->complete($value, $context); | ||
|
||
return $value; | ||
} | ||
|
||
|
||
public function completeDefault(\Nette\Schema\Context $context) | ||
{ | ||
|
||
} | ||
|
||
private function expandParameters(array $config): array | ||
{ | ||
$params = $this->builder->parameters; | ||
if (isset($config['parameters'])) { | ||
foreach ((array) $config['parameters'] as $k => $v) { | ||
$v = \explode(' ', \is_int($k) ? $v : $k); | ||
$params[\end($v)] = $this->builder::literal('$' . \end($v)); | ||
} | ||
} | ||
return \Nette\DI\Helpers::expand($config, $params); | ||
} | ||
|
||
private function getSchema(): \Nette\Schema\Schema | ||
{ | ||
return \Nette\Schema\Expect::structure([ | ||
'host' => \Nette\Schema\Expect::string('127.0.0.1'), | ||
'port' => \Nette\Schema\Expect::int()->nullable(), | ||
'timeout' => \Nette\Schema\Expect::int(10), | ||
'database' => \Nette\Schema\Expect::int(0), | ||
'auth' => \Nette\Schema\Expect::string()->nullable(), | ||
'persistent' => \Nette\Schema\Expect::bool(FALSE), | ||
'connectionAttempts' => \Nette\Schema\Expect::int(1), | ||
'lockDuration' => \Nette\Schema\Expect::int(15), | ||
'lockAcquireTimeout' => \Nette\Schema\Expect::bool(FALSE), | ||
'debugger' => \Nette\Schema\Expect::bool($this->builder->parameters['debugMode']), | ||
'versionCheck' => \Nette\Schema\Expect::bool(TRUE), | ||
]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Kdyby\Redis\DI\Config; | ||
|
||
class RedisSchema implements \Nette\Schema\Schema | ||
{ | ||
|
||
private \Nette\DI\ContainerBuilder $builder; | ||
|
||
private ?\Nette\Schema\Schema $schema = NULL; | ||
|
||
|
||
public function __construct(\Nette\DI\ContainerBuilder $builder) | ||
{ | ||
$this->builder = $builder; | ||
} | ||
|
||
public function normalize($value, \Nette\Schema\Context $context) | ||
{ | ||
$keys = [ | ||
'host', | ||
'port', | ||
'timeout', | ||
'database', | ||
'auth', | ||
'persistent', | ||
'connectionAttempts', | ||
'lockDuration', | ||
'lockAcquireTimeout', | ||
'debugger', | ||
'versionCheck', | ||
]; | ||
|
||
$client = []; | ||
|
||
foreach ($keys as $key) { | ||
if (\array_key_exists($key, $value)) { | ||
$client[$key] = $value[$key]; | ||
unset($value[$key]); | ||
} | ||
} | ||
|
||
$value['clients'][NULL] = $client; | ||
|
||
return $this->getSchema()->normalize($value, $context); | ||
} | ||
|
||
|
||
public function merge($value, $base) | ||
{ | ||
return \Nette\Schema\Helpers::merge($value, $base); | ||
} | ||
|
||
|
||
public function complete($value, \Nette\Schema\Context $context) | ||
{ | ||
$value = $this->expandParameters($value); | ||
|
||
$value = $this->getSchema()->complete($value, $context); | ||
|
||
return $value; | ||
} | ||
|
||
|
||
public function completeDefault(\Nette\Schema\Context $context) | ||
{ | ||
|
||
} | ||
|
||
private function expandParameters(array $config): array | ||
{ | ||
$params = $this->builder->parameters; | ||
if (isset($config['parameters'])) { | ||
foreach ((array) $config['parameters'] as $k => $v) { | ||
$v = \explode(' ', \is_int($k) ? $v : $k); | ||
$params[\end($v)] = $this->builder::literal('$' . \end($v)); | ||
} | ||
} | ||
return \Nette\DI\Helpers::expand($config, $params); | ||
} | ||
|
||
private function getSchema(): \Nette\Schema\Schema | ||
{ | ||
if ($this->schema === NULL) { | ||
$this->schema = \Nette\Schema\Expect::structure([ | ||
'journal' => \Nette\Schema\Expect::bool(FALSE), | ||
'storage' => \Nette\Schema\Expect::bool(FALSE), | ||
'session' => \Nette\Schema\Expect::bool(FALSE), | ||
'clients' => \Nette\Schema\Expect::arrayOf( | ||
new \Kdyby\Redis\DI\Config\ClientSchema($this->builder) | ||
)->default([]), | ||
]); | ||
} | ||
|
||
return $this->schema; | ||
} | ||
|
||
} |
Oops, something went wrong.