comparison vendor/symfony/validator/Mapping/ClassMetadata.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents c2387f117808
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
51 * 51 *
52 * @internal This property is public in order to reduce the size of the 52 * @internal This property is public in order to reduce the size of the
53 * class' serialized representation. Do not access it. Use 53 * class' serialized representation. Do not access it. Use
54 * {@link getPropertyMetadata()} instead. 54 * {@link getPropertyMetadata()} instead.
55 */ 55 */
56 public $members = array(); 56 public $members = [];
57 57
58 /** 58 /**
59 * @var PropertyMetadata[] 59 * @var PropertyMetadata[]
60 * 60 *
61 * @internal This property is public in order to reduce the size of the 61 * @internal This property is public in order to reduce the size of the
62 * class' serialized representation. Do not access it. Use 62 * class' serialized representation. Do not access it. Use
63 * {@link getPropertyMetadata()} instead. 63 * {@link getPropertyMetadata()} instead.
64 */ 64 */
65 public $properties = array(); 65 public $properties = [];
66 66
67 /** 67 /**
68 * @var GetterMetadata[] 68 * @var GetterMetadata[]
69 * 69 *
70 * @internal This property is public in order to reduce the size of the 70 * @internal This property is public in order to reduce the size of the
71 * class' serialized representation. Do not access it. Use 71 * class' serialized representation. Do not access it. Use
72 * {@link getPropertyMetadata()} instead. 72 * {@link getPropertyMetadata()} instead.
73 */ 73 */
74 public $getters = array(); 74 public $getters = [];
75 75
76 /** 76 /**
77 * @var array 77 * @var array
78 * 78 *
79 * @internal This property is public in order to reduce the size of the 79 * @internal This property is public in order to reduce the size of the
80 * class' serialized representation. Do not access it. Use 80 * class' serialized representation. Do not access it. Use
81 * {@link getGroupSequence()} instead. 81 * {@link getGroupSequence()} instead.
82 */ 82 */
83 public $groupSequence = array(); 83 public $groupSequence = [];
84 84
85 /** 85 /**
86 * @var bool 86 * @var bool
87 * 87 *
88 * @internal This property is public in order to reduce the size of the 88 * @internal This property is public in order to reduce the size of the
133 $parentProperties = parent::__sleep(); 133 $parentProperties = parent::__sleep();
134 134
135 // Don't store the cascading strategy. Classes never cascade. 135 // Don't store the cascading strategy. Classes never cascade.
136 unset($parentProperties[array_search('cascadingStrategy', $parentProperties)]); 136 unset($parentProperties[array_search('cascadingStrategy', $parentProperties)]);
137 137
138 return array_merge($parentProperties, array( 138 return array_merge($parentProperties, [
139 'getters', 139 'getters',
140 'groupSequence', 140 'groupSequence',
141 'groupSequenceProvider', 141 'groupSequenceProvider',
142 'members', 142 'members',
143 'name', 143 'name',
144 'properties', 144 'properties',
145 'defaultGroup', 145 'defaultGroup',
146 )); 146 ]);
147 } 147 }
148 148
149 /** 149 /**
150 * {@inheritdoc} 150 * {@inheritdoc}
151 */ 151 */
177 /** 177 /**
178 * {@inheritdoc} 178 * {@inheritdoc}
179 */ 179 */
180 public function addConstraint(Constraint $constraint) 180 public function addConstraint(Constraint $constraint)
181 { 181 {
182 if (!in_array(Constraint::CLASS_CONSTRAINT, (array) $constraint->getTargets())) { 182 if (!\in_array(Constraint::CLASS_CONSTRAINT, (array) $constraint->getTargets())) {
183 throw new ConstraintDefinitionException(sprintf( 183 throw new ConstraintDefinitionException(sprintf('The constraint "%s" cannot be put on classes.', \get_class($constraint)));
184 'The constraint "%s" cannot be put on classes.',
185 get_class($constraint)
186 ));
187 } 184 }
188 185
189 if ($constraint instanceof Valid) { 186 if ($constraint instanceof Valid) {
190 throw new ConstraintDefinitionException(sprintf( 187 throw new ConstraintDefinitionException(sprintf('The constraint "%s" cannot be put on classes.', \get_class($constraint)));
191 'The constraint "%s" cannot be put on classes.',
192 get_class($constraint)
193 ));
194 } 188 }
195 189
196 if ($constraint instanceof Traverse) { 190 if ($constraint instanceof Traverse) {
197 if ($constraint->traverse) { 191 if ($constraint->traverse) {
198 // If traverse is true, traversal should be explicitly enabled 192 // If traverse is true, traversal should be explicitly enabled
348 foreach ($source->getConstrainedProperties() as $property) { 342 foreach ($source->getConstrainedProperties() as $property) {
349 foreach ($source->getPropertyMetadata($property) as $member) { 343 foreach ($source->getPropertyMetadata($property) as $member) {
350 $member = clone $member; 344 $member = clone $member;
351 345
352 foreach ($member->getConstraints() as $constraint) { 346 foreach ($member->getConstraints() as $constraint) {
353 if (in_array($constraint::DEFAULT_GROUP, $constraint->groups, true)) { 347 if (\in_array($constraint::DEFAULT_GROUP, $constraint->groups, true)) {
354 $member->constraintsByGroup[$this->getDefaultGroup()][] = $constraint; 348 $member->constraintsByGroup[$this->getDefaultGroup()][] = $constraint;
355 } 349 }
356 350
357 $constraint->addImplicitGroupName($this->getDefaultGroup()); 351 $constraint->addImplicitGroupName($this->getDefaultGroup());
358 } 352 }
384 * {@inheritdoc} 378 * {@inheritdoc}
385 */ 379 */
386 public function getPropertyMetadata($property) 380 public function getPropertyMetadata($property)
387 { 381 {
388 if (!isset($this->members[$property])) { 382 if (!isset($this->members[$property])) {
389 return array(); 383 return [];
390 } 384 }
391 385
392 return $this->members[$property]; 386 return $this->members[$property];
393 } 387 }
394 388
401 } 395 }
402 396
403 /** 397 /**
404 * Sets the default group sequence for this class. 398 * Sets the default group sequence for this class.
405 * 399 *
406 * @param array $groupSequence An array of group names 400 * @param string[]|GroupSequence $groupSequence An array of group names
407 * 401 *
408 * @return $this 402 * @return $this
409 * 403 *
410 * @throws GroupDefinitionException 404 * @throws GroupDefinitionException
411 */ 405 */
413 { 407 {
414 if ($this->isGroupSequenceProvider()) { 408 if ($this->isGroupSequenceProvider()) {
415 throw new GroupDefinitionException('Defining a static group sequence is not allowed with a group sequence provider'); 409 throw new GroupDefinitionException('Defining a static group sequence is not allowed with a group sequence provider');
416 } 410 }
417 411
418 if (is_array($groupSequence)) { 412 if (\is_array($groupSequence)) {
419 $groupSequence = new GroupSequence($groupSequence); 413 $groupSequence = new GroupSequence($groupSequence);
420 } 414 }
421 415
422 if (in_array(Constraint::DEFAULT_GROUP, $groupSequence->groups, true)) { 416 if (\in_array(Constraint::DEFAULT_GROUP, $groupSequence->groups, true)) {
423 throw new GroupDefinitionException(sprintf('The group "%s" is not allowed in group sequences', Constraint::DEFAULT_GROUP)); 417 throw new GroupDefinitionException(sprintf('The group "%s" is not allowed in group sequences', Constraint::DEFAULT_GROUP));
424 } 418 }
425 419
426 if (!in_array($this->getDefaultGroup(), $groupSequence->groups, true)) { 420 if (!\in_array($this->getDefaultGroup(), $groupSequence->groups, true)) {
427 throw new GroupDefinitionException(sprintf('The group "%s" is missing in the group sequence', $this->getDefaultGroup())); 421 throw new GroupDefinitionException(sprintf('The group "%s" is missing in the group sequence', $this->getDefaultGroup()));
428 } 422 }
429 423
430 $this->groupSequence = $groupSequence; 424 $this->groupSequence = $groupSequence;
431 425
435 /** 429 /**
436 * {@inheritdoc} 430 * {@inheritdoc}
437 */ 431 */
438 public function hasGroupSequence() 432 public function hasGroupSequence()
439 { 433 {
440 return $this->groupSequence && count($this->groupSequence->groups) > 0; 434 return $this->groupSequence && \count($this->groupSequence->groups) > 0;
441 } 435 }
442 436
443 /** 437 /**
444 * {@inheritdoc} 438 * {@inheritdoc}
445 */ 439 */