Created
February 23, 2019 09:46
-
-
Save pulponair/b64a43dcba126a90fb1c72204215188f to your computer and use it in GitHub Desktop.
TYPO3 NewsRepository Proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugin.tx_news { | |
persistence { | |
classes { | |
GeorgRinger\News\Domain\Model\News { | |
subclasses { | |
Vendor\Events\Domain\Model\Event = Vendor\Events\Domain\Model\Event | |
Vendor\Events\Domain\Model\Course = Vendor\Events\Domain\Model\Course | |
} | |
} | |
Vendor\Events\Domain\Model\Event { | |
mapping { | |
recordType = Vendor\Events\Domain\Model\Event | |
tableName = tx_news_domain_model_news | |
} | |
} | |
Vendor\Events\Domain\Model\Course { | |
mapping { | |
recordType = Vendor\Events\Domain\Model\Course | |
tableName = tx_news_domain_model_news | |
} | |
} | |
} | |
} | |
objects { | |
GeorgRinger\News\Domain\Model\Dto\NewsDemand { | |
className = Vendor\Events\Domain\Model\Dto\NewsDemand | |
} | |
GeorgRinger\News\Domain\Repository\NewsRepository { | |
className = Vendor\Events\Domain\Repository\NewsRepositoryProxy | |
} | |
} | |
} | |
<?php | |
namespace Vendor\Events\Domain\Repository; | |
use TYPO3\CMS\Core\Utility\ClassNamingUtility; | |
use TYPO3\CMS\Extbase\Object\ObjectManager; | |
use TYPO3\CMS\Extbase\Utility\DebuggerUtility; | |
use GeorgRinger\News\Domain\Model\DemandInterface; | |
use TYPO3\CMS\Extbase\Persistence\QueryInterface; | |
class NewsRepositoryProxy extends \GeorgRinger\News\Domain\Repository\NewsRepository | |
{ | |
/** | |
* @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface | |
*/ | |
protected $objectManager; | |
/** | |
* @var Vendor\Events\Settings\SettingsService | |
*/ | |
protected $settingsService; | |
/** | |
* @var \GeorgRinger\News\Domain\Repository\NewsRepository | |
*/ | |
protected $actualRepository; | |
/** | |
* NewsRepositoryProxy constructor. | |
* @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager | |
*/ | |
public function __construct(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager) | |
{ | |
$this->objectManager = $objectManager; | |
$this->settingsService = $this->objectManager->get('Vendor\Events\Settings\SettingsService'); | |
$settings = $this->settingsService->getSettings(); | |
if (class_exists($settings['extKey']['newsType'])) { | |
$this->objectType = $settings['extKey']['newsType']; | |
$this->actualRepository = $objectManager->get(ClassNamingUtility::translateModelNameToRepositoryName($this->objectType)); | |
} else { | |
$this->objectType = '\GeorgRinger\News\Domain\Model\News'; | |
} | |
} | |
/** | |
* @param QueryInterface $query | |
* @param DemandInterface $demand | |
* @return array | |
* @throws \Exception | |
*/ | |
protected function createConstraintsFromDemand(QueryInterface $query, DemandInterface $demand) | |
{ | |
if ($this->actualRepository) { | |
$constraints = $this->actualRepository->createConstraintsFromDemand($query, $demand); | |
} else { | |
$constraints = parent::createConstraintsFromDemand($query, $demand); | |
} | |
return $constraints; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment