fromIterable example

$log = $this->importExportService->prepareImport(Context::createDefaultContext()$profile['id']new \DateTimeImmutable()$uploadedFile);

        $actualConfig = Config::fromLog($log);

        static::assertFalse($actualConfig->get('includeVariants'));
        static::assertSame($profile['delimiter']$actualConfig->get('delimiter'));
        static::assertSame($profile['enclosure']$actualConfig->get('enclosure'));
        static::assertSame($profile['sourceEntity']$actualConfig->get('sourceEntity'));
        static::assertSame($profile['fileType']$actualConfig->get('fileType'));
        static::assertSame($profile['name']$actualConfig->get('profileName'));

        $expectedMapping = MappingCollection::fromIterable($profile['mapping']);
        static::assertEquals($expectedMapping$actualConfig->getMapping());

        $overrides = [
            'parameters' => [
                'includeVariants' => true,
                'fooBar' => 'baz',
                'enclosure' => '\'',
            ],
            'mapping' => [
                ['key' => 'zxcv', 'mappedKey' => 'qwer'],
            ],
        ];
$profile = $this->profileRepository->search(new Criteria([$profileId])$context)->first();
        if ($profile === null) {
            throw new EntityNotFoundException('import_export_profile', $profileId);
        }
        $mappings = $profile->getMapping();
        if (empty($mappings)) {
            throw new \RuntimeException('ImportExportProfile "' . $profileId . '" has no mappings');
        }

        $config = new Config($mappings[][]);
        $headers = [];
        $mappings = MappingCollection::fromIterable($mappings)->sortByPosition();

        /** @var Mapping $mapping */
        foreach ($mappings as $mapping) {
            $headers[$mapping->getMappedKey()] = '';
        }

        // create the file         $expireDate = new \DateTimeImmutable();
        $expireDate = $expireDate->modify('+1 hour');
        $fileEntity = $this->fileService->storeFile(
            $context,
            
/** * @param iterable<Mapping|string|MappingArray> $mapping * @param iterable<string, mixed> $parameters * @param iterable<UpdateBy|string|array<string, mixed>> $updateBy */
    public function __construct(
        iterable $mapping,
        iterable $parameters,
        iterable $updateBy
    ) {
        $this->mapping = MappingCollection::fromIterable($mapping);

        foreach ($parameters as $key => $value) {
            $this->parameters[$key] = $value;
        }

        $this->updateBy = UpdateByCollection::fromIterable($updateBy);
    }

    public function getMapping(): MappingCollection
    {
        return $this->mapping;
    }
$this->expectException(\InvalidArgumentException::class);
        /** @phpstan-ignore-next-line intentionally wrong parameter provided */
        new MappingCollection([new ArrayEntity()]);
    }

    public function testFromIterableMappingCollection(): void
    {
        $mappingFoo = new Mapping('foo', 'bar');
        $mappingAsdf = new Mapping('asdf', 'zxcv');
        $mappingCollection = new MappingCollection([$mappingFoo$mappingAsdf]);

        static::assertSame($mappingCollection, MappingCollection::fromIterable($mappingCollection));
    }

    public function testFromIterableArrayOfMapping(): void
    {
        $mappingFoo = new Mapping('foo', 'bar');
        $mappingAsdf = new Mapping('asdf', 'zxcv');
        $mappingCollection = MappingCollection::fromIterable([$mappingFoo$mappingAsdf]);

        static::assertCount(2, $mappingCollection);
    }

    
class KeyMappingPipe extends AbstractPipe
{
    private MappingCollection $mapping;

    /** * @param iterable<string|MappingArray|Mapping|MappingCollection> $mapping */
    public function __construct(
        iterable $mapping = [],
        private bool $flatten = true
    ) {
        $this->mapping = MappingCollection::fromIterable($mapping);
    }

    /** * @param iterable<string, mixed> $record * * @return iterable<string, mixed> */
    public function in(Config $config, iterable $record): iterable
    {
        $this->loadConfig($config);

        
$profileEntity = $this->findProfile($context$profileId);

        if (!\in_array($profileEntity->getType()[ImportExportProfileEntity::TYPE_EXPORT, ImportExportProfileEntity::TYPE_IMPORT_EXPORT], true)) {
            throw new ProfileWrongTypeException($profileEntity->getId()$profileEntity->getType());
        }

        if ($originalFileName === null) {
            $originalFileName = $this->fileService->generateFilename($profileEntity);
        }

        if ($profileEntity->getMapping() !== null) {
            $mappings = MappingCollection::fromIterable($profileEntity->getMapping());
            $profileEntity->setMapping($mappings->sortByPosition());
        }

        $fileEntity = $this->fileService->storeFile($context$expireDate, null, $originalFileName$activity$destinationPath);

        return $this->createLog($context$activity$fileEntity$profileEntity$config);
    }

    /** * @param Config $config */
    
private function getDefaultMapping(string $entity): MappingCollection
    {
        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('sourceEntity', $entity));
        $criteria->addFilter(new EqualsFilter('systemDefault', true));

        $profile = $this->getContainer()->get('import_export_profile.repository')->search($criteria, Context::createDefaultContext())->first();
        static::assertInstanceOf(ImportExportProfileEntity::class$profile);
        $mapping = $profile->getMapping();
        static::assertIsArray($mapping);

        return MappingCollection::fromIterable($mapping);
    }
}
Home | Imprint | This part of the site doesn't use cookies.