Load data fixtures with the passed EntityManager

@param ObjectManager $manager
496950
public function load(ObjectManager $manager)
    {
        $this->manager = $manager;
        $options = $this->getOptions();

        $parser = new Parser();

        $data = [];
        foreach ($this->getFixtures() as $fixture) {
            $data[] = $parser->parse(file_get_contents($fixture));
        }

        $fixtures = $this->initFixtures($data);
        $builder = $this->container->get('kunstmaan_fixtures.builder.builder');
        $locale = isset($options['locale']) ? $options['locale'] : 'en_US';

        foreach ($this->getProviders() as $provider) {
            $builder->addProvider($provider);
        }

        /*
         * because of faker's magic calls we'll want to add this as last provider
         */
        $builder->addProvider(Factory::create($locale));
        $builder->setFixtures($fixtures);
        $builder->buildFixtures($manager);
    }
1044184
public function load(ObjectManager $manager)
    {
        $this->repo = $manager->getRepository('Kunstmaan\TranslatorBundle\Entity\Translation');

        $helloWorld = new Model();
        $helloWorld->setKeyword('heading.hello_world');
        $helloWorld->setDomain('messages');

        $translations = array(
            'en' => 'Hello World!',
            'fr' => 'Bonjour tout le monde',
            'nl' => 'Hallo wereld!',
        );

        $needForFlush = false;
        foreach ($translations as $language => $text) {
            if ($this->hasFixtureInstalled('messages', 'heading.hello_world', $language)) {
                continue;
            }

            $helloWorld->addText($language, $text);
            $needForFlush = true;
        }

        $this->repo->createTranslations($helloWorld);

        if ($needForFlush === true) {
            $manager->flush();
        }
    }
1111336
public function loaderModels(ClassMetadata $class, $manager, array $ids, \Closure $stacker)
    {
        $classOfManagerName = $class->getFieldMapping($manager);

        $pool       = $this->manager->getPool();
        $methodFind = $classOfManagerName->getRepositoryMethod();

        $repository = $pool->getManager($manager)->getRepository($classOfManagerName->getName());

        if ($methodFind && method_exists($repository, $methodFind)) {
            foreach ($repository->$methodFind($ids) as $object) {
                $id = $class->getIdentifierValue($object);

                $stacker($id, $object);
            }
        } else {
            trigger_error(sprintf('findOneBy in ModelPersister::loadAll context is depreciate. Define repository-method for "%s" manager model, see mapping for "%s".', $manager, $class->getName()), E_USER_DEPRECATED);

            $repository = $pool->getManager($manager)->getRepository($classOfManagerName->getName());
            $field      = $class->getIdentifierReference($manager)->field;

            foreach ($ids as $id) {
                $object = $repository->findOneBy(array($field => $id));

                if (!$object) {
                    continue;
                }

                $id = $class->getIdentifierValue($object, $manager);

                $stacker($id, $object);
            }
        }
    }
776833
public function load(ObjectManager $manager)
    {
        /**
         * Carts.
         *
         * @var CartInterface     $emptyCart
         * @var CartInterface     $fullCart
         * @var CustomerInterface $customer1
         * @var CustomerInterface $customer2
         * @var ProductInterface  $product
         * @var ProductInterface  $productReduced
         * @var CartLineInterface $cartLine1
         * @var CartLineInterface $cartLine2
         * @var ObjectDirector    $cartDirector
         * @var ObjectDirector    $cartLineDirector
         * @var AddressInterface  $address1
         * @var AddressInterface  $address2
         */
        $cartDirector = $this->getDirector('cart');
        $cartLineDirector = $this->getDirector('cart_line');

        $customer1 = $this->getReference('customer-1');
        $customer2 = $this->getReference('customer-2');
        $product = $this->getReference('product');
        $productReduced = $this->getReference('product-reduced');

        $address1 = $this->getReference('address-sant-celoni');
        $address2 = $this->getReference('address-viladecavalls');

        /**
         * Empty cart.
         */
        $emptyCart = $cartDirector
            ->create()
            ->setCustomer($customer1);

        $cartDirector->save($emptyCart);
        $this->addReference('empty-cart', $emptyCart);

        /**
         * Full cart.
         */
        $fullCart = $cartDirector
            ->create()
            ->setCustomer($customer2);

        $cartLine1 = $cartLineDirector
            ->create()
            ->setPurchasable($product)
            ->setPurchasableAmount($product->getPrice())
            ->setAmount($product->getPrice())
            ->setQuantity(2)
            ->setCart($fullCart);

        $cartLine2 = $cartLineDirector
            ->create()
            ->setPurchasable($productReduced)
            ->setPurchasableAmount($productReduced->getPrice())
            ->setAmount($productReduced->getPrice())
            ->setQuantity(2)
            ->setCart($fullCart);

        $fullCart
            ->addCartLine($cartLine1)
            ->addCartLine($cartLine2);

        $fullCart->setBillingAddress($address1);
        $fullCart->setDeliveryAddress($address2);

        $cartDirector->save($fullCart);
        $this->addReference('full-cart', $fullCart);
    }
