Merge pull request #766 from odolbeau/avoid-array-to-string-conversion

Avoid "array to string conversion" error
This commit is contained in:
William Durand 2015-12-11 09:12:17 +01:00
commit 93b189b16a
2 changed files with 29 additions and 2 deletions

View File

@ -478,8 +478,10 @@ class ApiDoc
$this->host = $route->getHost() ? : null; $this->host = $route->getHost() ? : null;
//replace route placeholders //replace route placeholders
foreach ($route->getDefaults() as $key => $value) { foreach ($route->getDefaults() as $key => $value) {
$this->host = str_replace('{' . $key . '}', $value, $this->host); if (is_string($value)) {
$this->host = str_replace('{' . $key . '}', $value, $this->host);
}
} }
} else { } else {
$this->host = null; $this->host = null;

View File

@ -13,6 +13,7 @@ namespace Nelmio\ApiDocBundle\Tests\Annotation;
use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Nelmio\ApiDocBundle\Tests\TestCase; use Nelmio\ApiDocBundle\Tests\TestCase;
use Symfony\Component\Routing\Route;
class ApiDocTest extends TestCase class ApiDocTest extends TestCase
{ {
@ -373,4 +374,28 @@ class ApiDocTest extends TestCase
$this->assertArrayHasKey(400, $map); $this->assertArrayHasKey(400, $map);
$this->assertEquals($apiDoc->getOutput(), $map[200]); $this->assertEquals($apiDoc->getOutput(), $map[200]);
} }
public function testSetRoute()
{
$route = new Route(
'/path/{foo}',
[
'foo' => 'bar',
'nested' => [
'key1' => 'value1',
'key2' => 'value2',
]
],
[],
[],
'{foo}.awesome_host.com'
);
$apiDoc = new ApiDoc([]);
$apiDoc->setRoute($route);
$this->assertSame($route, $apiDoc->getRoute());
$this->assertEquals('bar.awesome_host.com', $apiDoc->getHost());
$this->assertEquals('ANY', $apiDoc->getMethod());
}
} }