<?php
/**
* project: Pimcore - Schutzverband Nuernberg Rostbratwuerste
* User: erikb
* Year: 2022
*/
namespace Devkitchen\DocumentIndexingBundle\DataExtractorService;
use Devkitchen\DocumentIndexingBundle\DataExtractorService\DocumentTypeHandler\DocumentTypeHandlerInterface;
use Pimcore\Model\Document;
use Pimcore\Model\Document\Page;
class DataExtractorService {
private Page $document;
private DocumentTypeHandlerFactory $documentTypeHandlerFactory;
private DocumentTypeHandlerInterface $documentTypeHandler;
public function __construct(DocumentTypeHandlerFactory $documentTypeHandlerFactory) {
$this->documentTypeHandlerFactory = $documentTypeHandlerFactory;
}
/**
* @param Document $document
*
* @return DocumentTypeHandlerInterface|null
* @throws \Exception
*/
public function create( Document $document ): DocumentTypeHandlerInterface | null {
try {
$this->documentTypeHandler = $this->documentTypeHandlerFactory->create( $document );
return $this->documentTypeHandler;
}
catch (\InvalidArgumentException $exception) {
throw new \Exception( $exception->getMessage() );
}
return null;
}
public function getId(): int {
return $this->documentTypeHandler->getId();
}
public function getLanguage() : string {
return $this->documentTypeHandler->getLanguage();
}
public function getElasticIndex() : string {
return $this->documentTypeHandler::getIndexName();
}
public function getElasticSearchData() : array {
return $this->documentTypeHandler->getData();
}
}