8
0
pdfdokumente/Application/Model/Registries/registryAbstract.php

97 Zeilen
2.6 KiB
PHP

2020-05-30 00:45:18 +02:00
<?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 - Max Buhe <support@shopmodule.com>
* @link http://www.oxidmodule.com
*/
namespace D3\PdfDocuments\Application\Model\Registries;
2020-06-02 10:04:19 +02:00
use D3\PdfDocuments\Application\Model\Exceptions\wrongPdfGeneratorInterface;
2020-05-30 01:17:27 +02:00
use D3\PdfDocuments\Application\Model\Interfaces\pdfdocumentsGenericInterface;
2020-06-02 10:04:19 +02:00
use OxidEsales\Eshop\Core\Exception\StandardException;
2020-05-30 00:45:18 +02:00
2020-05-30 01:02:50 +02:00
abstract class registryAbstract implements registryGenericInterface
2020-05-30 00:45:18 +02:00
{
protected $_aRegistry = array();
2020-06-02 10:04:19 +02:00
/**
* @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');
}
}
2020-05-30 00:45:18 +02:00
/**
* @param $className * generator fully qualified class name
2020-05-30 01:17:27 +02:00
* @param pdfdocumentsGenericInterface $item
2020-05-30 00:45:18 +02:00
*/
2020-05-30 01:17:27 +02:00
protected function addItem($className, pdfdocumentsGenericInterface $item)
2020-05-30 00:45:18 +02:00
{
2020-06-02 10:04:19 +02:00
$requiredInterface = $this->getRequiredGeneratorInterfaceClassName();
if (false == $item instanceof $requiredInterface) {
throw oxNew(wrongPdfGeneratorInterface::class, $requiredInterface);
}
2020-05-30 00:45:18 +02:00
$this->_aRegistry[$className] = $item;
}
/**
* @param $className * generator fully qualified class name
*/
public function removeGenerator($className)
{
2020-06-02 10:04:19 +02:00
if ($this->hasGenerator($className)) {
unset( $this->_aRegistry[ $className ] );
}
2020-05-30 00:45:18 +02:00
}
/**
* @param $className * generator fully qualified class name
2020-07-03 20:04:21 +02:00
* @return bool
2020-05-30 00:45:18 +02:00
*/
public function hasGenerator($className)
{
2020-06-02 10:04:19 +02:00
return array_key_exists($className, $this->_aRegistry);
2020-05-30 00:45:18 +02:00
}
/**
* @return array
*/
public function getList()
{
return $this->_aRegistry;
}
public function clearList()
{
2020-06-02 10:04:19 +02:00
$this->_aRegistry = [];
2020-05-30 00:45:18 +02:00
}
}