1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpCfdi\SatCatalogos; |
6
|
|
|
|
7
|
|
|
use LogicException; |
8
|
|
|
use PhpCfdi\SatCatalogos\Common\BaseCatalog; |
9
|
|
|
use PhpCfdi\SatCatalogos\Exceptions\SatCatalogosLogicException; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class SatCatalogos |
13
|
|
|
* |
14
|
|
|
* @method CFDI\Aduanas aduanas(); |
15
|
|
|
* @method CFDI\ClavesUnidades clavesUnidades(); |
16
|
|
|
* @method CFDI\CodigosPostales codigosPostales(); |
17
|
|
|
* @method CFDI\FormasDePago formasDePago(); |
18
|
|
|
* @method CFDI\Impuestos impuestos(); |
19
|
|
|
* @method CFDI\MetodosDePago metodosDePago(); |
20
|
|
|
* @method CFDI\Monedas monedas(); |
21
|
|
|
* @method CFDI\NumerosPedimentoAduana numerosPedimentoAduana(); |
22
|
|
|
* @method CFDI\Paises paises(); |
23
|
|
|
* @method CFDI\PatentesAduanales patentesAduanales(); |
24
|
|
|
* @method CFDI\ProductosServicios productosServicios(); |
25
|
|
|
* @method CFDI\RegimenesFiscales regimenesFiscales(); |
26
|
|
|
* @method CFDI\ReglasTasaCuota reglasTasaCuota(); |
27
|
|
|
* @method CFDI\TiposComprobantes tiposComprobantes(); |
28
|
|
|
* @method CFDI\TiposFactores tiposFactores(); |
29
|
|
|
* @method CFDI\TiposRelaciones tiposRelaciones(); |
30
|
|
|
* @method CFDI\UsosCfdi usosCfdi(); |
31
|
|
|
* |
32
|
|
|
* @method Nomina\TiposContratos tiposContratos(); |
33
|
|
|
* @method Nomina\TiposNominas tiposNominas(); |
34
|
|
|
* @method Nomina\TiposJornadas tiposJornadas(); |
35
|
|
|
* @method Nomina\OrigenesRecursos origenesRecursos(); |
36
|
|
|
* @method Nomina\Bancos bancos(); |
37
|
|
|
* @method Nomina\PeriodicidadesPagos periodicidadesPagos(); |
38
|
|
|
* @method Nomina\RiesgosPuestos riesgosPuestos(); |
39
|
|
|
* @method Nomina\TiposDeducciones tiposDeducciones(); |
40
|
|
|
* @method Nomina\TiposHoras tiposHoras(); |
41
|
|
|
* @method Nomina\TiposIncapacidades tiposIncapacidades(); |
42
|
|
|
* @method Nomina\TiposOtrosPagos tiposOtrosPagos(); |
43
|
|
|
* @method Nomina\TiposPercepciones tiposPercepciones(); |
44
|
|
|
* @method Nomina\TiposRegimenes tiposRegimenes(); |
45
|
|
|
*/ |
46
|
|
|
class SatCatalogos |
47
|
|
|
{ |
48
|
|
|
/** @var array<string, class-string|BaseCatalog> */ |
|
|
|
|
49
|
|
|
private $map = [ |
50
|
|
|
// CFDI |
51
|
|
|
'aduanas' => CFDI\Aduanas::class, |
52
|
|
|
'clavesUnidades' => CFDI\ClavesUnidades::class, |
53
|
|
|
'codigosPostales' => CFDI\CodigosPostales::class, |
54
|
|
|
'formasDePago' => CFDI\FormasDePago::class, |
55
|
|
|
'impuestos' => CFDI\Impuestos::class, |
56
|
|
|
'metodosDePago' => CFDI\MetodosDePago::class, |
57
|
|
|
'monedas' => CFDI\Monedas::class, |
58
|
|
|
'numerosPedimentoAduana' => CFDI\NumerosPedimentoAduana::class, |
59
|
|
|
'paises' => CFDI\Paises::class, |
60
|
|
|
'patentesAduanales' => CFDI\PatentesAduanales::class, |
61
|
|
|
'productosServicios' => CFDI\ProductosServicios::class, |
62
|
|
|
'regimenesFiscales' => CFDI\RegimenesFiscales::class, |
63
|
|
|
'reglasTasaCuota' => CFDI\ReglasTasaCuota::class, |
64
|
|
|
'tiposComprobantes' => CFDI\TiposComprobantes::class, |
65
|
|
|
'tiposFactores' => CFDI\TiposFactores::class, |
66
|
|
|
'tiposRelaciones' => CFDI\TiposRelaciones::class, |
67
|
|
|
'usosCfdi' => CFDI\UsosCfdi::class, |
68
|
|
|
// Nominas |
69
|
|
|
'tiposContratos' => Nomina\TiposContratos::class, |
70
|
|
|
'tiposNominas' => Nomina\TiposNominas::class, |
71
|
|
|
'tiposJornadas' => Nomina\TiposJornadas::class, |
72
|
|
|
'origenesRecursos' => Nomina\OrigenesRecursos::class, |
73
|
|
|
'bancos' => Nomina\Bancos::class, |
74
|
|
|
'periodicidadesPagos' => Nomina\PeriodicidadesPagos::class, |
75
|
|
|
'riesgosPuestos' => Nomina\RiesgosPuestos::class, |
76
|
|
|
'tiposDeducciones' => Nomina\TiposDeducciones::class, |
77
|
|
|
'tiposHoras' => Nomina\TiposHoras::class, |
78
|
|
|
'tiposIncapacidades' => Nomina\TiposIncapacidades::class, |
79
|
|
|
'tiposOtrosPagos' => Nomina\TiposOtrosPagos::class, |
80
|
|
|
'tiposPercepciones' => Nomina\TiposPercepciones::class, |
81
|
|
|
'tiposRegimenes' => Nomina\TiposRegimenes::class, |
82
|
|
|
]; |
83
|
|
|
|
84
|
|
|
/** @var Repository */ |
85
|
|
|
private $repository; |
86
|
|
|
|
87
|
36 |
|
public function __construct(Repository $repository) |
88
|
|
|
{ |
89
|
36 |
|
$this->repository = $repository; |
90
|
36 |
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Magic method to return a catalog using the method name |
94
|
|
|
* |
95
|
|
|
* @param string $methodName |
96
|
|
|
* @param mixed[] $arguments |
97
|
|
|
* @return mixed |
98
|
|
|
* @throws SatCatalogosLogicException if cannot find a matching catalog with the method name |
99
|
|
|
*/ |
100
|
35 |
|
public function __call(string $methodName, array $arguments) |
101
|
|
|
{ |
102
|
35 |
|
if (! isset($this->map[$methodName])) { |
103
|
3 |
|
throw new SatCatalogosLogicException("No se pudo encontrar el catálogo '$methodName'"); |
104
|
|
|
} |
105
|
|
|
|
106
|
32 |
|
if (is_object($this->map[$methodName])) { |
107
|
1 |
|
return $this->map[$methodName]; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
try { |
111
|
|
|
/** @var mixed $created */ |
112
|
32 |
|
$created = $this->create($this->map[$methodName]); |
113
|
|
|
} catch (LogicException $exception) { |
114
|
|
|
throw new SatCatalogosLogicException("No se pudo encontrar el catálogo '$methodName'", 0, $exception); |
115
|
|
|
} |
116
|
|
|
|
117
|
32 |
|
$this->map[$methodName] = $created; |
118
|
32 |
|
return $created; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param class-string $className |
|
|
|
|
123
|
|
|
* @return BaseCatalog |
124
|
|
|
*/ |
125
|
32 |
|
private function create(string $className): BaseCatalog |
126
|
|
|
{ |
127
|
32 |
|
if (! class_exists($className)) { |
128
|
|
|
throw new LogicException("$className does not exists"); |
129
|
|
|
} |
130
|
32 |
|
if (! in_array(BaseCatalog::class, class_implements($className) ?: [], true)) { |
131
|
|
|
throw new LogicException(sprintf('%s does not implements %s', $className, BaseCatalog::class)); |
132
|
|
|
} |
133
|
|
|
/** @var BaseCatalog $object */ |
134
|
32 |
|
$object = new $className(); |
135
|
32 |
|
$object->withRepository($this->repository); |
136
|
|
|
|
137
|
32 |
|
return $object; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|