From 20ea2a74c7fa8f937488cae5d9d3ae407dda8d9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Je=CC=81ro=CC=82me=20Vieilledent?= Date: Mon, 27 Mar 2017 10:30:26 +0200 Subject: [PATCH] Fix #20: Fatal if global themes directories don't exist --- DependencyInjection/Compiler/AssetThemePass.php | 14 ++++++++------ DependencyInjection/Compiler/TwigThemePass.php | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/DependencyInjection/Compiler/AssetThemePass.php b/DependencyInjection/Compiler/AssetThemePass.php index e12f0ff..5863209 100644 --- a/DependencyInjection/Compiler/AssetThemePass.php +++ b/DependencyInjection/Compiler/AssetThemePass.php @@ -49,12 +49,14 @@ public function process(ContainerBuilder $container) // Look for assets themes at application level (web/assets/themes). $appLevelThemeDir = $container->getParameter('webroot_dir').'/assets/themes'; - foreach ((new Finder())->directories()->in($appLevelThemeDir)->depth('== 0') as $directoryInfo) { - $theme = $directoryInfo->getBasename(); - $themePaths = isset($themesPathMap[$theme]) ? $themesPathMap[$theme] : []; - // Application level paths are always top priority. - array_unshift($themePaths, 'assets/themes/'.$theme); - $themesPathMap[$theme] = $themePaths; + if (is_dir($appLevelThemeDir)) { + foreach ((new Finder())->directories()->in($appLevelThemeDir)->depth('== 0') as $directoryInfo) { + $theme = $directoryInfo->getBasename(); + $themePaths = isset($themesPathMap[$theme]) ? $themesPathMap[$theme] : []; + // Application level paths are always top priority. + array_unshift($themePaths, 'assets/themes/'.$theme); + $themesPathMap[$theme] = $themePaths; + } } foreach ($themesPathMap as $theme => &$paths) { diff --git a/DependencyInjection/Compiler/TwigThemePass.php b/DependencyInjection/Compiler/TwigThemePass.php index 3a13ab5..ecaaf28 100644 --- a/DependencyInjection/Compiler/TwigThemePass.php +++ b/DependencyInjection/Compiler/TwigThemePass.php @@ -60,12 +60,14 @@ public function process(ContainerBuilder $container) $twigLoaderDef = $container->findDefinition('ez_core_extra.twig_theme_loader'); // Now look for themes at application level (app/Resources/views/themes) $appLevelThemesDir = $globalViewsDir.'/themes'; - foreach ((new Finder())->directories()->in($appLevelThemesDir)->depth('== 0') as $directoryInfo) { - $theme = $directoryInfo->getBasename(); - $themePaths = isset($themesPathMap[$theme]) ? $themesPathMap[$theme] : []; - // Application level paths are always top priority. - array_unshift($themePaths, $directoryInfo->getRealPath()); - $themesPathMap[$theme] = $themePaths; + if (is_dir($appLevelThemesDir)) { + foreach ((new Finder())->directories()->in($appLevelThemesDir)->depth('== 0') as $directoryInfo) { + $theme = $directoryInfo->getBasename(); + $themePaths = isset($themesPathMap[$theme]) ? $themesPathMap[$theme] : []; + // Application level paths are always top priority. + array_unshift($themePaths, $directoryInfo->getRealPath()); + $themesPathMap[$theme] = $themePaths; + } } // De-duplicate the map