Compare commits

...

4 Commits
1.0.2 ... main

Author SHA1 Message Date
Dorian Contal 5acb21d503 Changement nom README pour affichage dans packagist 2025-05-14 10:53:04 +02:00
Dorian 6853bf95ae Condition si var vide non obligatoire mais regex 2025-05-14 10:46:22 +02:00
Dorian Contal e67eb62e57 Modif readme inclusion yaml et exemple import 2025-04-23 11:52:47 +02:00
Dorian Contal 0d3686e34e externalisation des import et use du package 2025-04-23 11:31:50 +02:00
20 changed files with 79 additions and 44 deletions

View File

@ -43,6 +43,16 @@ $result = $importService->import(
$logger
);
```
---
## 🧑‍💻 Exemple d'Importation dans le Contrôleur
Dans votre contrôleur ou service, n'oubliez pas d'importer les classes nécessaires pour utiliser le service d'importation :
```php
use Sudalys\ImportService\CsvImportService;
use Sudalys\ImportService\ExcelFileTransformer;
```
---
@ -70,6 +80,21 @@ Géré via `ExcelFileTransformer` :
---
## ⚙️ Configuration du Service dans `services.yaml`
Pour que le service fonctionne correctement dans Symfony, ajoutez la configuration suivante dans votre fichier `services.yaml` :
```yaml
services:
Sudalys\ImportService\:
resource: '../vendor/sudalys/import-service/src/Service/Import/'
autowire: true
autoconfigure: true
public: false
```
---
## 🎓 Exigences
- PHP >= 8.1
@ -82,3 +107,9 @@ Géré via `ExcelFileTransformer` :
MIT

View File

@ -1,15 +1,15 @@
<?php
namespace Sudalys\ImportService;
use App\Service\Import\CsvValidator;
use App\Service\Import\Processor\BasicCsvFileProcessor;
use App\Service\Import\Processor\MainProcessor;
use App\Service\Import\ErrorHandler\LoggingErrorHandler;
use App\Service\Import\Specification\ExactHeaderSpecification;
use App\Service\Import\Specification\RegexColumnSpecification;
use App\Service\Import\Specification\NumericSpecification;
use App\Service\Import\Specification\RequiredColumnSpecification;
use App\Service\Import\Result\ImportResult;
use Sudalys\ImportService\CsvValidator;
use Sudalys\ImportService\Processor\BasicCsvFileProcessor;
use Sudalys\ImportService\Processor\MainProcessor;
use Sudalys\ImportService\ErrorHandler\LoggingErrorHandler;
use Sudalys\ImportService\Specification\ExactHeaderSpecification;
use Sudalys\ImportService\Specification\RegexColumnSpecification;
use Sudalys\ImportService\Specification\NumericSpecification;
use Sudalys\ImportService\Specification\RequiredColumnSpecification;
use Sudalys\ImportService\Result\ImportResult;
use Psr\Log\LoggerInterface;
class CsvImportService

View File

@ -2,11 +2,11 @@
namespace Sudalys\ImportService;
use App\Service\Import\Interfaces\FileProcessorInterface;
use App\Service\Import\Interfaces\ValidatorInterface;
use App\Service\Import\Interfaces\ErrorHandlerInterface;
use App\Service\Import\Interfaces\DataProcessorInterface;
use App\Service\Import\Result\ImportResult;
use Sudalys\ImportService\Interfaces\FileProcessorInterface;
use Sudalys\ImportService\Interfaces\ValidatorInterface;
use Sudalys\ImportService\Interfaces\ErrorHandlerInterface;
use Sudalys\ImportService\Interfaces\DataProcessorInterface;
use Sudalys\ImportService\Result\ImportResult;
use function Symfony\Component\DependencyInjection\Loader\Configurator\iterator;

View File

@ -1,9 +1,9 @@
<?php
namespace Sudalys\ImportService;
use App\Service\Import\Interfaces\HeaderSpecificationInterface;
use App\Service\Import\Result\ValidationResult;
use App\Service\Import\Interfaces\ValidatorInterface;
use Sudalys\ImportService\Interfaces\HeaderSpecificationInterface;
use Sudalys\ImportService\Result\ValidationResult;
use Sudalys\ImportService\Interfaces\ValidatorInterface;
class CsvValidator implements ValidatorInterface
{

View File

@ -1,6 +1,6 @@
<?php
namespace App\Service\Import\ErrorHandler;
use App\Service\Import\Interfaces\ErrorHandlerInterface;
namespace Sudalys\ImportService\ErrorHandler;
use Sudalys\ImportService\Interfaces\ErrorHandlerInterface;
use Psr\Log\LoggerInterface;
class LoggingErrorHandler implements ErrorHandlerInterface

View File

@ -1,5 +1,5 @@
<?php
namespace App\Service\Import\Interfaces;
namespace Sudalys\ImportService\Interfaces;
interface ColumnSpecificationInterface
{
public function isSatisfiedBy(string $value): bool;

View File

@ -1,5 +1,5 @@
<?php
namespace App\Service\Import\Interfaces;
namespace Sudalys\ImportService\Interfaces;
interface DataProcessorInterface
{

View File

@ -1,5 +1,5 @@
<?php
namespace App\Service\Import\Interfaces;
namespace Sudalys\ImportService\Interfaces;
interface ErrorHandlerInterface
{
public function handle(array $errors): void;

View File

@ -1,5 +1,5 @@
<?php
namespace App\Service\Import\Interfaces;
namespace Sudalys\ImportService\Interfaces;
interface FileProcessorInterface
{
public function processFile(string $Path): array;

View File

@ -1,5 +1,5 @@
<?php
namespace App\Service\Import\Interfaces;
namespace Sudalys\ImportService\Interfaces;
interface HeaderSpecificationInterface
{
public function isSatisfiedBy(array $header): bool;

View File

@ -1,6 +1,6 @@
<?php
namespace App\Service\Import\Interfaces;
use App\Service\Import\Result\ValidationResult;
namespace Sudalys\ImportService\Interfaces;
use Sudalys\ImportService\Result\ValidationResult;
interface ValidatorInterface
{

View File

@ -1,6 +1,6 @@
<?php
namespace App\Service\Import\Processor;
use App\Service\Import\Interfaces\FileProcessorInterface;
namespace Sudalys\ImportService\Processor;
use Sudalys\ImportService\Interfaces\FileProcessorInterface;
use League\Csv\Reader;

View File

@ -1,6 +1,6 @@
<?php
namespace App\Service\Import\Processor;
use App\Service\Import\Interfaces\DataProcessorInterface;
namespace Sudalys\ImportService\Processor;
use Sudalys\ImportService\Interfaces\DataProcessorInterface;
class DatabaseDataProcessor implements DataProcessorInterface
{

View File

@ -1,9 +1,9 @@
<?php
namespace App\Service\Import\Processor;
namespace Sudalys\ImportService\Processor;
use App\Service\Import\Interfaces\DataProcessorInterface;
//use App\Service\Import\Interfaces\AutreProcessorInterface; // Ajoute d'autres interfaces de traitement si nécessaire
use Sudalys\ImportService\Interfaces\DataProcessorInterface;
//use Sudalys\ImportService\Interfaces\AutreProcessorInterface; // Ajoute d'autres interfaces de traitement si nécessaire
class MainProcessor implements DataProcessorInterface
{

View File

@ -1,6 +1,6 @@
<?php
namespace App\Service\Import\Result;
namespace Sudalys\ImportService\Result;
class ImportResult
{

View File

@ -1,6 +1,6 @@
<?php
namespace App\Service\Import\Result;
namespace Sudalys\ImportService\Result;
class ValidationResult
{

View File

@ -1,7 +1,7 @@
<?php
namespace App\Service\Import\Specification;
use App\Service\Import\Interfaces\HeaderSpecificationInterface;
namespace Sudalys\ImportService\Specification;
use Sudalys\ImportService\Interfaces\HeaderSpecificationInterface;
class ExactHeaderSpecification implements HeaderSpecificationInterface
{

View File

@ -1,6 +1,6 @@
<?php
namespace App\Service\Import\Specification;
use App\Service\Import\Interfaces\ColumnSpecificationInterface;
namespace Sudalys\ImportService\Specification;
use Sudalys\ImportService\Interfaces\ColumnSpecificationInterface;
class NumericSpecification implements ColumnSpecificationInterface
{

View File

@ -1,6 +1,6 @@
<?php
namespace App\Service\Import\Specification;
use App\Service\Import\Interfaces\ColumnSpecificationInterface;
namespace Sudalys\ImportService\Specification;
use Sudalys\ImportService\Interfaces\ColumnSpecificationInterface;
class RegexColumnSpecification implements ColumnSpecificationInterface
{
@ -15,7 +15,11 @@ class RegexColumnSpecification implements ColumnSpecificationInterface
public function isSatisfiedBy(string $value): bool
{
if(!empty($value) || !trim($value) === '') {
return preg_match($this->pattern, $value) === 1;
}else{
return true;
}
}
public function getErrorMessage(): string

View File

@ -1,8 +1,8 @@
<?php
namespace App\Service\Import\Specification;
namespace Sudalys\ImportService\Specification;
use App\Service\Import\Interfaces\ColumnSpecificationInterface;
use Sudalys\ImportService\Interfaces\ColumnSpecificationInterface;
class RequiredColumnSpecification implements ColumnSpecificationInterface
{