|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace PhpCfdi\SatCatalogosPopulate\Importers; |
|
6
|
|
|
|
|
7
|
|
|
use PhpCfdi\SatCatalogosPopulate\Database\Repository; |
|
8
|
|
|
use PhpCfdi\SatCatalogosPopulate\ImporterInterface; |
|
9
|
|
|
use Psr\Log\LoggerInterface; |
|
10
|
|
|
use RuntimeException; |
|
11
|
|
|
|
|
12
|
|
|
class Cce20Catalogs implements ImporterInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @param string $source Folder where all files exist |
|
16
|
|
|
*/ |
|
17
|
1 |
|
public function import(string $source, Repository $repository, LoggerInterface $logger): void |
|
18
|
|
|
{ |
|
19
|
1 |
|
$importers = $this->createImporters(); |
|
20
|
1 |
|
foreach ($importers as $file => $importer) { |
|
21
|
1 |
|
$sourceFile = $source . '/' . $file; |
|
22
|
1 |
|
if (! file_exists($sourceFile) || is_dir($sourceFile) || ! is_readable($sourceFile)) { |
|
23
|
|
|
throw new RuntimeException("No se encontró el archivo $sourceFile"); |
|
24
|
|
|
} |
|
25
|
1 |
|
$importer->import($sourceFile, $repository, $logger); |
|
26
|
|
|
} |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** @return array<string, ImporterInterface> */ |
|
30
|
2 |
|
public function createImporters(): array |
|
31
|
|
|
{ |
|
32
|
2 |
|
return [ |
|
33
|
2 |
|
'c_ClavePedimento20.xls' => new Cce20\CceClavePedimento(), |
|
34
|
2 |
|
'c_Colonia20.xls' => new Cce20\CceColonia(), |
|
35
|
2 |
|
'C_Estado20.xls' => new Cce20\CceEstado(), |
|
36
|
2 |
|
'c_FraccionArancelaria_cce20_20221212.xls' => new Cce20\CceFraccionArancelaria(), |
|
37
|
2 |
|
'c_INCOTERM20.xls' => new Cce20\CceIncoterm(), |
|
38
|
2 |
|
'c_Localidad20.xls' => new Cce20\CceLocalidad(), |
|
39
|
2 |
|
'c_MotivoTraslado20.xls' => new Cce20\CceMotivoTraslado(), |
|
40
|
2 |
|
'c_Municipio20.xls' => new Cce20\CceMunicipio(), |
|
41
|
2 |
|
'c_TipoOperacion20.xls' => new Cce20\CceTipoOperacion(), |
|
42
|
2 |
|
'c_UnidadAduana20.xls' => new Cce20\CceUnidadAduana(), |
|
43
|
2 |
|
]; |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|