diff --git a/src/ParameterResolver.php b/src/ParameterResolver.php index 3a3c86d..cd08789 100644 --- a/src/ParameterResolver.php +++ b/src/ParameterResolver.php @@ -114,7 +114,7 @@ protected function replaceSurroundingToken(string $parameter, string $token, cal { $oldParameter = $parameter; - while (mb_substr_count($parameter, $token) > 0) { + while (is_string($parameter) && mb_substr_count($parameter, $token) > 0) { $pos1 = mb_strpos($parameter, $token); $pos2 = mb_strpos($parameter, $token, $pos1 + 1); @@ -126,22 +126,25 @@ protected function replaceSurroundingToken(string $parameter, string $token, cal if ($pos2 === false) { throw new ConfigException("An uneven number of '{$token}' token bindings exists for '{$oldParameter}'"); } + $value = mb_substr($parameter, $pos1 + 1, $pos2 - ($pos1 + 1)); $newValue = $callable($value); - if (!is_string($newValue) && !is_numeric($newValue)) { - if (mb_strlen($value) + 2 === mb_strlen($parameter)) { - return $newValue; - } + // If it took up the entire parameter + if (($pos1 === 0 && ($pos2 + 1) === mb_strlen($parameter))) { + $parameter = $newValue; + continue; + } + + if (!is_string($newValue) && !is_numeric($newValue)) { throw new ConfigException( "Parameter '{$value}' as part of '{$oldParameter}' resolved to a non-string. This is only permissible if the parameter attempts no interpolation" ); } - $parameter = mb_substr($parameter, 0, $pos1) . $newValue . mb_substr($parameter, $pos2 + 1); } - return str_replace(self::ESCAPED_TOKEN, $token, $parameter); + return is_string($parameter) ? str_replace(self::ESCAPED_TOKEN, $token, $parameter) : $parameter; } public function getResolvedConstants() : array diff --git a/tests/integration/Basic/BasicTest.php b/tests/integration/Basic/BasicTest.php index b9cdf98..462969f 100644 --- a/tests/integration/Basic/BasicTest.php +++ b/tests/integration/Basic/BasicTest.php @@ -24,6 +24,9 @@ public function testBasic() $this->assertEquals("MyService1", $container["my_service"]->getFirstArgument()); $this->assertInstanceOf(ExampleClass::class, $container["my_service_2"]); $this->assertEquals("MyService2", $container["my_service_2"]->getFirstArgument()); + $arguments = $container["my_service_2"]->getArguments(); + + self::assertSame("potatosalad", $arguments[3]); } public function testBoolAndInt() diff --git a/tests/integration/Basic/file1.yml b/tests/integration/Basic/file1.yml index 9973fd4..3a8a9f7 100644 --- a/tests/integration/Basic/file1.yml +++ b/tests/integration/Basic/file1.yml @@ -10,6 +10,7 @@ services: - "%my_parameter_2%" - "%my_parameter_3%" - "%my_parameter_5%" + - "%my_parameter_7%%my_parameter_8%" parameters: my_parameter_2: "MyService2" @@ -19,3 +20,6 @@ parameters: my_parameter_5: "%my_parameter_6%" my_parameter_6: 5003 + + my_parameter_7: "potato" + my_parameter_8: "salad" \ No newline at end of file