If you want to make use of excel files, please also make sure to include phpoffice/phpexcel in your project:

$ composer require phpoffice/phpexcel

Configuration

Add your importer configurations in your app/config/config.yml.

Full example:

mathielen_import_engine:#configure storageproviders, that are used in all importersstorageprovider:default:type:directoryuri:/tmp/somedirupload:type:uploaduri:"%kernel.root_dir%/Resources/import"doctrine:type:doctrinequeries:#a list of DQL-Statements, Entity-Classnames, filenames or directories
- SELECT id FROM Acme\DemoBundle\Entity\Person P WHERE P.age > 10 #dql statement
- Acme\DemoBundle\Entity\ImportData #entity classname
- %kernel.root_dir%/dql/mysql.dql #file with dql statement in it
- %kernel.root_dir%/other-dql #directorydbal:type:dbalqueries:%kernel.root_dir%/sql/ #same like doctrineservices:type:serviceservices:#the services export_serviceA and export_serviceB must be configured in DICexport_serviceA:[exportMethod1, exportMethod2] #restrict to specific methods of serviceexport_serviceB:~ #every method of service can be used#configure your Importersimporters:your_importer_name:#some context information that is passed through the whole processcontext:key:value#automaticly recognize this importer by meeting of the conditions belowpreconditions:format:excel #format of data must be [csv, excel, xml]fieldcount:2#must have this number of fieldsfields:#these fields must exist (order is irrelevant)
- 'header2'
- 'header1'fieldset:#all fields must exist exactly this order
- 'header1'
- 'header2'filename:'somefile.xls'#filename must match one of these regular expression(s) (can be a list)#use an object-factory to convert raw row-arrays to target objectsobject_factory:type:jms_serializer #[jms_serializer, default]class:Acme\DemoBundle\ValueObject\MyImportedRow#add mappingmappings:#simple a-to-b mappingsource-field1:target-field1#convert the field (but dont map)source-field2:#converts excel's date-field to a Y-m-d string (you can use your own service-id here)converter:mathielen_importengine.converter.excel.genericdate#map and convertsource-field3:to:target-field3converter:upperCase #use a converter that was registered with the converter-provider#validate imported datavalidation:source:#add constraints to source fieldsheader1:emailheader2:notemptytarget:~ #activate validation against generated object from object-factory (via annotations, xml)#or supply list of constraints like in source#target of importtarget:type:service #[service, doctrine, file]service:'@import_service'#service name in DICmethod:processImportRow #method to invoke on service