pdfdokumente/Application/Model/Registries/registryAbstract.php

90 lines
2.3 KiB
PHP
Raw Normal View History

2020-05-30 00:45:18 +02:00
<?php
/**
2020-07-04 23:25:24 +02:00
* See LICENSE file for license details.
2020-05-30 00:45:18 +02:00
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
2020-07-04 23:25:24 +02:00
* @author D3 Data Development - Max Buhe <support@shopmodule.com>
* @link http://www.oxidmodule.com
2020-05-30 00:45:18 +02:00
*/
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
}
}