13
13
14
14
use Symfony \Bundle \FrameworkBundle \Controller \RedirectController ;
15
15
use Symfony \Bundle \FrameworkBundle \Controller \TemplateController ;
16
+ use Symfony \Component \Config \Util \Exception \XmlParsingException ;
16
17
use Symfony \Component \Config \Util \XmlUtils ;
17
18
use Symfony \Component \Routing \Loader \XmlFileLoader as BaseXmlFileLoader ;
18
19
use Symfony \Component \Routing \RouteCollection ;
@@ -26,6 +27,10 @@ class XmlFileLoader extends BaseXmlFileLoader
26
27
27
28
private const REDEFINED_SCHEME_URI = 'https://symfony.com/schema/routing/routing-1.0.xsd ' ;
28
29
private const SCHEME_URI = 'https://symfony.com/schema/routing/framework-routing-1.0.xsd ' ;
30
+ private const SCHEMA_LOCATIONS = [
31
+ self ::REDEFINED_SCHEME_URI => parent ::SCHEME_PATH ,
32
+ self ::SCHEME_URI => self ::SCHEME_PATH ,
33
+ ];
29
34
30
35
/** @var \DOMDocument */
31
36
private $ document ;
@@ -35,8 +40,14 @@ class XmlFileLoader extends BaseXmlFileLoader
35
40
protected function loadFile (string $ file )
36
41
{
37
42
try {
43
+ foreach (self ::SCHEMA_LOCATIONS as $ uri => $ path ) {
44
+ if (false !== strpos ($ file , $ uri )) {
45
+ $ file = str_replace ([$ uri , '\\' ], ['file:/// ' .realpath ($ path ), '/ ' ], $ file );
46
+ }
47
+ }
48
+
38
49
return $ this ->document = parent ::loadFile ($ file );
39
- } catch (\ Exception $ e ) {
50
+ } catch (XmlParsingException $ e ) {
40
51
if (0 === strpos ($ e ->getMessage (), sprintf ('[WARNING 1549] failed to load external entity "%s" ' , self ::REDEFINED_SCHEME_URI ))) {
41
52
if (!is_writable (self ::SCHEME_PATH )) {
42
53
throw new \RuntimeException (sprintf ('"%s" is not writeable. ' , self ::SCHEME_PATH ), 0 , $ e );
@@ -54,12 +65,6 @@ protected function loadFile(string $file)
54
65
55
66
return $ this ->loadFile ($ file );
56
67
}
57
- if (0 === strpos ($ e ->getMessage (), sprintf ('[WARNING 1549] failed to load external entity "%s" ' , self ::SCHEME_URI ))
58
- // workaround testing on Windows
59
- || false !== strpos ($ e ->getMessage (), 'C:\projects\symfony\src\Symfony\Bundle\FrameworkBundle\Tests ' )
60
- ) {
61
- return $ this ->loadFile (str_replace ([self ::SCHEME_URI , '\\' ], ['file:/// ' .realpath (self ::SCHEME_PATH ), '/ ' ], $ file ));
62
- }
63
68
64
69
throw $ e ;
65
70
} finally {
0 commit comments