| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\PropertyAccess; |
| 13 |
|
| 14 |
use Psr\Cache\CacheItemPoolInterface; |
| 15 |
use Symfony\Component\PropertyInfo\PropertyReadInfoExtractorInterface; |
| 16 |
use Symfony\Component\PropertyInfo\PropertyWriteInfoExtractorInterface; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
m> |
| 22 |
|
| 23 |
class PropertyAccessorBuilder |
| 24 |
{ |
| 25 |
private int $magicMethods = PropertyAccessor::MAGIC_GET | PropertyAccessor::MAGIC_SET; |
| 26 |
private bool $throwExceptionOnInvalidIndex = false; |
| 27 |
private bool $throwExceptionOnInvalidPropertyPath = true; |
| 28 |
private ?CacheItemPoolInterface $cacheItemPool = null; |
| 29 |
private ?PropertyReadInfoExtractorInterface $readInfoExtractor = null; |
| 30 |
private ?PropertyWriteInfoExtractorInterface $writeInfoExtractor = null; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public function enableMagicMethods(): static |
| 38 |
{ |
| 39 |
$this->magicMethods = PropertyAccessor::MAGIC_GET | PropertyAccessor::MAGIC_SET | PropertyAccessor::MAGIC_CALL; |
| 40 |
|
| 41 |
return $this; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public function disableMagicMethods(): static |
| 50 |
{ |
| 51 |
$this->magicMethods = PropertyAccessor::DISALLOW_MAGIC_METHODS; |
| 52 |
|
| 53 |
return $this; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public function enableMagicCall(): static |
| 62 |
{ |
| 63 |
$this->magicMethods |= PropertyAccessor::MAGIC_CALL; |
| 64 |
|
| 65 |
return $this; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public function enableMagicGet(): self |
| 72 |
{ |
| 73 |
$this->magicMethods |= PropertyAccessor::MAGIC_GET; |
| 74 |
|
| 75 |
return $this; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
public function enableMagicSet(): static |
| 84 |
{ |
| 85 |
$this->magicMethods |= PropertyAccessor::MAGIC_SET; |
| 86 |
|
| 87 |
return $this; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public function disableMagicCall(): static |
| 96 |
{ |
| 97 |
$this->magicMethods &= ~PropertyAccessor::MAGIC_CALL; |
| 98 |
|
| 99 |
return $this; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
public function disableMagicGet(): static |
| 108 |
{ |
| 109 |
$this->magicMethods &= ~PropertyAccessor::MAGIC_GET; |
| 110 |
|
| 111 |
return $this; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
public function disableMagicSet(): static |
| 120 |
{ |
| 121 |
$this->magicMethods &= ~PropertyAccessor::MAGIC_SET; |
| 122 |
|
| 123 |
return $this; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
public function isMagicCallEnabled(): bool |
| 130 |
{ |
| 131 |
return $this->magicMethods & PropertyAccessor::MAGIC_CALL; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
public function isMagicGetEnabled(): bool |
| 138 |
{ |
| 139 |
return $this->magicMethods & PropertyAccessor::MAGIC_GET; |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
public function isMagicSetEnabled(): bool |
| 146 |
{ |
| 147 |
return $this->magicMethods & PropertyAccessor::MAGIC_SET; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
public function enableExceptionOnInvalidIndex(): static |
| 159 |
{ |
| 160 |
$this->throwExceptionOnInvalidIndex = true; |
| 161 |
|
| 162 |
return $this; |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
public function disableExceptionOnInvalidIndex(): static |
| 173 |
{ |
| 174 |
$this->throwExceptionOnInvalidIndex = false; |
| 175 |
|
| 176 |
return $this; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
public function isExceptionOnInvalidIndexEnabled(): bool |
| 183 |
{ |
| 184 |
return $this->throwExceptionOnInvalidIndex; |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
public function enableExceptionOnInvalidPropertyPath(): static |
| 196 |
{ |
| 197 |
$this->throwExceptionOnInvalidPropertyPath = true; |
| 198 |
|
| 199 |
return $this; |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
public function disableExceptionOnInvalidPropertyPath(): static |
| 210 |
{ |
| 211 |
$this->throwExceptionOnInvalidPropertyPath = false; |
| 212 |
|
| 213 |
return $this; |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
public function isExceptionOnInvalidPropertyPath(): bool |
| 220 |
{ |
| 221 |
return $this->throwExceptionOnInvalidPropertyPath; |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
public function setCacheItemPool(?CacheItemPoolInterface $cacheItemPool): static |
| 230 |
{ |
| 231 |
$this->cacheItemPool = $cacheItemPool; |
| 232 |
|
| 233 |
return $this; |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
public function getCacheItemPool(): ?CacheItemPoolInterface |
| 240 |
{ |
| 241 |
return $this->cacheItemPool; |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
public function setReadInfoExtractor(?PropertyReadInfoExtractorInterface $readInfoExtractor): static |
| 248 |
{ |
| 249 |
$this->readInfoExtractor = $readInfoExtractor; |
| 250 |
|
| 251 |
return $this; |
| 252 |
} |
| 253 |
|
| 254 |
public function getReadInfoExtractor(): ?PropertyReadInfoExtractorInterface |
| 255 |
{ |
| 256 |
return $this->readInfoExtractor; |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
public function setWriteInfoExtractor(?PropertyWriteInfoExtractorInterface $writeInfoExtractor): static |
| 263 |
{ |
| 264 |
$this->writeInfoExtractor = $writeInfoExtractor; |
| 265 |
|
| 266 |
return $this; |
| 267 |
} |
| 268 |
|
| 269 |
public function getWriteInfoExtractor(): ?PropertyWriteInfoExtractorInterface |
| 270 |
{ |
| 271 |
return $this->writeInfoExtractor; |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
public function getPropertyAccessor(): PropertyAccessorInterface |
| 278 |
{ |
| 279 |
$throw = PropertyAccessor::DO_NOT_THROW; |
| 280 |
|
| 281 |
if ($this->throwExceptionOnInvalidIndex) { |
| 282 |
$throw |= PropertyAccessor::THROW_ON_INVALID_INDEX; |
| 283 |
} |
| 284 |
|
| 285 |
if ($this->throwExceptionOnInvalidPropertyPath) { |
| 286 |
$throw |= PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH; |
| 287 |
} |
| 288 |
|
| 289 |
return new PropertyAccessor($this->magicMethods, $throw, $this->cacheItemPool, $this->readInfoExtractor, $this->writeInfoExtractor); |
| 290 |
} |
| 291 |
} |