Skip to content

Commit

Permalink
Merge pull request #2097 from dpfaffenbauer/issues/1896
Browse files Browse the repository at this point in the history
[ResourceBundle] class names with lower-case names
  • Loading branch information
dpfaffenbauer committed Nov 20, 2022
1 parent cf8c527 commit 32bf2c4
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 32bf2c4

Please sign in to comment.