simplify registry configuration

This commit is contained in:
Daniel Seifert 2020-06-02 10:04:19 +02:00
bovenliggende fa96df326d
commit efdc63225e
Getekend door: DanielS
GPG sleutel-ID: 8A7C4C6ED1915C6F
5 gewijzigde bestanden met toevoegingen van 72 en 15 verwijderingen

Bestand weergeven

@ -0,0 +1,26 @@
<?php
/**
* This Software is the property of Data Development and is protected
* by copyright law - it is NOT Freeware.
* Any unauthorized use of this software without a valid license
* is a violation of the license agreement and will be prosecuted by
* civil and criminal law.
* http://www.shopmodule.com
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com
*/
namespace D3\PdfDocuments\Application\Model\Exceptions;
class wrongPdfGeneratorInterface extends pdfGeneratorExceptionAbstract
{
public function __construct( $requiredInterface, $sMessage = "generator class doesn't fulfilled the interface", $iCode = 0, \Exception $previous = null ) {
$sMessage .= $requiredInterface;
parent::__construct( $sMessage, $iCode, $previous );
}
}

Bestand weergeven

@ -17,18 +17,49 @@
namespace D3\PdfDocuments\Application\Model\Registries;
use D3\PdfDocuments\Application\Model\Exceptions\wrongPdfGeneratorInterface;
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsGenericInterface;
use OxidEsales\Eshop\Core\Exception\StandardException;
abstract class registryAbstract implements registryGenericInterface
{
protected $_aRegistry = array();
/**
* @return string
*/
public function getRequiredGeneratorInterfaceClassName()
{
return pdfdocumentsGenericInterface::class;
}
/**
* @param $className
*/
public function addGenerator($className)
{
if (false == $this->hasGenerator($className)) {
/** @var pdfdocumentsGenericInterface $generator */
$generator = oxNew( $className );
$this->addItem( $className, $generator );
} else {
throw oxNew(StandardException::class, 'generator still exists in registry');
}
}
/**
* @param $className * generator fully qualified class name
* @param pdfdocumentsGenericInterface $item
*/
protected function addItem($className, pdfdocumentsGenericInterface $item)
{
$requiredInterface = $this->getRequiredGeneratorInterfaceClassName();
if (false == $item instanceof $requiredInterface) {
throw oxNew(wrongPdfGeneratorInterface::class, $requiredInterface);
}
$this->_aRegistry[$className] = $item;
}
@ -37,7 +68,9 @@ abstract class registryAbstract implements registryGenericInterface
*/
public function removeGenerator($className)
{
// TODO: Implement removeGenerator() method.
if ($this->hasGenerator($className)) {
unset( $this->_aRegistry[ $className ] );
}
}
/**
@ -45,7 +78,7 @@ abstract class registryAbstract implements registryGenericInterface
*/
public function hasGenerator($className)
{
// TODO: Implement hasGenerator() method.
return array_key_exists($className, $this->_aRegistry);
}
/**
@ -58,6 +91,6 @@ abstract class registryAbstract implements registryGenericInterface
public function clearList()
{
// TODO: Implement clearList() method.
$this->_aRegistry = [];
}
}

Bestand weergeven

@ -19,6 +19,8 @@ namespace D3\PdfDocuments\Application\Model\Registries;
interface registryGenericInterface
{
public function getRequiredGeneratorInterfaceClassName();
/**
* @param $className * generator fully qualified class name
*/

Bestand weergeven

@ -27,19 +27,18 @@ class registryOrderoverview extends registryAbstract implements registryOrderove
{
public function __construct()
{
$this->addGenerator(invoicePdf::class, oxNew(invoicePdf::class));
$this->addGenerator(deliverynotePdf::class, oxNew(deliverynotePdf::class));
$this->addGenerator(invoicewithoutlogoPdf::class, oxNew(invoicewithoutlogoPdf::class));
$this->addGenerator(deliverynotewithoutlogoPdf::class, oxNew(deliverynotewithoutlogoPdf::class));
$this->addGenerator(invoicePdf::class);
$this->addGenerator(deliverynotePdf::class);
$this->addGenerator(invoicewithoutlogoPdf::class);
$this->addGenerator(deliverynotewithoutlogoPdf::class);
}
/**
* @param $className
* @param pdfdocumentsOrderInterface $pdfGenerator
* @return string
*/
public function addGenerator($className, pdfdocumentsOrderInterface $pdfGenerator)
public function getRequiredGeneratorInterfaceClassName()
{
$this->addItem($className, $pdfGenerator);
return pdfdocumentsOrderInterface::class;
}
/**

Bestand weergeven

@ -17,13 +17,10 @@
namespace D3\PdfDocuments\Application\Model\Registries;
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsOrderInterface;
interface registryOrderoverviewInterface extends registryGenericInterface
{
/**
* @param $className * generator fully qualified class name
* @param pdfdocumentsOrderInterface $pdfGenerator
*/
public function addGenerator($className, pdfdocumentsOrderInterface $pdfGenerator);
public function addGenerator($className);
}