-
Notifications
You must be signed in to change notification settings - Fork 70
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 #108 from PavelJurasek/php8-4
Fix: session and storage config sections can be client definitions
- Loading branch information
Showing
7 changed files
with
146 additions
and
22 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 |
---|---|---|
|
@@ -16,7 +16,9 @@ jobs: | |
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: redis | ||
extensions: redis, igbinary | ||
env: | ||
REDIS_CONFIGURE_OPTS: --enable-redis --enable-redis-igbinary | ||
|
||
- name: Start Redis | ||
uses: supercharge/[email protected] | ||
|
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Kdyby\Redis\DI\Config; | ||
|
||
class SessionClientSchema 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 (\is_bool($value)) { | ||
return $value; | ||
} | ||
|
||
$value = $this->getSchema()->normalize($value, $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) | ||
{ | ||
if ( ! \is_bool($value)) { | ||
$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(FALSE), | ||
'versionCheck' => \Nette\Schema\Expect::bool(TRUE), | ||
'native' => \Nette\Schema\Expect::bool(TRUE), | ||
'prefix' => \Nette\Schema\Expect::string(\Kdyby\Redis\DI\RedisExtension::DEFAULT_SESSION_PREFIX), | ||
'weight' => \Nette\Schema\Expect::int(1), | ||
])->castTo('array'); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
redis: | ||
journal: false | ||
storage: false | ||
session: | ||
database: 1 | ||
native: false | ||
versionCheck: false |