Skip to content

Commit

Permalink
Support YAML config files and routes.yaml (see #1199)
Browse files Browse the repository at this point in the history
Description
-----------

fixes #1198

Commits
-------

7d7a184 Support YAML config files and routes.yaml
48901c2 Trigger a deprecation warning if the routes file is called "routing"
0d2584c Always check the new config directory first
a1a5332 Also load the routes.yaml file in the old app/config location
  • Loading branch information
aschempp authored and leofeyer committed Jan 17, 2020
1 parent 9c0502b commit 8516fbb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
22 changes: 13 additions & 9 deletions manager-bundle/src/HttpKernel/ContaoKernel.php
Expand Up @@ -189,7 +189,7 @@ public function setManagerConfig(ManagerConfig $managerConfig): void
*/
public function registerContainerConfiguration(LoaderInterface $loader): void
{
if ($parametersFile = $this->getConfigFile('parameters.yml')) {
if ($parametersFile = $this->getConfigFile('parameters')) {
$loader->load($parametersFile);
}

Expand All @@ -206,14 +206,14 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
$loader->load($parametersFile);
}

if ($configFile = $this->getConfigFile('config_'.$this->getEnvironment().'.yml')) {
if ($configFile = $this->getConfigFile('config_'.$this->getEnvironment())) {
$loader->load($configFile);
} elseif ($configFile = $this->getConfigFile('config.yml')) {
} elseif ($configFile = $this->getConfigFile('config')) {
$loader->load($configFile);
}

// Automatically load the services.yml file if it exists
if ($servicesFile = $this->getConfigFile('services.yml')) {
if ($servicesFile = $this->getConfigFile('services')) {
$loader->load($servicesFile);
}
}
Expand Down Expand Up @@ -339,15 +339,19 @@ private function getConfigFile(string $file): ?string
{
$rootDir = $this->getProjectDir();

if (file_exists($rootDir.'/config/'.$file)) {
return $rootDir.'/config/'.$file;
foreach (['.yaml', '.yml'] as $ext) {
if (file_exists($rootDir.'/config/'.$file.$ext)) {
return $rootDir.'/config/'.$file.$ext;
}
}

// Fallback to the legacy config file (see #566)
if (file_exists($rootDir.'/app/config/'.$file)) {
@trigger_error(sprintf('Storing the "%s" file in the "app/config" folder has been deprecated and will no longer work in Contao 5.0. Move it to the "config" folder instead.', $file), E_USER_DEPRECATED);
foreach (['.yaml', '.yml'] as $ext) {
if (file_exists($rootDir.'/app/config/'.$file.$ext)) {
@trigger_error(sprintf('Storing the "%s" file in the "app/config" folder has been deprecated and will no longer work in Contao 5.0. Move it to the "config" folder instead.', $file.$ext), E_USER_DEPRECATED);

return $rootDir.'/app/config/'.$file;
return $rootDir.'/app/config/'.$file.$ext;
}
}

return null;
Expand Down
22 changes: 15 additions & 7 deletions manager-bundle/src/Routing/RouteLoader.php
Expand Up @@ -71,7 +71,7 @@ function (RouteCollection $collection, RoutingPluginInterface $plugin): RouteCol
);

// Load the routing.yml file if it exists
if ($configFile = $this->getConfigFile('routing.yml')) {
if ($configFile = $this->getConfigFile()) {
$routes = $this->loader->getResolver()->resolve($configFile)->load($configFile);

if ($routes instanceof RouteCollection) {
Expand All @@ -89,17 +89,25 @@ function (RouteCollection $collection, RoutingPluginInterface $plugin): RouteCol
return $collection;
}

private function getConfigFile(string $file): ?string
private function getConfigFile(): ?string
{
if (file_exists($this->rootDir.'/config/'.$file)) {
return $this->rootDir.'/config/'.$file;
foreach (['routes.yaml', 'routes.yml', 'routing.yaml', 'routing.yml'] as $file) {
if (file_exists($this->rootDir.'/config/'.$file)) {
if (0 === strncmp($file, 'routing.', 8)) {
@trigger_error(sprintf('Using a "%s" file has been deprecated and will no longer work in Contao 5.0. Rename it to "routes.yaml" instead.', $file), E_USER_DEPRECATED);
}

return $this->rootDir.'/config/'.$file;
}
}

// Fallback to the legacy config file (see #566)
if (file_exists($this->rootDir.'/app/config/'.$file)) {
@trigger_error(sprintf('Storing the "%s" file in the "app/config" folder has been deprecated and will no longer work in Contao 5.0. Move it to the "config" folder instead.', $file), E_USER_DEPRECATED);
foreach (['routes.yaml', 'routes.yml', 'routing.yaml', 'routing.yml'] as $file) {
if (file_exists($this->rootDir.'/app/config/'.$file)) {
@trigger_error(sprintf('Storing the "%s" file in the "app/config" folder has been deprecated and will no longer work in Contao 5.0. Move it to the "config" folder instead.', $file), E_USER_DEPRECATED);

return $this->rootDir.'/app/config/'.$file;
return $this->rootDir.'/app/config/'.$file;
}
}

return null;
Expand Down

0 comments on commit 8516fbb

Please sign in to comment.