Moved ConfigInterface to the last.

This commit is contained in:
李铭昕 2019-09-05 09:41:53 +08:00
parent e7c1d05b59
commit 21170d123d
4 changed files with 8 additions and 9 deletions

View File

@ -14,7 +14,6 @@ namespace Hyperf\Snowflake;
class Meta
{
/**
* @var int [0, 31]
*/

View File

@ -25,7 +25,7 @@ class RedisMilliSecondMetaGenerator extends MetaGenerator
protected $dataCenterId;
public function __construct(ConfigInterface $config, ConfigurationInterface $configuration, int $beginTimestamp = self::DEFAULT_BEGIN_SECOND)
public function __construct(ConfigurationInterface $configuration, int $beginTimestamp = self::DEFAULT_BEGIN_SECOND, ConfigInterface $config)
{
parent::__construct($configuration, $beginTimestamp * 1000);

View File

@ -25,7 +25,7 @@ class RedisSecondMetaGenerator extends MetaGenerator
protected $dataCenterId;
public function __construct(ConfigInterface $config, ConfigurationInterface $configuration, int $beginTimestamp = self::DEFAULT_BEGIN_SECOND)
public function __construct(ConfigurationInterface $configuration, int $beginTimestamp = self::DEFAULT_BEGIN_SECOND, ConfigInterface $config)
{
parent::__construct($configuration, $beginTimestamp);

View File

@ -48,7 +48,7 @@ class RedisMetaGeneratorTest extends TestCase
{
$container = $this->getContainer();
$config = $container->get(ConfigInterface::class);
$metaGenerator = new RedisMilliSecondMetaGenerator($config, new SnowflakeConfig());
$metaGenerator = new RedisMilliSecondMetaGenerator(new SnowflakeConfig(), MetaGeneratorInterface::DEFAULT_BEGIN_SECOND, $config);
$meta = $metaGenerator->generate();
$this->assertInstanceOf(Meta::class, $meta);
@ -61,7 +61,7 @@ class RedisMetaGeneratorTest extends TestCase
$container = $this->getContainer();
$hConfig = $container->get(ConfigInterface::class);
$config = new SnowflakeConfig();
$metaGenerator = new RedisMilliSecondMetaGenerator($hConfig, $config);
$metaGenerator = new RedisMilliSecondMetaGenerator($config, MetaGeneratorInterface::DEFAULT_BEGIN_SECOND, $hConfig);
$generator = new SnowflakeIdGenerator($metaGenerator);
$id = $generator->generate();
@ -78,7 +78,7 @@ class RedisMetaGeneratorTest extends TestCase
$container = $this->getContainer();
$hConfig = $container->get(ConfigInterface::class);
$config = new SnowflakeConfig();
$metaGenerator = new RedisSecondMetaGenerator($hConfig, $config);
$metaGenerator = new RedisSecondMetaGenerator($config, MetaGeneratorInterface::DEFAULT_BEGIN_SECOND, $hConfig);
$meta = $metaGenerator->generate();
$this->assertInstanceOf(Meta::class, $meta);
$this->assertSame(0, $meta->getDataCenterId());
@ -90,7 +90,7 @@ class RedisMetaGeneratorTest extends TestCase
$container = $this->getContainer();
$hConfig = $container->get(ConfigInterface::class);
$config = new SnowflakeConfig();
$metaGenerator = new RedisSecondMetaGenerator($hConfig, $config);
$metaGenerator = new RedisSecondMetaGenerator($config, MetaGeneratorInterface::DEFAULT_BEGIN_SECOND, $hConfig);
$generator = new SnowflakeIdGenerator($metaGenerator);
$id = $generator->generate();
@ -107,7 +107,7 @@ class RedisMetaGeneratorTest extends TestCase
$container = $this->getContainer();
$hConfig = $container->get(ConfigInterface::class);
$config = new SnowflakeConfig();
$metaGenerator = new RedisSecondMetaGenerator($hConfig, $config);
$metaGenerator = new RedisSecondMetaGenerator($config, MetaGeneratorInterface::DEFAULT_BEGIN_SECOND, $hConfig);
$generator = new SnowflakeIdGenerator($metaGenerator);
$meta = $generator->degenerate(PHP_INT_MAX);
@ -124,7 +124,7 @@ class RedisMetaGeneratorTest extends TestCase
$container = $this->getContainer();
$hConfig = $container->get(ConfigInterface::class);
$config = new SnowflakeConfig();
$metaGenerator = new RedisSecondMetaGenerator($hConfig, $config);
$metaGenerator = new RedisSecondMetaGenerator($config, MetaGeneratorInterface::DEFAULT_BEGIN_SECOND, $hConfig);
$generator = new SnowflakeIdGenerator($metaGenerator);
$generator = new UserDefinedIdGenerator($generator);