Created
October 19, 2012 11:13
-
-
Save bwaidelich/3917639 to your computer and use it in GitHub Desktop.
Doctrine behaviors in TYPO3 Flow - Example: Softdeletable
This file contains 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
{ | |
"name": "your/package", | |
/* ... */ | |
"require": { | |
"gedmo/doctrine-extensions": "2.3.x-dev" | |
}, | |
} |
This file contains 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
<?php | |
namespace YourPackage\Aop; | |
use TYPO3\Flow\Annotations as Flow; | |
/** | |
* @Flow\Aspect | |
*/ | |
class EntityManagerFactoryAspect { | |
/** | |
* @var \TYPO3\Flow\Reflection\ReflectionService | |
* @Flow\Inject | |
*/ | |
protected $reflectionService; | |
/** | |
* @Flow\Around("method(TYPO3\Flow\Persistence\Doctrine\EntityManagerFactory->create())") | |
* @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint The current join point | |
* @return \Doctrine\ORM\EntityManager | |
*/ | |
public function registerSoftDeletableFilter(\TYPO3\Flow\Aop\JoinPointInterface $joinPoint) { | |
/** @var $entityManager \Doctrine\ORM\EntityManager */ | |
$entityManager = $joinPoint->getAdviceChain()->proceed($joinPoint); | |
/** @var $eventManager \Doctrine\Common\EventManager */ | |
$eventManager = $entityManager->getEventManager(); | |
$classNamesAnnotatedAsDeletable = $this->reflectionService->getClassNamesByAnnotation('Gedmo\Mapping\Annotation\SoftDeleteable'); | |
if (!is_array($classNamesAnnotatedAsDeletable)) { | |
return $entityManager; | |
} | |
foreach ($classNamesAnnotatedAsDeletable as $index => $className) { | |
if (!$this->reflectionService->isClassAnnotatedWith($className, 'TYPO3\Flow\Annotations\Entity')) { | |
unset($classNamesAnnotatedAsDeletable[$index]); | |
} | |
} | |
if ($classNamesAnnotatedAsDeletable !== array()) { | |
$doctrineConfiguration = $entityManager->getConfiguration(); | |
$doctrineConfiguration->addFilter('soft-deletable', 'Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter'); | |
$entityManager->getFilters()->enable('soft-deletable'); | |
$softDeletableListener = new \Gedmo\SoftDeleteable\SoftDeleteableListener(); | |
$eventManager->addEventSubscriber($softDeletableListener); | |
} | |
return $entityManager; | |
} | |
} | |
?> |
This file contains 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
<?php | |
namespace YourPackage\Domain\Model; | |
use TYPO3\Flow\Annotations as Flow; | |
use Doctrine\ORM\Mapping as ORM; | |
use Gedmo\Mapping\Annotation as Gedmo; | |
/** | |
* @Flow\Entity | |
* @Gedmo\SoftDeleteable(fieldName="deletedAt") | |
*/ | |
class SomeModel { | |
/** | |
* @var \DateTime | |
* @ORM\Column(nullable=true) | |
*/ | |
protected $deletedAt; | |
/** | |
* @param \DateTime $deletedAt | |
* @return void | |
*/ | |
public function setDeletedAt(\DateTime $deletedAt) { | |
$this->deletedAt= $deletedAt; | |
} | |
/** | |
* @return \DateTime | |
*/ | |
public function getDeletedAt() { | |
return $this->deletedAt; | |
} | |
/** ... */ | |
} |
..Late response, sorry for that: It didn't make it into 2.0, but in the current version doctrine filters are configurable via settings: http://docs.typo3.org/flow/TYPO3FlowDocumentation/latest/TheDefinitiveGuide/PartIII/Persistence.html#on-the-doctrine-filter-system
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Was this indeed implemented in Flow 2.0? I'm not sure where to start looking in the code if it exists.