diff --git a/Classes/Service/RegisterService.php b/Classes/Service/RegisterService.php new file mode 100644 index 0000000000000000000000000000000000000000..ea242236989e6fb8fd61724f92a1525f8ef1f9d1 --- /dev/null +++ b/Classes/Service/RegisterService.php @@ -0,0 +1,100 @@ +<?php + +namespace SGalinski\SgMail\Service; + +/*************************************************************** + * Copyright notice + * + * (c) sgalinski Internet Services (https://www.sgalinski.de) + * + * All rights reserved + * + * This script is part of the TYPO3 project. The TYPO3 project is + * free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * The GNU General Public License can be found at + * http://www.gnu.org/copyleft/gpl.html. + * + * This script is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * This copyright notice MUST APPEAR in all copies of the script! + ***************************************************************/ + +use TYPO3\CMS\Core\Cache\CacheManager; +use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; +use TYPO3\CMS\Core\Utility\GeneralUtility; + +/** + * Class RegisterService + * + * @package SGalinski\SgMail\Service + */ +class RegisterService implements \TYPO3\CMS\Core\SingletonInterface { + const CACHE_NAME = 'sg_mail_registerArrayCache'; + const CACHE_LIFETIME_IN_SECONDS = 86400; + + /** + * @var array + */ + public $registerArray = []; + + /** + * @var array + */ + private $registrationFiles = []; + + /** + * Enables extensions to add their registration files + * + * @param string $pathToRegisterFile + */ + public function register($pathToRegisterFile) { + if (file_exists($pathToRegisterFile)) { + $this->registerArray[] = [ + 'path' => $pathToRegisterFile + ]; + } + } + + /** + * Get all registered templates from the cache + * + * @return array + * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException + * @throws \BadFunctionCallException + * @throws \InvalidArgumentException + */ + public function getRegisterArray(): array { + /** @var CacheManager $cacheManager */ + $cacheManager = GeneralUtility::makeInstance(CacheManager::class); + /** @var FrontendInterface $cache */ + $cache = $cacheManager->getCache(self::CACHE_NAME); + $cacheId = md5('sg_mail'); + /** @var array entry */ + if (($entry = $cache->get($cacheId)) === FALSE) { + $entry = $this->registerExtensions(); + + if ($entry === NULL) { + $entry = []; + } + + $cache->set($cacheId, $entry, [], self::CACHE_LIFETIME_IN_SECONDS); + } + + return $entry; + } + + /** + * + */ + private function registerExtensions() { + + } +} +