From 21170d123d0382a7f3f271b18ef240c99f3eace7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=93=AD=E6=98=95?= <715557344@qq.com> Date: Thu, 5 Sep 2019 09:41:53 +0800 Subject: [PATCH] Moved ConfigInterface to the last. --- src/snowflake/src/Meta.php | 1 - .../MetaGenerator/RedisMilliSecondMetaGenerator.php | 2 +- .../src/MetaGenerator/RedisSecondMetaGenerator.php | 2 +- src/snowflake/tests/RedisMetaGeneratorTest.php | 12 ++++++------ 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/snowflake/src/Meta.php b/src/snowflake/src/Meta.php index dbaf5b637..dd70d2bf0 100644 --- a/src/snowflake/src/Meta.php +++ b/src/snowflake/src/Meta.php @@ -14,7 +14,6 @@ namespace Hyperf\Snowflake; class Meta { - /** * @var int [0, 31] */ diff --git a/src/snowflake/src/MetaGenerator/RedisMilliSecondMetaGenerator.php b/src/snowflake/src/MetaGenerator/RedisMilliSecondMetaGenerator.php index e3f83a2a9..c288aae2e 100644 --- a/src/snowflake/src/MetaGenerator/RedisMilliSecondMetaGenerator.php +++ b/src/snowflake/src/MetaGenerator/RedisMilliSecondMetaGenerator.php @@ -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); diff --git a/src/snowflake/src/MetaGenerator/RedisSecondMetaGenerator.php b/src/snowflake/src/MetaGenerator/RedisSecondMetaGenerator.php index 6b5b390f1..917696351 100644 --- a/src/snowflake/src/MetaGenerator/RedisSecondMetaGenerator.php +++ b/src/snowflake/src/MetaGenerator/RedisSecondMetaGenerator.php @@ -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); diff --git a/src/snowflake/tests/RedisMetaGeneratorTest.php b/src/snowflake/tests/RedisMetaGeneratorTest.php index 895cac077..696d172aa 100644 --- a/src/snowflake/tests/RedisMetaGeneratorTest.php +++ b/src/snowflake/tests/RedisMetaGeneratorTest.php @@ -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);