https://github.com/fastbolt/entity-importer
Entity importing library for importing data from files (CSV and Excel currently) or API into doctrine.
https://github.com/fastbolt/entity-importer
data doctrine2 excel excel-import
Last synced: 4 months ago
JSON representation
Entity importing library for importing data from files (CSV and Excel currently) or API into doctrine.
- Host: GitHub
- URL: https://github.com/fastbolt/entity-importer
- Owner: fastbolt
- License: mit
- Created: 2022-03-18T10:19:39.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2026-01-27T09:24:17.000Z (5 months ago)
- Last Synced: 2026-01-27T21:07:12.666Z (5 months ago)
- Topics: data, doctrine2, excel, excel-import
- Language: PHP
- Homepage:
- Size: 181 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
[](https://packagist.org/packages/fastbolt/entity-importer)
[](https://codeclimate.com/github/fastbolt/entity-importer)
[](https://app.codecov.io/gh/fastbolt/entity-importer/)
[](https://shepherd.dev/github/fastbolt/entity-importer)
[](https://shepherd.dev/github/fastbolt/entity-importer)
[](https://github.com/fastbolt/entity-importer/actions)
# Entity importing library
This library aims to provide an easy way to import files into doctrine entities.
## Prerequisites
For now, the bundle is tested using PHP 7.4, 8.0 and 8.1.
Internally, we rely on [PortPHP](https://github.com/portphp) and [Doctrine](https://github.com/doctrine/persistence)
## Installation
The library can be installed via composer:
```
composer require fastbolt/entity-importer
```
## Configuration
If not configured automatically, the bundle needs to be enabled in your project's `bundles.php` file:
```php
['all' => true],
];
```
## Implementation
The only necessary code for new importers is the `Fastbolt\EntityImporter\EntityImporterDefinition` implementation. We recommend
extending the abstract `Fastbolt\EntityImporter\AbstractEntityImporterDefinition` class.
Currently, two import sources are available: Csv and Xlsx.
## Usage
After implementing the above interface, the console command `entity_importer:import` will automatically recognize the new implementation.
When executing the command without any arguments, it will display all available implementations:

### Implementation example:
```php
repository = $repository;
$this->materialGroupRepository = $materialGroupRepository;
$this->branchRepository = $branchRepository;
$this->importSourceDefinition = new Csv('MDMATERIALS.csv', CsvReader::TYPE);
}
/**
* @inheritDoc
*/
public function getName(): string
{
return 'materials';
}
/**
* @inheritDoc
*/
public function getDescription(): string
{
return 'Importer for Materials';
}
/**
* @inheritDoc
*/
public function getEntityClass(): string
{
return Material::class;
}
/**
* @inheritDoc
*/
public function getIdentifierColumns(): array
{
return ['materialNumber', 'branch'];
}
/**
* @inheritDoc
*/
public function getFields(): array
{
return [
'materialGroup',
'branch',
'materialNumber',
'shortMaterialNumber',
'purchasingTextDe',
'purchasingTextEn',
'priceGroup',
'priceUnit',
'packingUnit',
'weight',
'purchasingAbcMark',
'language',
'availableSince',
'customsTariffNumber',
'ean',
'isOnlineMaterial',
'rangeIndicator',
];
}
/**
* @inheritDoc
*/
public function getImportSourceDefinition(): Csv
{
return $this->importSourceDefinition;
}
/**
* @inheritDoc
*/
public function getRepository(): ObjectRepository
{
return $this->repository;
}
/**
* @inheritDoc
*/
public function getFieldConverters(): array
{
return [
'branch' => function ($value): Branch {
return $this->branchRepository->find($value);
},
'materialGroup' => function ($value): MaterialGroup {
return $this->materialGroupRepository->findOneBy(['name' => $value]);
},
'priceUnit' => static function ($value): int {
return (int)trim($value);
},
'availableSince' => static function ($value): ?DateTime {
if ('00000000' === $value) {
return null;
}
return DateTime::createFromFormat('Ymd', $value);
},
'packingUnit' => static function ($value): int {
return (int)trim($value);
},
'weight' => static function ($value): float {
return (float)trim(str_replace(',', '', $value));
},
];
}
/**
* @inheritDoc
*/
public function getSkippedFields(): array
{
return [
'language',
];
}
/**
* @inheritDoc
*/
public function getEntityModifier(): ?callable
{
return static function (Material $material) {
$material->setIsProtected(true);
};
}
}
```