Skip to content

Commit f4e721d

Browse files
[SSP-2007] entity changes log (#2980)
2 parents 485a19f + 53be7c6 commit f4e721d

File tree

57 files changed

+2340
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2340
-8
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\FrameworkBundle\Component\EntityLog\Attribute;
6+
7+
use Attribute;
8+
9+
#[Attribute(Attribute::TARGET_METHOD)]
10+
class EntityLogIdentify
11+
{
12+
public const IS_LOCALIZED = true;
13+
14+
/**
15+
* @param bool $isLocalized
16+
*/
17+
public function __construct(
18+
public bool $isLocalized = false,
19+
) {
20+
}
21+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\FrameworkBundle\Component\EntityLog\Attribute;
6+
7+
use Attribute;
8+
9+
#[Attribute(Attribute::TARGET_PROPERTY)]
10+
class ExcludeLog
11+
{
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\FrameworkBundle\Component\EntityLog\Attribute;
6+
7+
use Attribute;
8+
9+
#[Attribute(Attribute::TARGET_PROPERTY)]
10+
class Log
11+
{
12+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\FrameworkBundle\Component\EntityLog\Attribute;
6+
7+
use Attribute;
8+
9+
#[Attribute(Attribute::TARGET_CLASS)]
10+
class Loggable
11+
{
12+
public const STRATEGY_EXCLUDE_ALL = 'exclude_all';
13+
public const STRATEGY_INCLUDE_ALL = 'include_all';
14+
15+
/**
16+
* @param string $strategy
17+
*/
18+
public function __construct(
19+
protected readonly string $strategy = self::STRATEGY_INCLUDE_ALL,
20+
) {
21+
}
22+
23+
/**
24+
* @return string
25+
*/
26+
public function getStrategy(): string
27+
{
28+
return $this->strategy;
29+
}
30+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\FrameworkBundle\Component\EntityLog\Attribute;
6+
7+
use Attribute;
8+
9+
#[Attribute(Attribute::TARGET_CLASS)]
10+
class LoggableChild extends Loggable
11+
{
12+
}
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
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+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\FrameworkBundle\Component\EntityLog\Attribute;
6+
7+
class LoggableEntityConfigCacheFacade
8+
{
9+
/**
10+
* @var \Shopsys\FrameworkBundle\Component\EntityLog\Attribute\LoggableEntityConfig[]
11+
*/
12+
protected array $loggableEntityConfigCache = [];
13+
14+
/**
15+
* @param \Shopsys\FrameworkBundle\Component\EntityLog\Attribute\LoggableEntityConfig $loggableEntityConfig
16+
*/
17+
public function addLoggableEntityConfig(LoggableEntityConfig $loggableEntityConfig): void
18+
{
19+
$this->loggableEntityConfigCache[$loggableEntityConfig->getEntityName()] = $loggableEntityConfig;
20+
}
21+
22+
/**
23+
* @param string $entityName
24+
* @return \Shopsys\FrameworkBundle\Component\EntityLog\Attribute\LoggableEntityConfig|null
25+
*/
26+
public function findLoggableEntityConfig(string $entityName): ?LoggableEntityConfig
27+
{
28+
return $this->loggableEntityConfigCache[$entityName] ?? null;
29+
}
30+
}

0 commit comments

Comments
 (0)