2 namespace TYPO3\CMS\Extbase\Reflection;
108 protected $ignoredTags = array(
'package',
'subpackage',
'license',
'copyright',
'author',
'version',
'const');
181 if ($this->initialized) {
182 throw new Exception(
'The Reflection Service can only be initialized once.', 1232044696);
184 $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
185 $this->cacheIdentifier =
'ReflectionData_' . $frameworkConfiguration[
'extensionName'];
187 $this->initialized =
true;
207 if ($this->dataCacheNeedsUpdate) {
210 $this->initialized =
false;
221 if (!isset($this->reflectedClassNames[$className])) {
224 if (!isset($this->classTagsValues[$className])) {
227 return isset($this->classTagsValues[$className]) ? $this->classTagsValues[$className] : array();
239 if (!isset($this->reflectedClassNames[$className])) {
242 if (!isset($this->classTagsValues[$className])) {
245 return isset($this->classTagsValues[$className][$tag]) ? $this->classTagsValues[$className][$tag] : array();
256 if (!isset($this->reflectedClassNames[$className])) {
259 return isset($this->classPropertyNames[$className]) ? $this->classPropertyNames[$className] : array();
270 $className = is_object($classNameOrObject) ? get_class($classNameOrObject) : $classNameOrObject;
271 if (isset($this->classSchemata[$className])) {
272 return $this->classSchemata[$className];
288 if (!array_key_exists($className, $this->methodReflections) || !array_key_exists($methodName, $this->methodReflections[$className])) {
289 $this->methodReflections[$className][$methodName] =
new MethodReflection($className, $methodName);
290 $this->dataCacheNeedsUpdate =
true;
292 }
catch (\ReflectionException $e) {
294 $this->methodReflections[$className][$methodName] = null;
296 return isset($this->methodReflections[$className][$methodName]);
308 if (!isset($this->methodTagsValues[$className][$methodName])) {
309 $this->methodTagsValues[$className][$methodName] = array();
311 foreach ($method->getTagsValues() as $tag => $values) {
312 if (array_search($tag, $this->ignoredTags) ===
false) {
313 $this->methodTagsValues[$className][$methodName][$tag] = $values;
317 return $this->methodTagsValues[$className][$methodName];
330 if (!isset($this->methodParameters[$className][$methodName])) {
332 $this->methodParameters[$className][$methodName] = array();
333 foreach ($method->getParameters() as $parameterPosition => $parameter) {
337 return $this->methodParameters[$className][$methodName];
349 if (!isset($this->reflectedClassNames[$className])) {
352 if (!isset($this->propertyTagsValues[$className])) {
355 return isset($this->propertyTagsValues[$className][$propertyName]) ? $this->propertyTagsValues[$className][$propertyName] : array();
368 if (!isset($this->reflectedClassNames[$className])) {
371 if (!isset($this->propertyTagsValues[$className][$propertyName])) {
374 return isset($this->propertyTagsValues[$className][$propertyName][$tag]) ? $this->propertyTagsValues[$className][$propertyName][$tag] : array();
386 return isset($this->reflectedClassNames[$className]);
398 if ($this->initialized ===
false) {
401 if (!isset($this->reflectedClassNames[$className])) {
404 if (!isset($this->classTagsValues[$className])) {
407 return isset($this->classTagsValues[$className][$tag]);
420 if (!isset($this->reflectedClassNames[$className])) {
423 if (!isset($this->propertyTagsValues[$className])) {
426 if (!isset($this->propertyTagsValues[$className][$propertyName])) {
429 return isset($this->propertyTagsValues[$className][$propertyName][$tag]);
441 $this->reflectedClassNames[$className] = time();
442 foreach ($class->getTagsValues() as $tag => $values) {
443 if (array_search($tag, $this->ignoredTags) ===
false) {
444 $this->taggedClasses[$tag][] = $className;
445 $this->classTagsValues[$className][$tag] = $values;
448 foreach ($class->getProperties() as $property) {
449 $propertyName = $property->getName();
450 $this->classPropertyNames[$className][] = $propertyName;
451 foreach ($property->getTagsValues() as $tag => $values) {
452 if (array_search($tag, $this->ignoredTags) ===
false) {
453 $this->propertyTagsValues[$className][$propertyName][$tag] = $values;
457 foreach ($class->getMethods() as $method) {
458 $methodName = $method->getName();
459 foreach ($method->getTagsValues() as $tag => $values) {
460 if (array_search($tag, $this->ignoredTags) ===
false) {
461 $this->methodTagsValues[$className][$methodName][$tag] = $values;
464 foreach ($method->getParameters() as $parameterPosition => $parameter) {
468 ksort($this->reflectedClassNames);
469 $this->dataCacheNeedsUpdate =
true;
481 if (!class_exists($className)) {
482 throw new Exception\UnknownClassException(
'The classname "' . $className .
'" was not found and thus can not be reflected.', 1278450972);
484 $classSchema = $this->objectManager->get(\TYPO3\CMS\Extbase\Reflection\ClassSchema::class, $className);
485 if (is_subclass_of($className, \TYPO3\CMS\Extbase\DomainObject\AbstractEntity::class)) {
488 if (class_exists($possibleRepositoryClassName)) {
489 $classSchema->setAggregateRoot(
true);
491 }
elseif (is_subclass_of($className, \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject::class)) {
497 $classSchema->addProperty($propertyName, implode(
' ', $this->
getPropertyTagValues($className, $propertyName,
'var')), $this->
isPropertyTaggedWith($className, $propertyName,
'lazy'), $cascadeTagValues[0]);
500 $classSchema->setUuidPropertyName($propertyName);
503 $classSchema->markAsIdentityProperty($propertyName);
506 $this->classSchemata[$className] = $classSchema;
507 $this->dataCacheNeedsUpdate =
true;
521 $parameterInformation = array(
522 'position' => $parameterPosition,
523 'byReference' => $parameter->isPassedByReference(),
524 'array' => $parameter->isArray(),
525 'optional' => $parameter->isOptional(),
526 'allowsNull' => $parameter->allowsNull()
528 $parameterClass = $parameter->
getClass();
529 $parameterInformation[
'class'] = $parameterClass !== null ? $parameterClass->getName() : null;
530 if ($parameter->isDefaultValueAvailable()) {
531 $parameterInformation[
'defaultValue'] = $parameter->getDefaultValue();
533 if ($parameterClass !== null) {
534 $parameterInformation[
'type'] = $parameterClass->getName();
535 }
elseif ($method !== null) {
536 $methodTagsAndValues = $this->
getMethodTagsValues($method->getDeclaringClass()->getName(), $method->getName());
537 if (isset($methodTagsAndValues[
'param']) && isset($methodTagsAndValues[
'param'][$parameterPosition])) {
538 $explodedParameters = explode(
' ', $methodTagsAndValues[
'param'][$parameterPosition]);
539 if (count($explodedParameters) >= 2) {
544 $parameterInformation[
'type'] = $typeInfo[
'type'];
546 $parameterInformation[
'type'] = $explodedParameters[0];
551 if (isset($parameterInformation[
'type']) && $parameterInformation[
'type'][0] ===
'\\') {
552 $parameterInformation[
'type'] = substr($parameterInformation[
'type'], 1);
554 return $parameterInformation;
566 if (!isset($this->methodReflections[$className][$methodName])) {
567 $this->methodReflections[$className][$methodName] =
new MethodReflection($className, $methodName);
568 $this->dataCacheNeedsUpdate =
true;
570 return $this->methodReflections[$className][$methodName];
580 $data = $this->dataCache->get($this->cacheIdentifier);
581 if ($data !==
false) {
582 foreach ($data as $propertyName => $propertyValue) {
583 $this->{$propertyName} = $propertyValue;
596 if (!is_object($this->dataCache)) {
597 throw new Exception(
'A cache must be injected before initializing the Reflection Service.', 1232044697);
600 $propertyNames = array(
601 'reflectedClassNames',
602 'classPropertyNames',
606 'propertyTagsValues',
610 foreach ($propertyNames as $propertyName) {
611 $data[$propertyName] = $this->{$propertyName};
613 $this->dataCache->set($this->cacheIdentifier, $data);