| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- declare(strict_types=1);
- namespace App\Service\Utils;
- use App\Attribute\BillingSettingDefaultValue;
- use App\Attribute\OrganizationDefaultValue;
- use App\Entity\Access\Access;
- /**
- * Class EntityUtils : Gestion des valeurs par défauts devant être présentes dans les entités.
- */
- class EntityUtils
- {
- /**
- * @throws \ReflectionException
- */
- public function defaultValueSettersByAccess(mixed $entity, Access $access): void
- {
- $this->organizationDefaultValue($entity, $access);
- $this->billingSettingDefaultValueDefaultValue($entity, $access);
- }
- /**
- * @throws \ReflectionException
- */
- protected function organizationDefaultValue(mixed $entity, Access $access): void
- {
- $reflection = new \ReflectionClass($entity::class);
- $organizationFaultValue = $reflection->getAttributes(OrganizationDefaultValue::class)[0] ?? null;
- $fieldName = $organizationFaultValue?->getArguments()['fieldName'] ?? null;
- if ($fieldName) {
- $entity->{sprintf('set%s', ucfirst($fieldName))}(...[$access->getOrganization()]);
- }
- }
- /**
- * @throws \ReflectionException
- */
- protected function billingSettingDefaultValueDefaultValue(mixed $entity, Access $access): void
- {
- $reflection = new \ReflectionClass($entity::class);
- $billingSettingDefaultValueDefault = $reflection->getAttributes(BillingSettingDefaultValue::class)[0] ?? null;
- $fieldName = $billingSettingDefaultValueDefault?->getArguments()['fieldName'] ?? null;
- if ($fieldName) {
- $entity->{sprintf('set%s', ucfirst($fieldName))}(...[$access->getOrganization()?->getBillingSetting()]);
- }
- }
- }
|