. */ namespace SP\Services\Import; use DI\Container; defined('APP_ROOT') || die(); /** * Clase XmlImport para usarla como envoltorio para llamar a la clase que corresponda * según el tipo de archivo XML detectado. * * @package SP */ class XmlImport implements ImportInterface { /** * @var FileImport */ protected $xmlFileImport; /** * @var ImportParams */ protected $importParams; /** * @var Container */ private $dic; /** * XmlImport constructor. * * @param Container $dic * @param XmlFileImport $xmlFileImport * @param ImportParams $importParams */ public function __construct(Container $dic, XmlFileImport $xmlFileImport, ImportParams $importParams) { $this->xmlFileImport = $xmlFileImport; $this->importParams = $importParams; $this->dic = $dic; } /** * Iniciar la importación desde XML. * * @throws ImportException * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface * @return ImportInterface */ public function doImport() { $format = $this->xmlFileImport->detectXMLFormat(); // $this->LogMessage->addDescription(sprintf(__('Formato detectado: %s'), mb_strtoupper($format))); return $this->selectImportType($format)->doImport(); } /** * @param $format * @return KeepassImport|KeepassXImport|SyspassImport * @throws ImportException * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ protected function selectImportType($format) { switch ($format) { case 'syspass': return new SyspassImport($this->dic, $this->xmlFileImport, $this->importParams); case 'keepass': return new KeepassImport($this->dic, $this->xmlFileImport, $this->importParams); case 'keepassx': return new KeepassXImport($this->dic, $this->xmlFileImport, $this->importParams); } throw new ImportException(__u('Formato no detectado')); } /** * @throws ImportException */ public function getCounter() { throw new ImportException(__u('Not implemented')); } }