diff --git a/src/Factory/FileBasedEnvResolvingStrategyFactory.php b/src/Factory/FileBasedEnvResolvingStrategyFactory.php index fb572ba..bac097b 100644 --- a/src/Factory/FileBasedEnvResolvingStrategyFactory.php +++ b/src/Factory/FileBasedEnvResolvingStrategyFactory.php @@ -15,6 +15,9 @@ use Lamoda\MultiEnv\Strategy\FileBasedEnvResolvingStrategy; use Lamoda\MultiEnv\Strategy\RawEnvResolvingStrategy; +/** + * @deprecated This factory must be implemented in the client code. It will be removed in version 1.0 + */ class FileBasedEnvResolvingStrategyFactory { public static function createStrategy( @@ -23,6 +26,11 @@ public static function createStrategy( string $envFileName, string $basePathToEnvFile ): FileBasedEnvResolvingStrategy { + @trigger_error( + sprintf('Factory %s is deprecated. It must be implemented in the client code. It will be removed in version 1.0', self::class), + E_USER_DEPRECATED + ); + return new FileBasedEnvResolvingStrategy( new FirstSuccessfulHostDetector([ new ServerHeadersBasedHostDetector($serverHeaderToSearch), diff --git a/src/Factory/HostBasedEnvResolvingStrategyFactory.php b/src/Factory/HostBasedEnvResolvingStrategyFactory.php index 2edddcd..3ca8238 100644 --- a/src/Factory/HostBasedEnvResolvingStrategyFactory.php +++ b/src/Factory/HostBasedEnvResolvingStrategyFactory.php @@ -13,6 +13,9 @@ use Lamoda\MultiEnv\HostDetector\ServerHeadersBasedHostDetector; use Lamoda\MultiEnv\Strategy\HostBasedEnvResolvingStrategy; +/** + * @deprecated This factory must be implemented in the client code. It will be removed in version 1.0 + */ class HostBasedEnvResolvingStrategyFactory { public static function createStrategy( @@ -20,6 +23,11 @@ public static function createStrategy( string $cliArgToSearch, string $delimiter ): HostBasedEnvResolvingStrategy { + @trigger_error( + sprintf('Factory %s is deprecated. It must be implemented in the client code. It will be removed in version 1.0', self::class), + E_USER_DEPRECATED + ); + return new HostBasedEnvResolvingStrategy( new FirstSuccessfulHostDetector([ new ServerHeadersBasedHostDetector($serverHeaderToSearch), diff --git a/src/HostDetector/HostIdMapper.php b/src/HostDetector/HostIdMapper.php new file mode 100644 index 0000000..2c9ef3d --- /dev/null +++ b/src/HostDetector/HostIdMapper.php @@ -0,0 +1,37 @@ +inner = $inner; + $this->hostIdMap = $hostIdMap; + } + + public function getCurrentHost(): HostId + { + $innerHostId = $this->inner->getCurrentHost(); + $value = $this->hostIdMap[(string)$innerHostId] ?? ''; + + return new HostId($value); + } +} \ No newline at end of file diff --git a/tests/Unit/HostDetector/HostIdMapperTest.php b/tests/Unit/HostDetector/HostIdMapperTest.php new file mode 100644 index 0000000..9ec3e4a --- /dev/null +++ b/tests/Unit/HostDetector/HostIdMapperTest.php @@ -0,0 +1,64 @@ +inner = $this->createMock(HostDetectorInterface::class); + $this->mapper = new HostIdMapper($this->inner, [ + 'host_from_1' => 'host_to_1', + 'host_from_2' => 'host_to_2', + ]); + } + + /** + * @dataProvider dataGetCurrentHost + */ + public function testGetCurrentHost(HostId $innerResponse, HostId $expected): void + { + $this->inner + ->method('getCurrentHost') + ->willReturn($innerResponse); + + $result = $this->mapper->getCurrentHost(); + + $this->assertEquals($expected, $result); + } + + public function dataGetCurrentHost(): iterable + { + yield [ + new HostId(''), + new HostId(''), + ]; + + yield [ + new HostId('host_from_1'), + new HostId('host_to_1'), + ]; + + yield [ + new HostId('unknown'), + new HostId(''), + ]; + } +} \ No newline at end of file