1251495
public function load(ObjectManager $manager) {
    $c = $this->project->getUserClass();
		
    $user = new $c('p.scheit@ps-webforge.com');
    $user->setPassword('583cdd008f2ea237bfe4d39a2d827f42');
    $manager->persist($user);

    $user = new $c('psc-laptop@ps-webforge.com');
    $user->setPassword('9606fe7ecf5e4e76e4fa0f07c97e3e49');
    $manager->persist($user);

    $hostConfig = $this->project->getHostConfig();
    $user = new $c($hostConfig->req('cmf.user'));
    $user->hashPassword($hostConfig->req('cmf.password'));
    $manager->persist($user);
  }
324745
public function load(ObjectManager $manager)
    {
        $group1 = $this->createGroup($manager, 'Administrators', array(
            $this->getReference(RoleFixtures::REFERENCE_PERMISSIONMANAGER_ROLE),
            $this->getReference(RoleFixtures::REFERENCE_ADMIN_ROLE),
        ));

        $group2 = $this->createGroup($manager, 'Guests', array(
            $this->getReference(RoleFixtures::REFERENCE_GUEST_ROLE),
        ));

        $group3 = $this->createGroup($manager, 'Super administrators', array(
            $this->getReference(RoleFixtures::REFERENCE_PERMISSIONMANAGER_ROLE),
            $this->getReference(RoleFixtures::REFERENCE_ADMIN_ROLE),
            $this->getReference(RoleFixtures::REFERENCE_SUPERADMIN_ROLE),
        ));

        $manager->flush();

        $this->addReference(self::REFERENCE_ADMINS_GROUP, $group1);
        $this->addReference(self::REFERENCE_GUESTS_GROUP, $group2);
        $this->addReference(self::REFERENCE_SUPERADMINS_GROUP, $group3);
    }
477081
public function load(ObjectManager $manager)
    {
        $food          = new Category('Food');
        $fruit         = new Category('Fruit');

        $apples        = new Category('Apples');
        $apples->setUnitDescriptionSingular('lb');
        $apples->setUnitDescriptionPlural('lbs');

        $vegetables    = new Category('Vegetables');

        $tomatoes      = new Category('Tomatoes');
        $tomatoes->setUnitDescriptionSingular('lb');
        $tomatoes->setUnitDescriptionPlural('lbs');

        $carrots       = new Category('Carrots');
        $carrots->setUnitDescriptionSingular('lb');
        $carrots->setUnitDescriptionPlural('lbs');

        $sweetPotatoes = new Category('Sweet Potatoes');
        $sweetPotatoes->setUnitDescriptionSingular('lb');
        $sweetPotatoes->setUnitDescriptionPlural('lbs');

        $onions        = new Category('Onions');
        $onions->setUnitDescriptionSingular('lb');
        $onions->setUnitDescriptionPlural('lbs');

        $meat          = new Category('Meat');
        $dairy         = new Category('Dairy');

        $milk          = new Category('Milk');
        $milk->setUnitDescriptionSingular('quart');
        $milk->setUnitDescriptionPlural('quarts');

        $eggs          = new Category('Eggs');
        $eggs->setUnitDescriptionSingular('dozen');
        $eggs->setUnitDescriptionPlural('dozen');

        $food->addCategory($fruit);
          $fruit->addCategory($apples);
        $food->addCategory($vegetables);
          $vegetables->addCategory($tomatoes);
          $vegetables->addCategory($carrots);
          $vegetables->addCategory($sweetPotatoes);
          $vegetables->addCategory($onions);
        $food->addCategory($meat);
        $food->addCategory($dairy);
          $dairy->addCategory($milk);
          $dairy->addCategory($eggs);

        $manager->persist($food);
        $manager->flush();

        $this->addReference('eggs-category', $eggs);
        $this->addReference('tomatoes-category', $tomatoes);
        $this->addReference('milk-category', $milk);
        $this->addReference('apples-category', $apples);
        $this->addReference('carrots-category', $carrots);
        $this->addReference('onions-category', $onions);
        $this->addReference('sweet-potatoes-category', $sweetPotatoes);
    }
250659
protected function loadFixtures(
        LoaderInterface $loader,
        EntityManagerInterface $manager,
        array $files,
        array $parameters,
        ?PurgeMode $purgeMode
    ) {
        $persister = $this->createPersister($manager);

        $loader = $loader->withPersister($persister);

        return $loader->load($files, $parameters, [], $purgeMode);
    }
1221668
public function load(ObjectManager $manager)
    {
        $testClient = new ApiClient();
        $testClient->setName('Test client');
        $testClient->setKey('test_key');
        $testClient->setSecret('test_secret');
        $testClient->setTrusted(true);

        $manager->persist($testClient);
        $manager->flush();
    }
889920
public function load(ObjectManager $manager)
    {
        // Assumes first user is admin user
        $user = $manager->find('OrkestraApplicationBundle:User', 1);

        $author = new Author();
        $author->setUser($user);
        $manager->persist($author);

        $menu = new Menu();
        $menu->setName('main_nav');
        $menu->setType('main_nav');
        $menu->setDefinition($this->getMainNavDefinition());
        $manager->persist($menu);

        $manager->flush();
    }
1252918
public function load(ObjectManager $manager)
    {
        $nodeRepository = $this->container->get('open_orchestra_model.repository.redirection');
        $nodes = $nodeRepository->findAll();
        $updateRoute = $this->container->get('open_orchestra_backoffice.manager.route_document');

        foreach ($nodes as $node) {
            $routes = $updateRoute->createOrUpdateForRedirection($node);
            foreach ($routes as $route) {
                $manager->persist($route);
            }
        }

        $manager->flush();
    }
1207909
public function load(ObjectManager $manager)
    {
        /**
         * @var ObjectDirector $currencyDirector
         */
        $currencyDirector = $this->getDirector('currency');

        /**
         * Dollar.
         */
        $currencyDollar = $currencyDirector
            ->create()
            ->setName('Dollar')
            ->setSymbol('$')
            ->setIso('USD');

        $currencyDirector->save($currencyDollar);
        $this->setReference('currency-dollar', $currencyDollar);

        /**Euro
         */
        $currencyEuro = $currencyDirector
            ->create()
            ->setName('Euro')
            ->setSymbol('€')
            ->setIso('EUR');

        $currencyDirector->save($currencyEuro);
        $this->setReference('currency-euro', $currencyEuro);

        /**
         * Pound.
         */
        $currencyPound = $currencyDirector
            ->create()
            ->setName('Pound')
            ->setSymbol('£')
            ->setIso('GBP');

        $currencyDirector->save($currencyPound);
        $this->setReference('currency-pound', $currencyPound);

        /**
         * Ien.
         */
        $currencyIen = $currencyDirector
            ->create()
            ->setName('Yen')
            ->setSymbol('円')
            ->setIso('JPY');

        $currencyDirector->save($currencyIen);
        $this->setReference('currency-ien', $currencyIen);
    }
1365002
protected function loadMappingInformation(array $objectManager, ContainerBuilder $container)
    {
        if ($objectManager['auto_mapping']) {
            // automatically register bundle mappings
            foreach (array_keys($container->getParameter('kernel.bundles')) as $bundle) {
                if (!isset($objectManager['mappings'][$bundle])) {
                    $objectManager['mappings'][$bundle] = [
                        'mapping' => true,
                        'is_bundle' => true,
                    ];
                }
            }
        }

        foreach ($objectManager['mappings'] as $mappingName => $mappingConfig) {
            if (null !== $mappingConfig && false === $mappingConfig['mapping']) {
                continue;
            }

            $mappingConfig = array_replace([
                'dir' => false,
                'type' => false,
                'prefix' => false,
            ], (array) $mappingConfig);

            $mappingConfig['dir'] = $container->getParameterBag()->resolveValue($mappingConfig['dir']);
            // a bundle configuration is detected by realizing that the specified dir is not absolute and existing
            if (!isset($mappingConfig['is_bundle'])) {
                $mappingConfig['is_bundle'] = !is_dir($mappingConfig['dir']);
            }

            if ($mappingConfig['is_bundle']) {
                $bundle = null;
                foreach ($container->getParameter('kernel.bundles') as $name => $class) {
                    if ($mappingName === $name) {
                        $bundle = new \ReflectionClass($class);

                        break;
                    }
                }

                if (null === $bundle) {
                    throw new \InvalidArgumentException(sprintf('Bundle "%s" does not exist or it is not enabled.', $mappingName));
                }

                $mappingConfig = $this->getMappingDriverBundleConfigDefaults($mappingConfig, $bundle, $container);
                if (!$mappingConfig) {
                    continue;
                }
            }

            $this->assertValidMappingConfiguration($mappingConfig, $objectManager['name']);
            $this->setMappingDriverConfig($mappingConfig, $mappingName);
            $this->setMappingDriverAlias($mappingConfig, $mappingName);
        }
    }
817333
protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $container)
    {
        $ormConfigDef = $container->setDefinition(sprintf('doctrine.orm.%s_configuration', $entityManager['name']), new ChildDefinition('doctrine.orm.configuration'));

        $this->loadOrmEntityManagerMappingInformation($entityManager, $ormConfigDef, $container);
        $this->loadOrmCacheDrivers($entityManager, $container);

        if (isset($entityManager['entity_listener_resolver']) && $entityManager['entity_listener_resolver']) {
            $container->setAlias(sprintf('doctrine.orm.%s_entity_listener_resolver', $entityManager['name']), $entityManager['entity_listener_resolver']);
        } else {
            $definition = new Definition('%doctrine.orm.entity_listener_resolver.class%');
            $definition->addArgument(new Reference('service_container'));
            $container->setDefinition(sprintf('doctrine.orm.%s_entity_listener_resolver', $entityManager['name']), $definition);
        }

        $methods = [
            'setMetadataCacheImpl' => new Reference(sprintf('doctrine.orm.%s_metadata_cache', $entityManager['name'])),
            'setQueryCacheImpl' => new Reference(sprintf('doctrine.orm.%s_query_cache', $entityManager['name'])),
            'setResultCacheImpl' => new Reference(sprintf('doctrine.orm.%s_result_cache', $entityManager['name'])),
            'setMetadataDriverImpl' => new Reference('doctrine.orm.' . $entityManager['name'] . '_metadata_driver'),
            'setProxyDir' => '%doctrine.orm.proxy_dir%',
            'setProxyNamespace' => '%doctrine.orm.proxy_namespace%',
            'setAutoGenerateProxyClasses' => '%doctrine.orm.auto_generate_proxy_classes%',
            'setClassMetadataFactoryName' => $entityManager['class_metadata_factory_name'],
            'setDefaultRepositoryClassName' => $entityManager['default_repository_class'],
            'setNamingStrategy' => new Reference($entityManager['naming_strategy']),
            'setQuoteStrategy' => new Reference($entityManager['quote_strategy']),
            'setEntityListenerResolver' => new Reference(sprintf('doctrine.orm.%s_entity_listener_resolver', $entityManager['name'])),
        ];

        $listenerId        = sprintf('doctrine.orm.%s_listeners.attach_entity_listeners', $entityManager['name']);
        $listenerDef       = $container->setDefinition($listenerId, new Definition('%doctrine.orm.listeners.attach_entity_listeners.class%'));
        $listenerTagParams = ['event' => 'loadClassMetadata'];
        if (isset($entityManager['connection'])) {
            $listenerTagParams['connection'] = $entityManager['connection'];
        }
        $listenerDef->addTag('doctrine.event_listener', $listenerTagParams);

        if (isset($entityManager['second_level_cache'])) {
            $this->loadOrmSecondLevelCache($entityManager, $ormConfigDef, $container);
        }

        if ($entityManager['repository_factory']) {
            $methods['setRepositoryFactory'] = new Reference($entityManager['repository_factory']);
        }

        foreach ($methods as $method => $arg) {
            $ormConfigDef->addMethodCall($method, [$arg]);
        }

        foreach ($entityManager['hydrators'] as $name => $class) {
            $ormConfigDef->addMethodCall('addCustomHydrationMode', [$name, $class]);
        }

        if (! empty($entityManager['dql'])) {
            foreach ($entityManager['dql']['string_functions'] as $name => $function) {
                $ormConfigDef->addMethodCall('addCustomStringFunction', [$name, $function]);
            }
            foreach ($entityManager['dql']['numeric_functions'] as $name => $function) {
                $ormConfigDef->addMethodCall('addCustomNumericFunction', [$name, $function]);
            }
            foreach ($entityManager['dql']['datetime_functions'] as $name => $function) {
                $ormConfigDef->addMethodCall('addCustomDatetimeFunction', [$name, $function]);
            }
        }

        $enabledFilters    = [];
        $filtersParameters = [];
        foreach ($entityManager['filters'] as $name => $filter) {
            $ormConfigDef->addMethodCall('addFilter', [$name, $filter['class']]);
            if ($filter['enabled']) {
                $enabledFilters[] = $name;
            }
            if (! $filter['parameters']) {
                continue;
            }

            $filtersParameters[$name] = $filter['parameters'];
        }

        $managerConfiguratorName = sprintf('doctrine.orm.%s_manager_configurator', $entityManager['name']);
        $container
            ->setDefinition($managerConfiguratorName, new ChildDefinition('doctrine.orm.manager_configurator.abstract'))
            ->replaceArgument(0, $enabledFilters)
            ->replaceArgument(1, $filtersParameters);

        if (! isset($entityManager['connection'])) {
            $entityManager['connection'] = $this->defaultConnection;
        }

        $container
            ->setDefinition(sprintf('doctrine.orm.%s_entity_manager', $entityManager['name']), new ChildDefinition('doctrine.orm.entity_manager.abstract'))
            ->setPublic(true)
            ->setArguments([
                new Reference(sprintf('doctrine.dbal.%s_connection', $entityManager['connection'])),
                new Reference(sprintf('doctrine.orm.%s_configuration', $entityManager['name'])),
            ])
            ->setConfigurator([new Reference($managerConfiguratorName), 'configure']);

        $container->setAlias(
            sprintf('doctrine.orm.%s_entity_manager.event_manager', $entityManager['name']),
            new Alias(sprintf('doctrine.dbal.%s_connection.event_manager', $entityManager['connection']), false)
        );

        if (! isset($entityManager['entity_listeners'])) {
            return;
        }

        if (! isset($listenerDef)) {
            throw new InvalidArgumentException('Entity listeners configuration requires doctrine-orm 2.5.0 or newer');
        }

        $entities = $entityManager['entity_listeners']['entities'];

        foreach ($entities as $entityListenerClass => $entity) {
            foreach ($entity['listeners'] as $listenerClass => $listener) {
                foreach ($listener['events'] as $listenerEvent) {
                    $listenerEventName = $listenerEvent['type'];
                    $listenerMethod    = $listenerEvent['method'];

                    $listenerDef->addMethodCall('addEntityListener', [
                        $entityListenerClass,
                        $listenerClass,
                        $listenerEventName,
                        $listenerMethod,
                    ]);
                }
            }
        }
    }
912824
protected function loadOrmCacheDrivers(array $entityManager, ContainerBuilder $container)
    {
        $this->loadCacheDriver('metadata_cache', $entityManager['name'], $entityManager['metadata_cache_driver'], $container);
        $this->loadCacheDriver('result_cache', $entityManager['name'], $entityManager['result_cache_driver'], $container);
        $this->loadCacheDriver('query_cache', $entityManager['name'], $entityManager['query_cache_driver'], $container);
    }
118033
protected function loadFiles(
        EntityManagerInterface $entityManager,
        $object,
        UploadableClassMetadata $uploadableMeta
    ): void {
        $this->assertIsObject($object);
        $propertyManipulator = $this->getPropertyManipulator($entityManager);
        foreach ($uploadableMeta->getUploadableProperties() as $property => $config) {
            $key = $propertyManipulator->getPropertyValue($object, $property);

            if (!empty($key)) {
                $propertyManipulator->setAndSaveValue(
                    $object,
                    $config['targetField'],
                    new File($key, $this->computeFilesystem($config))
                );
            }
        }
    }
456959
public function load(ObjectManager $objectManager)
    {
        /**
         * @var ObjectDirector $zoneDirector
         */
        $zoneDirector = $this->getDirector('zone');

        $zone08021 = $zoneDirector
            ->create()
            ->setName('Postalcode 08021')
            ->setCode('zone-08021')
            ->addLocation($this->getReference('location-sant-celoni'))
            ->addLocation($this->getReference('location-08021'));

        $this->setReference('zone-08021', $zone08021);
        $zoneDirector->save($zone08021);

        $zoneViladecavalls = $zoneDirector
            ->create()
            ->setName('Viladecavalls i alrededores')
            ->setCode('zone-viladecavalls')
            ->addLocation($this->getReference('location-viladecavalls'));

        $this->setReference('zone-viladecavalls', $zoneViladecavalls);
        $zoneDirector->save($zoneViladecavalls);
    }