@@ -40,14 +40,16 @@ final class ApiLoader extends Loader
40
40
private $ resourceMetadataFactory ;
41
41
private $ resourcePathGenerator ;
42
42
private $ container ;
43
+ private $ formats ;
43
44
44
- public function __construct (KernelInterface $ kernel , ResourceNameCollectionFactoryInterface $ resourceNameCollectionFactory , ResourceMetadataFactoryInterface $ resourceMetadataFactory , ResourcePathNamingStrategyInterface $ resourcePathGenerator , ContainerInterface $ container )
45
+ public function __construct (KernelInterface $ kernel , ResourceNameCollectionFactoryInterface $ resourceNameCollectionFactory , ResourceMetadataFactoryInterface $ resourceMetadataFactory , ResourcePathNamingStrategyInterface $ resourcePathGenerator , ContainerInterface $ container, array $ formats )
45
46
{
46
47
$ this ->fileLoader = new XmlFileLoader (new FileLocator ($ kernel ->locateResource ('@ApiPlatformBundle/Resources/config/routing ' )));
47
48
$ this ->resourceNameCollectionFactory = $ resourceNameCollectionFactory ;
48
49
$ this ->resourceMetadataFactory = $ resourceMetadataFactory ;
49
50
$ this ->resourcePathGenerator = $ resourcePathGenerator ;
50
51
$ this ->container = $ container ;
52
+ $ this ->formats = $ formats ;
51
53
}
52
54
53
55
/**
@@ -57,9 +59,7 @@ public function load($data, $type = null)
57
59
{
58
60
$ routeCollection = new RouteCollection ();
59
61
60
- $ routeCollection ->addCollection ($ this ->fileLoader ->load ('hal.xml ' ));
61
- $ routeCollection ->addCollection ($ this ->fileLoader ->load ('jsonld.xml ' ));
62
- $ routeCollection ->addCollection ($ this ->fileLoader ->load ('hydra.xml ' ));
62
+ $ this ->loadExternalFiles ($ routeCollection );
63
63
64
64
if ($ this ->container ->getParameter ('api_platform.enable_swagger ' )) {
65
65
$ routeCollection ->addCollection ($ this ->fileLoader ->load ('swagger.xml ' ));
@@ -92,6 +92,21 @@ public function supports($resource, $type = null)
92
92
return 'api_platform ' === $ type ;
93
93
}
94
94
95
+ /**
96
+ * Load external files.
97
+ *
98
+ * @param RouteCollection $routeCollection
99
+ */
100
+ private function loadExternalFiles (RouteCollection $ routeCollection )
101
+ {
102
+ $ routeCollection ->addCollection ($ this ->fileLoader ->load ('api.xml ' ));
103
+
104
+ if (isset ($ this ->formats ['jsonld ' ])) {
105
+ $ routeCollection ->addCollection ($ this ->fileLoader ->load ('jsonld.xml ' ));
106
+ $ routeCollection ->addCollection ($ this ->fileLoader ->load ('hydra.xml ' ));
107
+ }
108
+ }
109
+
95
110
/**
96
111
* Creates and adds a route for the given operation to the route collection.
97
112
*
0 commit comments