<commit_before><?php

/*
 * This file is part of the Sylius package.
 *
 * (c) <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Sylius\Bundle\AttributeBundle\DependencyInjection\Compiler;

use Sylius\Component\Attribute\Factory\AttributeFactory;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

final class RegisterAttributeFactoryPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container): void
    {
        if (!$container->hasDefinition('sylius.registry.attribute_type')) {
            return;
        }

        $registry = $container->getDefinition('sylius.registry.attribute_type');

        foreach (array_keys($container->getParameter('sylius.attribute.subjects')) as $subject) {
            $oldAttributeFactory = $container->getDefinition(sprintf('sylius.factory.%s_attribute', $subject));
            $attributeFactoryDefinition = new Definition(AttributeFactory::class, [$oldAttributeFactory, $registry]);
            $attributeFactoryDefinition->setPublic(true);

            $container->setDefinition(sprintf('sylius.factory.%s_attribute', $subject), $attributeFactoryDefinition);
        }
    }
}<commit_msg>#12051 fix attribute registry initialized twice<commit_after><?php

/*
 * This file is part of the Sylius package.
 *
 * (c) <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Sylius\Bundle\AttributeBundle\DependencyInjection\Compiler;

use Sylius\Component\Attribute\Factory\AttributeFactory;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

final class RegisterAttributeFactoryPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container): void
    {
        if (!$container->hasDefinition('sylius.registry.attribute_type')) {
            return;
        }

        $registry = new Reference('sylius.registry.attribute_type');

        foreach (array_keys($container->getParameter('sylius.attribute.subjects')) as $subject) {
            $oldAttributeFactory = $container->getDefinition(sprintf('sylius.factory.%s_attribute', $subject));
            $attributeFactoryDefinition = new Definition(AttributeFactory::class, [$oldAttributeFactory, $registry]);
            $attributeFactoryDefinition->setPublic(true);

            $container->setDefinition(sprintf('sylius.factory.%s_attribute', $subject), $attributeFactoryDefinition);
        }
    }
}
{'fraction_non_alphanumeric': 0.10479755018713849, 'fraction_numerical': 0.0023817625042531474, 'mean_word_length': 4.642994241842611, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4159243', 'n_tokens_mistral': 747, 'n_tokens_neox': 736, 'n_words': 152}