$this->getModulesList(\Modules::getStructure()), 'modulesWithValues' => $this->getModulesList(\Modules::getStructure(), withValues: true), 'bundles' => $this->bundleFinder->getBundles(), 'frontend_bundles' => [], 'components' => iterator_to_array($this->getComponents()), ]; if ($bundlesWithJSResources = $this->bundleFinder->getExistingBundlesPath('Resources/static')) { $config['frontend_bundles'] = $bundlesWithJSResources; } if (findModule(\Modules::COMPONENTS)) { Mapping::withKeys($this->bundleFinder->getBundles(), function ($bundle, $class) use (&$config) { $bundles = $this->bundleFinder->getContainer()->getParameter('kernel.bundles_metadata'); if (file_exists("{$bundles[$bundle]['path']}/Resources/views/components")) { if (StringUtil::startsWith($bundles[$bundle]['namespace'], 'Shop')) { $config['twig_bundles'][$bundle] = "bundles/{$bundle}/Resources/views/"; } else { $config['twig_bundles'][$bundle] = "engine/bundles/KupShop/{$bundle}/Resources/views/"; } } }); } $output->write(json_encode($config)); return 0; } private function getModulesList(array $structure, ?string $parent = null, bool $withValues = false): array { $modules = []; foreach ($structure as $key => $item) { $moduleKey = $key; if ($parent) { $moduleKey = $parent.'__'.$key; } $modules[$moduleKey] = $withValues ? $this->getModuleValue($parent ?: $key, $parent ? $key : null) : \Modules::check($parent ?: $key, $parent ? $key : null); if (!empty($item['submodules'])) { $modules = array_merge($modules, $this->getModulesList($item['submodules'], $key, $withValues)); } } return $modules; } private function getModuleValue(string $moduleConst, ?string $submoduleName) { $modules = \Modules::getStructure(); $module = $modules[$moduleConst]['value'] ?? null; $submodule = $modules[$moduleConst]['submodules'][$submoduleName]['value'] ?? null; if (empty($module)) { return false; } if (!empty($submoduleName) && empty($submodule)) { return false; } return findModule($module, $submodule, false); } protected function getComponents(): \Generator { if (!$this->componentsLocator) { return; } foreach ($this->componentsLocator->getComponents() as $component) { // If component not used on shop, skip if (!isset($component['shop'])) { continue; } yield $component['name'] => [ 'version' => $component['shop']['version'], 'version_js' => $component['shop']['js'], 'version_css' => $component['shop']['css'], 'entrypoints' => $component['entrypoints'], 'template' => $component['template'], 'class' => $component['className'], 'selector' => "'[data-component=\"{$component['className']}\"]'", ]; } } }