‪TYPO3CMS  ‪main
Property.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Symfony\Component\PropertyInfo\Type;
24 
30 {
34  private ‪$name;
35 
36  private array ‪$definition;
37 
42 
43  public function ‪__construct(string ‪$name, array ‪$definition)
44  {
45  $this->name = ‪$name;
46  $this->characteristics = new ‪PropertyCharacteristics(‪$definition['propertyCharacteristicsBit']);
47  unset(‪$definition['propertyCharacteristicsBit']);
48 
49  $defaults = [
50  'c' => null, // cascade
51  't' => [], // types
52  'v' => [], // validators
53  ];
54 
55  foreach ($defaults as $key => $defaultValue) {
56  if (!isset(‪$definition[$key])) {
57  ‪$definition[$key] = $defaultValue;
58  }
59  }
60 
61  $this->definition = ‪$definition;
62  }
63 
64  public function ‪getName(): string
65  {
66  return ‪$this->name;
67  }
68 
76  public function ‪getTypes(): array
77  {
78  return $this->definition['t'];
79  }
80 
84  public function ‪getPrimaryType(): ?Type
85  {
86  return $this->‪getFilteredTypes(fn(Type $type) => $type->getClassName() !== LazyLoadingProxy::class)[0] ?? null;
87  }
88 
89  public function ‪getPrimaryCollectionValueType(): ?Type
90  {
91  if (!$this->‪getPrimaryType()->isCollection()) {
92  return null;
93  }
94 
95  return $this->‪getPrimaryType()->getCollectionValueTypes()[0] ?? null;
96  }
97 
101  public function ‪getFilteredTypes(callable $callback): array
102  {
103  return array_values(array_filter($this->definition['t'], $callback));
104  }
105 
106  public function ‪filterLazyLoadingProxyAndLazyObjectStorage(Type $type): bool
107  {
108  return !in_array((string)$type->getClassName(), [LazyLoadingProxy::class, LazyObjectStorage::class], true);
109  }
110 
111  public function ‪isObjectStorageType(): bool
112  {
113  $filteredTypes = $this->‪getFilteredTypes(
114  fn(Type $type) => in_array((string)$type->getClassName(), [ObjectStorage::class, LazyObjectStorage::class], true)
115  );
116 
117  return $filteredTypes !== [];
118  }
119 
120  public function ‪isPublic(): bool
121  {
122  return $this->characteristics->get(‪PropertyCharacteristics::VISIBILITY_PUBLIC);
123  }
124 
125  public function ‪isProtected(): bool
126  {
127  return $this->characteristics->get(‪PropertyCharacteristics::VISIBILITY_PROTECTED);
128  }
129 
130  public function ‪isPrivate(): bool
131  {
132  return $this->characteristics->get(‪PropertyCharacteristics::VISIBILITY_PRIVATE);
133  }
134 
135  public function ‪isLazy(): bool
136  {
137  return $this->characteristics->get(‪PropertyCharacteristics::ANNOTATED_LAZY);
138  }
139 
140  public function ‪isTransient(): bool
141  {
142  return $this->characteristics->get(‪PropertyCharacteristics::ANNOTATED_TRANSIENT);
143  }
144 
145  public function ‪isNullable(): bool
146  {
147  return $this->‪getPrimaryType() === null || $this->‪getPrimaryType()->isNullable();
148  }
149 
150  public function ‪getValidators(): array
151  {
152  return $this->definition['v'];
153  }
154 
155  public function ‪getCascadeValue(): ?string
156  {
157  return $this->definition['c'];
158  }
159 }
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property\getCascadeValue
‪getCascadeValue()
Definition: Property.php:153
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property\isPublic
‪isPublic()
Definition: Property.php:118
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property\getValidators
‪getValidators()
Definition: Property.php:148
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property\$definition
‪array $definition
Definition: Property.php:35
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property\isTransient
‪isTransient()
Definition: Property.php:138
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property\getTypes
‪list< Type > getTypes()
Definition: Property.php:74
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property\__construct
‪__construct(string $name, array $definition)
Definition: Property.php:41
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\PropertyCharacteristics\ANNOTATED_LAZY
‪const ANNOTATED_LAZY
Definition: PropertyCharacteristics.php:30
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property\$name
‪string $name
Definition: Property.php:33
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property\getPrimaryCollectionValueType
‪getPrimaryCollectionValueType()
Definition: Property.php:87
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\PropertyCharacteristics\VISIBILITY_PUBLIC
‪const VISIBILITY_PUBLIC
Definition: PropertyCharacteristics.php:29
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\PropertyCharacteristics\VISIBILITY_PRIVATE
‪const VISIBILITY_PRIVATE
Definition: PropertyCharacteristics.php:27
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property\isProtected
‪isProtected()
Definition: Property.php:123
‪TYPO3\CMS\Extbase\Persistence\ObjectStorage
Definition: ObjectStorage.php:34
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property\$characteristics
‪PropertyCharacteristics $characteristics
Definition: Property.php:39
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\PropertyCharacteristics
Definition: PropertyCharacteristics.php:26
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property
Definition: Property.php:30
‪TYPO3\CMS\Extbase\Reflection\ClassSchema
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property\getFilteredTypes
‪list< Type > getFilteredTypes(callable $callback)
Definition: Property.php:99
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property\getPrimaryType
‪getPrimaryType()
Definition: Property.php:82
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property\isObjectStorageType
‪isObjectStorageType()
Definition: Property.php:109
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy
Definition: LazyLoadingProxy.php:30
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property\isPrivate
‪isPrivate()
Definition: Property.php:128
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property\filterLazyLoadingProxyAndLazyObjectStorage
‪filterLazyLoadingProxyAndLazyObjectStorage(Type $type)
Definition: Property.php:104
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property\isLazy
‪isLazy()
Definition: Property.php:133
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\PropertyCharacteristics\ANNOTATED_TRANSIENT
‪const ANNOTATED_TRANSIENT
Definition: PropertyCharacteristics.php:31
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage
Definition: LazyObjectStorage.php:36
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property\getName
‪getName()
Definition: Property.php:62
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\Property\isNullable
‪isNullable()
Definition: Property.php:143
‪TYPO3\CMS\Extbase\Reflection\ClassSchema\PropertyCharacteristics\VISIBILITY_PROTECTED
‪const VISIBILITY_PROTECTED
Definition: PropertyCharacteristics.php:28