Last active
December 16, 2015 12:19
-
-
Save RafaelKa/5434110 to your computer and use it in GitHub Desktop.
Possible solution for ORM issue by property introduction
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
<?php | |
namespace .......... | |
use TYPO3\Flow\Annotations as Flow; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* | |
* @Flow\Scope("singleton") | |
* @Flow\Aspect | |
*/ | |
class SomeAspect { | |
/** | |
* @Flow\Inject | |
* @var \TYPO3\Flow\Reflection\ReflectionService | |
*/ | |
protected $reflectionService; | |
/** | |
* @param \TYPO3\Flow\Reflection\ReflectionService $reflectionService Description | |
*/ | |
public function injectReflectionService(\TYPO3\Flow\Reflection\ReflectionService $reflectionService) { | |
$this->reflectionService = $reflectionService; | |
} | |
/** | |
* @var string | |
* @Flow\Introduce("Train2Web\ControlPanel\Core\Services\SuperUser\Aspect\SuperUserProxyAspect->isSuperUserProxy") | |
*/ | |
protected $purpose; | |
/** | |
* @var string | |
* @Flow\Introduce("Train2Web\ControlPanel\Core\Services\SuperUser\Aspect\SuperUserProxyAspect->isSomethingElse") | |
*/ | |
protected $somethingElse; | |
/** | |
* Dirty patch for reflection service by introduced properties -> introduced properties are not in persistence layer | |
* | |
* @todo : Remove this advice if http://forge.typo3.org/issues/27045 is resolved. | |
* | |
* @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint The current join point | |
* @return void | |
* @Flow\Before("method(TYPO3\Flow\Persistence\Doctrine\EntityManagerFactory->create())") | |
*/ | |
public function assignPropertiesToORM(\TYPO3\Flow\Aop\JoinPointInterface $joinPoint) { | |
// those are added as property even if not tagged with entity/valueobject | |
$propertyTypeWhiteList = array( | |
'DateTime', | |
'SplObjectStorage', | |
'Doctrine\Common\Collections\Collection', | |
'Doctrine\Common\Collections\ArrayCollection' | |
); | |
$aspectClassName = get_class($this); | |
$aspectClassShema = $this->reflectionService->getClassSchema($aspectClassName); | |
$introducedPropertyNames = $this->reflectionService->getPropertyNamesByAnnotation($aspectClassName, 'TYPO3\Flow\Annotations\Introduce'); | |
foreach ($introducedPropertyNames as $propertyName) { | |
$isTransientProperty = $this->reflectionService->isPropertyAnnotatedWith($aspectClassName, $propertyName, 'TYPO3\Flow\Annotations\Transient'); | |
if ($isTransientProperty) {continue;} | |
$declaredType = trim(implode(' ', $this->reflectionService->getPropertyTagValues($aspectClassName, $propertyName, 'var')), ' \\'); | |
if (preg_match('/\s/', $declaredType) === 1 || empty($declaredType)) { | |
throw new \TYPO3\Flow\Reflection\Exception\InvalidPropertyTypeException(sprintf('Introduced in "%s" property "%s" has no @var annotation or type is not defined or is not annotated as "TYPO3\Flow\Annotations\Transient". Please define type for "%s" or annotate it as "TYPO3\Flow\Annotations\Transient".', $aspectClassName, $propertyName, $propertyName), 1366547612); | |
} | |
try { | |
$parsedType = \TYPO3\Flow\Utility\TypeHandling::parseType($declaredType); | |
} catch (\TYPO3\Flow\Utility\Exception\InvalidTypeException $exception) { | |
throw new \InvalidArgumentException(sprintf($exception->getMessage(), 'class "' . $aspectClassName . '" for property "' . $propertyName . '"'), 1366551857); | |
} | |
if (!in_array($parsedType['type'], $propertyTypeWhiteList) | |
&& (class_exists($parsedType['type']) || interface_exists($parsedType['type'])) | |
&& !($this->reflectionService->isClassAnnotatedWith($parsedType['type'], 'TYPO3\Flow\Annotations\Entity') || $this->isClassAnnotatedWith($parsedType['type'], 'Doctrine\ORM\Mapping\Entity') || $this->isClassAnnotatedWith($parsedType['type'], 'TYPO3\Flow\Annotations\ValueObject'))) { | |
continue; | |
} | |
// get all affected classes stuff is still not present but if it is possible here then we can add this Property to all affected classes | |
// foreach ($affectedClasses as $affectedClass){ | |
// $classSchema = $this->reflectionService->getClassSchema($affectedClass); | |
// $classSchema->addProperty($propertyName, $declaredType, $this->isPropertyAnnotatedWith($aspectClassName, $propertyName, 'TYPO3\Flow\Annotations\Lazy')); | |
// if ($this->reflectionService->isPropertyAnnotatedWith($className, $propertyName, 'TYPO3\Flow\Annotations\Identity')) { | |
// $classSchema->markAsIdentityProperty($propertyName); | |
// } | |
// } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment