@@ -82,9 +82,10 @@ Kernel. Be sure to also change the location of the cache, logs and configuration
82
82
files so they don't collide with the files from ``src/Kernel.php ``::
83
83
84
84
// src/ApiKernel.php
85
- use Symfony\Component\Config\Loader\LoaderInterface;
86
- use Symfony\Component\DependencyInjection\ContainerBuilder;
87
- use Symfony\Component\HttpKernel\Kernel;
85
+ use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
86
+ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
87
+ use Symfony\Component\HttpKernel\Kernel as BaseKernel;
88
+ use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
88
89
89
90
class ApiKernel extends Kernel
90
91
{
@@ -101,36 +102,33 @@ files so they don't collide with the files from ``src/Kernel.php``::
101
102
}
102
103
}
103
104
104
- public function getProjectDir(): string
105
- {
106
- return \dirname(__DIR__);
107
- }
108
-
109
105
public function getCacheDir(): string
110
106
{
111
- return $this->getProjectDir().'/var/cache/api/'.$this->getEnvironment() ;
107
+ return $this->getProjectDir().'/var/cache/api/'.$this->environment ;
112
108
}
113
109
114
110
public function getLogDir(): string
115
111
{
116
112
return $this->getProjectDir().'/var/log/api';
117
113
}
118
114
119
- public function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
115
+ protected function configureContainer(ContainerConfigurator $container): void
120
116
{
121
- $container->addResource(new FileResource($this->getProjectDir().'/config/api_bundles.php'));
122
- $container->setParameter('container.dumper.inline_factories', true);
123
- $confDir = $this->getProjectDir().'/config/api';
124
-
125
- $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
126
- $loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob');
127
- $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
128
- $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
117
+ $container->import('../config/api/{packages}/*.yaml');
118
+ $container->import('../config/api/{packages}/'.$this->environment.'/*.yaml');
119
+
120
+ if (is_file(\dirname(__DIR__).'/config/api/services.yaml')) {
121
+ $container->import('../config/api/services.yaml');
122
+ $container->import('../config/api/{services}_'.$this->environment.'.yaml');
123
+ } else {
124
+ $container->import('../config/api/{services}.php');
125
+ }
129
126
}
130
127
131
- protected function configureRoutes(RouteCollectionBuilder $routes): void
128
+ protected function configureRoutes(RoutingConfigurator $routes): void
132
129
{
133
- $confDir = $this->getProjectDir().'/config/api';
130
+ $routes->import('../config/api/{routes}/'.$this->environment.'/*.yaml');
131
+ $routes->import('../config/api/{routes}/*.yaml');
134
132
// ... load only the config routes strictly needed for the API
135
133
}
136
134
}
0 commit comments