From 32bf2c4498b6d47fb84bf1bf6657ffacb2dd80fe Mon Sep 17 00:00:00 2001 From: Dominik Date: Wed, 16 Nov 2022 07:46:34 +0100 Subject: [PATCH] Merge pull request #2097 from dpfaffenbauer/issues/1896 [ResourceBundle] class names with lower-case names --- .../DependencyInjection/Configuration.php | 1 + .../DependencyInjection/Configuration.php | 1 + .../DependencyInjection/Configuration.php | 6 ++++++ .../DependencyInjection/Configuration.php | 3 +++ .../Controller/ResourceSettingsController.php | 18 ++++++++++++++++-- .../Compiler/StackClassesPass.php | 14 ++++++++------ .../DependencyInjection/Configuration.php | 1 + .../DependencyInjection/Configuration.php | 2 ++ 8 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/CoreShop/Bundle/AddressBundle/DependencyInjection/Configuration.php b/src/CoreShop/Bundle/AddressBundle/DependencyInjection/Configuration.php index ad30783f29..530dec2d32 100644 --- a/src/CoreShop/Bundle/AddressBundle/DependencyInjection/Configuration.php +++ b/src/CoreShop/Bundle/AddressBundle/DependencyInjection/Configuration.php @@ -202,6 +202,7 @@ private function addModelsSection(ArrayNodeDefinition $node): void ->addDefaultsIfNotSet() ->children() ->scalarNode('model')->defaultValue('Pimcore\Model\DataObject\CoreShopAddress')->cannotBeEmpty()->end() + ->scalarNode('pimcore_class_name')->end() ->scalarNode('interface')->defaultValue(AddressInterface::class)->cannotBeEmpty()->end() ->scalarNode('factory')->defaultValue(PimcoreFactory::class)->cannotBeEmpty()->end() ->scalarNode('repository')->cannotBeEmpty()->end() diff --git a/src/CoreShop/Bundle/CustomerBundle/DependencyInjection/Configuration.php b/src/CoreShop/Bundle/CustomerBundle/DependencyInjection/Configuration.php index 103e567e3d..00d916a0f5 100644 --- a/src/CoreShop/Bundle/CustomerBundle/DependencyInjection/Configuration.php +++ b/src/CoreShop/Bundle/CustomerBundle/DependencyInjection/Configuration.php @@ -82,6 +82,7 @@ private function addModelsSection(ArrayNodeDefinition $node): void ->addDefaultsIfNotSet() ->children() ->scalarNode('model')->defaultValue('Pimcore\Model\DataObject\CoreShopCompany')->cannotBeEmpty()->end() + ->scalarNode('pimcore_class_name')->end() ->scalarNode('interface')->defaultValue(CompanyInterface::class)->cannotBeEmpty()->end() ->scalarNode('factory')->defaultValue(PimcoreFactory::class)->cannotBeEmpty()->end() ->scalarNode('repository')->defaultValue(CompanyRepository::class)->cannotBeEmpty()->end() diff --git a/src/CoreShop/Bundle/OrderBundle/DependencyInjection/Configuration.php b/src/CoreShop/Bundle/OrderBundle/DependencyInjection/Configuration.php index 881d515513..9459bfd066 100644 --- a/src/CoreShop/Bundle/OrderBundle/DependencyInjection/Configuration.php +++ b/src/CoreShop/Bundle/OrderBundle/DependencyInjection/Configuration.php @@ -203,6 +203,7 @@ private function addModelsSection(ArrayNodeDefinition $node): void ->addDefaultsIfNotSet() ->children() ->scalarNode('model')->defaultValue('Pimcore\Model\DataObject\CoreShopOrder')->cannotBeEmpty()->end() + ->scalarNode('pimcore_class_name')->end() ->scalarNode('interface')->defaultValue(OrderInterface::class)->cannotBeEmpty()->end() ->scalarNode('factory')->defaultValue(PimcoreFactory::class)->cannotBeEmpty()->end() ->scalarNode('repository')->defaultValue(OrderRepository::class)->end() @@ -233,6 +234,7 @@ private function addModelsSection(ArrayNodeDefinition $node): void ->addDefaultsIfNotSet() ->children() ->scalarNode('model')->defaultValue('Pimcore\Model\DataObject\CoreShopOrderItem')->cannotBeEmpty()->end() + ->scalarNode('pimcore_class_name')->end() ->scalarNode('interface')->defaultValue(OrderItemInterface::class)->cannotBeEmpty()->end() ->scalarNode('factory')->defaultValue(PimcoreFactory::class)->cannotBeEmpty()->end() ->scalarNode('repository')->defaultValue(OrderItemRepository::class)->cannotBeEmpty()->end() @@ -251,6 +253,7 @@ private function addModelsSection(ArrayNodeDefinition $node): void ->addDefaultsIfNotSet() ->children() ->scalarNode('model')->defaultValue('Pimcore\Model\DataObject\CoreShopOrderInvoice')->cannotBeEmpty()->end() + ->scalarNode('pimcore_class_name')->end() ->scalarNode('interface')->defaultValue(OrderInvoiceInterface::class)->cannotBeEmpty()->end() ->scalarNode('factory')->defaultValue(PimcoreFactory::class)->cannotBeEmpty()->end() ->scalarNode('repository')->defaultValue(OrderInvoiceRepository::class)->end() @@ -270,6 +273,7 @@ private function addModelsSection(ArrayNodeDefinition $node): void ->addDefaultsIfNotSet() ->children() ->scalarNode('model')->defaultValue('Pimcore\Model\DataObject\CoreShopOrderInvoiceItem')->cannotBeEmpty()->end() + ->scalarNode('pimcore_class_name')->end() ->scalarNode('interface')->defaultValue(OrderInvoiceItemInterface::class)->cannotBeEmpty()->end() ->scalarNode('factory')->defaultValue(PimcoreFactory::class)->cannotBeEmpty()->end() ->scalarNode('repository')->cannotBeEmpty()->end() @@ -288,6 +292,7 @@ private function addModelsSection(ArrayNodeDefinition $node): void ->addDefaultsIfNotSet() ->children() ->scalarNode('model')->defaultValue('Pimcore\Model\DataObject\CoreShopOrderShipment')->cannotBeEmpty()->end() + ->scalarNode('pimcore_class_name')->end() ->scalarNode('interface')->defaultValue(OrderShipmentInterface::class)->cannotBeEmpty()->end() ->scalarNode('factory')->defaultValue(PimcoreFactory::class)->cannotBeEmpty()->end() ->scalarNode('repository')->defaultValue(OrderShipmentRepository::class)->end() @@ -307,6 +312,7 @@ private function addModelsSection(ArrayNodeDefinition $node): void ->addDefaultsIfNotSet() ->children() ->scalarNode('model')->defaultValue('Pimcore\Model\DataObject\CoreShopOrderShipmentItem')->cannotBeEmpty()->end() + ->scalarNode('pimcore_class_name')->end() ->scalarNode('interface')->defaultValue(OrderShipmentItemInterface::class)->cannotBeEmpty()->end() ->scalarNode('factory')->defaultValue(PimcoreFactory::class)->cannotBeEmpty()->end() ->scalarNode('repository')->cannotBeEmpty()->end() diff --git a/src/CoreShop/Bundle/ProductBundle/DependencyInjection/Configuration.php b/src/CoreShop/Bundle/ProductBundle/DependencyInjection/Configuration.php index c322505df6..61288fa780 100644 --- a/src/CoreShop/Bundle/ProductBundle/DependencyInjection/Configuration.php +++ b/src/CoreShop/Bundle/ProductBundle/DependencyInjection/Configuration.php @@ -259,6 +259,7 @@ private function addModelsSection(ArrayNodeDefinition $node): void ->addDefaultsIfNotSet() ->children() ->scalarNode('model')->defaultValue('Pimcore\Model\DataObject\CoreShopProduct')->cannotBeEmpty()->end() + ->scalarNode('pimcore_class_name')->end() ->scalarNode('interface')->defaultValue(ProductInterface::class)->cannotBeEmpty()->end() ->scalarNode('factory')->defaultValue(PimcoreFactory::class)->cannotBeEmpty()->end() ->scalarNode('admin_controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() @@ -278,6 +279,7 @@ private function addModelsSection(ArrayNodeDefinition $node): void ->addDefaultsIfNotSet() ->children() ->scalarNode('model')->defaultValue('Pimcore\Model\DataObject\CoreShopCategory')->cannotBeEmpty()->end() + ->scalarNode('pimcore_class_name')->end() ->scalarNode('interface')->defaultValue(CategoryInterface::class)->cannotBeEmpty()->end() ->scalarNode('factory')->defaultValue(PimcoreFactory::class)->cannotBeEmpty()->end() ->scalarNode('repository')->defaultValue(CategoryRepository::class)->end() @@ -296,6 +298,7 @@ private function addModelsSection(ArrayNodeDefinition $node): void ->addDefaultsIfNotSet() ->children() ->scalarNode('model')->defaultValue('Pimcore\Model\DataObject\CoreShopManufacturer')->cannotBeEmpty()->end() + ->scalarNode('pimcore_class_name')->end() ->scalarNode('interface')->defaultValue(ManufacturerInterface::class)->cannotBeEmpty()->end() ->scalarNode('factory')->defaultValue(PimcoreFactory::class)->cannotBeEmpty()->end() ->scalarNode('repository')->cannotBeEmpty()->end() diff --git a/src/CoreShop/Bundle/ResourceBundle/Controller/ResourceSettingsController.php b/src/CoreShop/Bundle/ResourceBundle/Controller/ResourceSettingsController.php index f3929c71b8..9b1935e58b 100644 --- a/src/CoreShop/Bundle/ResourceBundle/Controller/ResourceSettingsController.php +++ b/src/CoreShop/Bundle/ResourceBundle/Controller/ResourceSettingsController.php @@ -18,6 +18,7 @@ namespace CoreShop\Bundle\ResourceBundle\Controller; +use CoreShop\Bundle\ResourceBundle\CoreShopResourceBundle; use Pimcore\Model\Element\AbstractElement; use Pimcore\Model\Element\Service; use Symfony\Component\HttpFoundation\Request; @@ -55,12 +56,25 @@ public function getConfigAction(): Response $classes = $this->container->getParameter('coreshop.all.pimcore_classes'); foreach ($classes as $key => $definition) { + if (!isset($definition['classes']['type'])) { + continue; + } + + if ($definition['classes']['type'] !== CoreShopResourceBundle::PIMCORE_MODEL_TYPE_OBJECT) { + continue; + } + $alias = explode('.', $key); $application = $alias[0]; $alias = $alias[1]; - $class = str_replace('Pimcore\\Model\\DataObject\\', '', $definition['classes']['model']); - $class = str_replace('\\', '', $class); + if (isset($definition['classes']['pimcore_class_name'])) { + $class = $definition['classes']['pimcore_class_name']; + } + else { + $fullClassName = $definition['classes']['model']; + $class = str_replace(['Pimcore\\Model\\DataObject\\', '\\'], '', $fullClassName); + } $config['classMap'][$application][$alias] = $class; } diff --git a/src/CoreShop/Bundle/ResourceBundle/DependencyInjection/Compiler/StackClassesPass.php b/src/CoreShop/Bundle/ResourceBundle/DependencyInjection/Compiler/StackClassesPass.php index 99c141256a..c9022def9a 100644 --- a/src/CoreShop/Bundle/ResourceBundle/DependencyInjection/Compiler/StackClassesPass.php +++ b/src/CoreShop/Bundle/ResourceBundle/DependencyInjection/Compiler/StackClassesPass.php @@ -41,26 +41,28 @@ public function process(ContainerBuilder $container): void $classStack = []; $classStackPimcoreClassName = []; - $classStackPimcoreClassId = []; foreach ($stack as $alias => $interface) { [$applicationName, $name] = explode('.', $alias); $classStack[$alias] = []; $classStackPimcoreClassName[$alias] = []; - $classStackPimcoreClassId[$alias] = []; foreach ($classes as $definition) { if (!@interface_exists($definition['classes']['interface'])) { continue; } - if (in_array($interface, class_implements($definition['classes']['interface'])) || $interface === $definition['classes']['interface']) { + if ($interface === $definition['classes']['interface'] || in_array($interface, class_implements($definition['classes']['interface']), true)) { $classStack[$alias][] = $definition['classes']['model']; - $fullClassName = $definition['classes']['model']; - $class = str_replace('Pimcore\\Model\\DataObject\\', '', $fullClassName); - $class = str_replace('\\', '', $class); + if (isset($definition['classes']['pimcore_class_name'])) { + $class = $definition['classes']['pimcore_class_name']; + } + else { + $fullClassName = $definition['classes']['model']; + $class = str_replace(['Pimcore\\Model\\DataObject\\', '\\'], '', $fullClassName); + } $classStackPimcoreClassName[$alias][] = $class; } diff --git a/src/CoreShop/Bundle/ResourceBundle/DependencyInjection/Configuration.php b/src/CoreShop/Bundle/ResourceBundle/DependencyInjection/Configuration.php index d175868198..e5307693cc 100644 --- a/src/CoreShop/Bundle/ResourceBundle/DependencyInjection/Configuration.php +++ b/src/CoreShop/Bundle/ResourceBundle/DependencyInjection/Configuration.php @@ -97,6 +97,7 @@ private function addResourcesSection(ArrayNodeDefinition $node): void ->arrayNode('classes') ->children() ->scalarNode('model')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('pimcore_class_name')->end() ->scalarNode('interface')->cannotBeEmpty()->end() ->scalarNode('repository')->cannotBeEmpty()->defaultValue(PimcoreRepository::class)->end() ->scalarNode('factory')->defaultValue(PimcoreFactory::class)->end() diff --git a/src/CoreShop/Bundle/WishlistBundle/DependencyInjection/Configuration.php b/src/CoreShop/Bundle/WishlistBundle/DependencyInjection/Configuration.php index 558d11fb0c..0dd589a63e 100644 --- a/src/CoreShop/Bundle/WishlistBundle/DependencyInjection/Configuration.php +++ b/src/CoreShop/Bundle/WishlistBundle/DependencyInjection/Configuration.php @@ -82,6 +82,7 @@ private function addModelsSection(ArrayNodeDefinition $node): void ->addDefaultsIfNotSet() ->children() ->scalarNode('model')->defaultValue('Pimcore\Model\DataObject\CoreShopWishlist')->cannotBeEmpty()->end() + ->scalarNode('pimcore_class_name')->end() ->scalarNode('interface')->defaultValue(WishlistInterface::class)->cannotBeEmpty()->end() ->scalarNode('factory')->defaultValue(PimcoreFactory::class)->cannotBeEmpty()->end() ->scalarNode('repository')->defaultValue(WishlistRepository::class)->end() @@ -100,6 +101,7 @@ private function addModelsSection(ArrayNodeDefinition $node): void ->addDefaultsIfNotSet() ->children() ->scalarNode('model')->defaultValue('Pimcore\Model\DataObject\CoreShopWishlistItem')->cannotBeEmpty()->end() + ->scalarNode('pimcore_class_name')->end() ->scalarNode('interface')->defaultValue(WishlistItemInterface::class)->cannotBeEmpty()->end() ->scalarNode('factory')->defaultValue(PimcoreFactory::class)->cannotBeEmpty()->end() ->scalarNode('repository')->defaultValue(WishlistItemRepository::class)->cannotBeEmpty()->end()