diff --git a/.gitignore b/.gitignore index 660fc15..cc31cac 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ composer.lock /phpunit.xml .phpunit.result.cache +.idea diff --git a/src/Compiler.php b/src/Compiler.php index 76af861..c270caa 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -271,6 +271,10 @@ public function compileInclude($value) */ protected function compileServers($value) { + $value = preg_replace_callback('/@servers\(\[(.*?)\]\)/s', function ($matches) { + return '@servers(['.preg_replace('/\s+/', '', $matches[1]).'])'; + }, $value); + $pattern = $this->createMatcher('servers'); return preg_replace($pattern, '$1servers$2; ?>', $value); diff --git a/tests/CompilerTest.php b/tests/CompilerTest.php index 3ee66b7..2f0d0a3 100644 --- a/tests/CompilerTest.php +++ b/tests/CompilerTest.php @@ -32,4 +32,50 @@ public function test_compile_before_statement() $this->assertSame(1, preg_match('/\$__container->before\(.*?\}\);/s', $result, $matches)); } + + public function test_it_compiles_server_statement() + { + $str = <<<'EOL' +@servers([ + 'foo' => 'bar' +]) +EOL; + $compiler = new Compiler(); + $result = $compiler->compile($str); + + $this->assertSame($result, "servers(['foo'=>'bar']); ?>"); + + $str = <<<'EOL' +@servers([ + 'foo' => [ + 'bar', + 'baz', + 'bah' + ] +]) +EOL; + $compiler = new Compiler(); + $result = $compiler->compile($str); + + $this->assertSame($result, "servers(['foo'=>['bar','baz','bah']]); ?>"); + + $str = <<<'EOL' +@servers([ + 'foo' => ['bar'], + 'bar' => ['baz'] +]) +EOL; + $compiler = new Compiler(); + $result = $compiler->compile($str); + + $this->assertSame($result, "servers(['foo'=>['bar'],'bar'=>['baz']]); ?>"); + + $str = <<<'EOL' +@servers(['foo' => 'bar']) +EOL; + $compiler = new Compiler(); + $result = $compiler->compile($str); + + $this->assertSame($result, "servers(['foo'=>'bar']); ?>"); + } }