edmondscommerce /
doctrine-static-meta
| 1 | <?php declare(strict_types=1); |
||
| 2 | |||
| 3 | namespace TemplateNamespace\Entity\Fields\Traits; |
||
| 4 | |||
| 5 | use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData; |
||
| 6 | use TemplateNamespace\Entity\Fields\Interfaces\TemplateFieldNameFieldInterface; |
||
| 7 | |||
| 8 | trait TemplateFieldNameFieldTrait |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var string |
||
| 12 | */ |
||
| 13 | private $templateFieldName; |
||
| 14 | |||
| 15 | |||
| 16 | /** |
||
| 17 | * This method sets the validation for this field. |
||
| 18 | * You should add in as many relevant property constraints as you see fit. |
||
| 19 | * |
||
| 20 | * Remove the PHPMD suppressed warning once you start setting constraints |
||
| 21 | * |
||
| 22 | * @param ValidatorClassMetaData $metadata |
||
| 23 | * |
||
| 24 | * @see https://symfony.com/doc/current/validation.html#supported-constraints |
||
| 25 | * |
||
| 26 | * @throws \Symfony\Component\Validator\Exception\MissingOptionsException |
||
| 27 | * @throws \Symfony\Component\Validator\Exception\InvalidOptionsException |
||
| 28 | * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException |
||
| 29 | * |
||
| 30 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
||
| 31 | */ |
||
| 32 | protected static function validatorMetaForPropertyTemplateFieldName(ValidatorClassMetaData $metadata): void |
||
| 33 | { |
||
| 34 | // $metadata->addPropertyConstraint( |
||
| 35 | // TemplateFieldNameFieldInterface::PROP_TEMPLATE_FIELD_NAME, |
||
| 36 | // new NotBlank() |
||
| 37 | // ); |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @return string |
||
| 42 | */ |
||
| 43 | public function getTemplateFieldName(): string |
||
| 44 | { |
||
| 45 | if (null === $this->templateFieldName) { |
||
| 46 | return TemplateFieldNameFieldInterface::DEFAULT_TEMPLATE_FIELD_NAME; |
||
| 47 | } |
||
| 48 | |||
| 49 | return $this->templateFieldName; |
||
| 50 | } |
||
| 51 | |||
| 52 | private function initTemplateFieldName(): void |
||
| 53 | { |
||
| 54 | $this->templateFieldName = TemplateFieldNameFieldInterface::DEFAULT_TEMPLATE_FIELD_NAME; |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param string $templateFieldName |
||
| 59 | * |
||
| 60 | * @return self |
||
| 61 | */ |
||
| 62 | private function setTemplateFieldName(string $templateFieldName): self |
||
| 63 | { |
||
| 64 | $this->updatePropertyValue( |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 65 | TemplateFieldNameFieldInterface::PROP_TEMPLATE_FIELD_NAME, |
||
| 66 | $templateFieldName |
||
| 67 | ); |
||
| 68 | |||
| 69 | return $this; |
||
| 70 | } |
||
| 71 | } |
||
| 72 |