|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Shopsys\FrameworkBundle\Component\EntityLog\Attribute; |
| 6 | + |
| 7 | +class LoggableEntityConfig |
| 8 | +{ |
| 9 | + /** |
| 10 | + * @param string $entityName |
| 11 | + * @param string $entityFullyQualifiedName |
| 12 | + * @param bool $isLoggable |
| 13 | + * @param array $excludedPropertyNames |
| 14 | + * @param array $includedPropertyNames |
| 15 | + * @param string|null $strategy |
| 16 | + * @param string|null $entityReadableNameFunctionName |
| 17 | + * @param bool $isLocalized |
| 18 | + * @param string|null $parentEntityName |
| 19 | + * @param string|null $parentEntityFunctionName |
| 20 | + * @param string|null $parentEntityIdentityFunctionName |
| 21 | + */ |
| 22 | + public function __construct( |
| 23 | + protected string $entityName, |
| 24 | + protected string $entityFullyQualifiedName, |
| 25 | + protected bool $isLoggable, |
| 26 | + protected array $excludedPropertyNames = [], |
| 27 | + protected array $includedPropertyNames = [], |
| 28 | + protected ?string $strategy = null, |
| 29 | + protected ?string $entityReadableNameFunctionName = null, |
| 30 | + protected bool $isLocalized = false, |
| 31 | + protected ?string $parentEntityName = null, |
| 32 | + protected ?string $parentEntityFunctionName = null, |
| 33 | + protected ?string $parentEntityIdentityFunctionName = null, |
| 34 | + ) { |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @return string |
| 39 | + */ |
| 40 | + public function getEntityName(): string |
| 41 | + { |
| 42 | + return $this->entityName; |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * @return string |
| 47 | + */ |
| 48 | + public function getEntityFullyQualifiedName(): string |
| 49 | + { |
| 50 | + return $this->entityFullyQualifiedName; |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * @return bool |
| 55 | + */ |
| 56 | + public function isLoggable(): bool |
| 57 | + { |
| 58 | + return $this->isLoggable; |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @return string|null |
| 63 | + */ |
| 64 | + public function getStrategy(): ?string |
| 65 | + { |
| 66 | + return $this->strategy; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * @param string|null $strategy |
| 71 | + */ |
| 72 | + public function setStrategy(?string $strategy): void |
| 73 | + { |
| 74 | + $this->strategy = $strategy; |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * @return string|null |
| 79 | + */ |
| 80 | + public function getEntityReadableNameFunctionName(): ?string |
| 81 | + { |
| 82 | + return $this->entityReadableNameFunctionName; |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * @param string|null $entityReadableNameFunctionName |
| 87 | + */ |
| 88 | + public function setEntityReadableNameFunctionName(?string $entityReadableNameFunctionName): void |
| 89 | + { |
| 90 | + $this->entityReadableNameFunctionName = $entityReadableNameFunctionName; |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * @return bool |
| 95 | + */ |
| 96 | + public function isLocalized(): bool |
| 97 | + { |
| 98 | + return $this->isLocalized; |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * @param bool $isLocalized |
| 103 | + */ |
| 104 | + public function setIsLocalized(bool $isLocalized): void |
| 105 | + { |
| 106 | + $this->isLocalized = $isLocalized; |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * @return string|null |
| 111 | + */ |
| 112 | + public function getParentEntityName(): ?string |
| 113 | + { |
| 114 | + return $this->parentEntityName; |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * @param string $parentEntityName |
| 119 | + */ |
| 120 | + public function setParentEntityName(string $parentEntityName): void |
| 121 | + { |
| 122 | + $this->parentEntityName = $parentEntityName; |
| 123 | + $this->parentEntityFunctionName = sprintf('get%s', ucfirst($parentEntityName)); |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * @return string|null |
| 128 | + */ |
| 129 | + public function getParentEntityFunctionName(): ?string |
| 130 | + { |
| 131 | + return $this->parentEntityFunctionName; |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * @return string|null |
| 136 | + */ |
| 137 | + public function getParentEntityIdentityFunctionName(): ?string |
| 138 | + { |
| 139 | + return $this->parentEntityIdentityFunctionName; |
| 140 | + } |
| 141 | + |
| 142 | + /** |
| 143 | + * @param string $parentEntityIdentityFunctionName |
| 144 | + */ |
| 145 | + public function setParentEntityIdentityFunctionName(string $parentEntityIdentityFunctionName): void |
| 146 | + { |
| 147 | + $this->parentEntityIdentityFunctionName = $parentEntityIdentityFunctionName; |
| 148 | + } |
| 149 | + |
| 150 | + /** |
| 151 | + * @param string $excludedPropertyName |
| 152 | + */ |
| 153 | + public function addExcludedPropertyName(string $excludedPropertyName): void |
| 154 | + { |
| 155 | + $this->excludedPropertyNames[$excludedPropertyName] = $excludedPropertyName; |
| 156 | + } |
| 157 | + |
| 158 | + /** |
| 159 | + * @param string $includedPropertyName |
| 160 | + */ |
| 161 | + public function addIncludedPropertyName(string $includedPropertyName): void |
| 162 | + { |
| 163 | + $this->includedPropertyNames[$includedPropertyName] = $includedPropertyName; |
| 164 | + } |
| 165 | + |
| 166 | + /** |
| 167 | + * @param string $propertyName |
| 168 | + * @return bool |
| 169 | + */ |
| 170 | + public function isPropertyLoggable(string $propertyName): bool |
| 171 | + { |
| 172 | + if ($this->isLoggable() === false) { |
| 173 | + return false; |
| 174 | + } |
| 175 | + |
| 176 | + if ($this->getStrategy() === null) { |
| 177 | + return false; |
| 178 | + } |
| 179 | + |
| 180 | + if ($this->getStrategy() === Loggable::STRATEGY_EXCLUDE_ALL) { |
| 181 | + return array_key_exists($propertyName, $this->includedPropertyNames); |
| 182 | + } |
| 183 | + |
| 184 | + return array_key_exists($propertyName, $this->excludedPropertyNames) === false; |
| 185 | + } |
| 186 | + |
| 187 | + /** |
| 188 | + * @return bool |
| 189 | + */ |
| 190 | + public function isEntityIdentifiable(): bool |
| 191 | + { |
| 192 | + return $this->getEntityReadableNameFunctionName() !== null; |
| 193 | + } |
| 194 | +} |
0 commit comments