Skip to content

Fix issue while loading a container #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/Symfony/XmlServiceMapFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PHPStan\Symfony;

use function simplexml_load_file;
use function simplexml_load_string;
use function sprintf;
use function strpos;
use function substr;
Expand All @@ -20,7 +20,12 @@ public function __construct(string $containerXml)

public function create(): ServiceMap
{
$xml = @simplexml_load_file($this->containerXml);
$fileContents = file_get_contents($this->containerXml);
if ($fileContents === false) {
throw new XmlContainerNotExistsException(sprintf('Container %s does not exist or cannot be parsed', $this->containerXml));
}

$xml = @simplexml_load_string($fileContents);
if ($xml === false) {
throw new XmlContainerNotExistsException(sprintf('Container %s does not exist or cannot be parsed', $this->containerXml));
}
Expand Down
8 changes: 8 additions & 0 deletions tests/Symfony/ServiceMapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public function testGetService(string $id, callable $validator): void
$validator($factory->create()->getService($id));
}

public function testGetContainerEscapedPath(): void
{
$factory = new XmlServiceMapFactory(__DIR__ . '/containers/bugfix%2Fcontainer.xml');
$serviceMap = $factory->create();

self::assertNotNull($serviceMap->getService('withClass'));
}

public function getServiceProvider(): Iterator
{
yield [
Expand Down
13 changes: 13 additions & 0 deletions tests/Symfony/containers/bugfix%2Fcontainer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service></service><!-- without id -->
<service id="withoutClass"></service>
<service id="withClass" class="Foo"></service>
<service id="withoutPublic" class="Foo"></service>
<service id="publicNotFalse" class="Foo" public="true"></service>
<service id="private" class="Foo" public="false"></service>
<service id="synthetic" class="Foo" synthetic="true"></service>
<service id="alias" class="Bar" alias="withClass"></service>
</services>
</container>