Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 649c258

Browse files
Merge pull request #41 from jdeniau/patch-1
Fix issue while loading a container
2 parents 6b4d9f1 + da1b601 commit 649c258

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

‎src/Symfony/XmlServiceMapFactory.php‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace PHPStan\Symfony;
44

5-
use function simplexml_load_file;
5+
use function simplexml_load_string;
66
use function sprintf;
77
use function strpos;
88
use function substr;
@@ -20,7 +20,12 @@ public function __construct(string $containerXml)
2020

2121
public function create(): ServiceMap
2222
{
23-
$xml = @simplexml_load_file($this->containerXml);
23+
$fileContents = file_get_contents($this->containerXml);
24+
if ($fileContents === false) {
25+
throw new XmlContainerNotExistsException(sprintf('Container %s does not exist or cannot be parsed', $this->containerXml));
26+
}
27+
28+
$xml = @simplexml_load_string($fileContents);
2429
if ($xml === false) {
2530
throw new XmlContainerNotExistsException(sprintf('Container %s does not exist or cannot be parsed', $this->containerXml));
2631
}

‎tests/Symfony/ServiceMapTest.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ public function testGetService(string $id, callable $validator): void
1717
$validator($factory->create()->getService($id));
1818
}
1919

20+
public function testGetContainerEscapedPath(): void
21+
{
22+
$factory = new XmlServiceMapFactory(__DIR__ . '/containers/bugfix%2Fcontainer.xml');
23+
$serviceMap = $factory->create();
24+
25+
self::assertNotNull($serviceMap->getService('withClass'));
26+
}
27+
2028
public function getServiceProvider(): Iterator
2129
{
2230
yield [
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<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">
3+
<services>
4+
<service></service><!-- without id -->
5+
<service id="withoutClass"></service>
6+
<service id="withClass" class="Foo"></service>
7+
<service id="withoutPublic" class="Foo"></service>
8+
<service id="publicNotFalse" class="Foo" public="true"></service>
9+
<service id="private" class="Foo" public="false"></service>
10+
<service id="synthetic" class="Foo" synthetic="true"></service>
11+
<service id="alias" class="Bar" alias="withClass"></service>
12+
</services>
13+
</container>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /