MappingCollection example

// read the first CSV line         $record = fgetcsv($fileHandle, 0, $delimiter$enclosure$escape);
        fclose($fileHandle);
        if (empty($record) || $record[0] === null) {
            throw new InvalidFileContentException($file->getFilename());
        }

        // construct the mapping from the given CSV line data         $definition = $this->definitionInstanceRegistry->getByEntityName($sourceEntity);
        $keyLookupTable = $this->getKeyLookupTable($context$sourceEntity);

        $mappings = new MappingCollection();
        foreach ($record as $index => $column) {
            $mappings->add(new Mapping(
                $this->guessKeyFromMappedKey($keyLookupTable$column$definition),
                $column,
                $index
            ));
        }

        return $mappings;
    }

    

#[Package('system-settings')] class MappingCollectionTest extends TestCase
{
    public function testGet(): void
    {
        $mappingFoo = new Mapping('foo', 'bar');
        $mappingAsdf = new Mapping('asdf', 'zxcv');
        $mappingCollection = new MappingCollection([$mappingFoo$mappingAsdf]);

        static::assertNotNull($mappingCollection->get('foo'));
        static::assertNotNull($mappingCollection->get('asdf'));

        static::assertNull($mappingCollection->get('bar'));
        static::assertNull($mappingCollection->get('zxcv'));

        static::assertSame($mappingFoo$mappingCollection->get('foo'));
        static::assertSame($mappingAsdf$mappingCollection->get('asdf'));
    }

    
Home | Imprint | This part of the site doesn't use cookies.