Skip to content

Commit 7b30fc6

Browse files
committed
Make deleted value configurable for SoftDeleteableFilter.php
1 parent 0fe2e47 commit 7b30fc6

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

src/Mapping/Annotation/SoftDeleteable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ final class SoftDeleteable implements GedmoAnnotation
3535

3636
public bool $hardDelete = true;
3737

38-
public $deletedValue = null;
38+
public ?string $deletedValue = null;
3939

4040
/**
4141
* @param array<string, mixed> $data
4242
*/
43-
public function __construct(array $data = [], string $fieldName = 'deletedAt', bool $timeAware = false, bool $hardDelete = true, $deletedValue = null)
43+
public function __construct(array $data = [], string $fieldName = 'deletedAt', bool $timeAware = false, bool $hardDelete = true, ?string $deletedValue = null)
4444
{
4545
if ([] !== $data) {
4646
Deprecation::trigger(

src/SoftDeleteable/Mapping/Driver/Attribute.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public function readExtendedMetadata($meta, array &$config)
6464
}
6565

6666
if (isset($annot->deletedValue)) {
67+
if (!is_string($annot->deletedValue)) {
68+
throw new InvalidMappingException('deletedValue must be string. '.gettype($annot->deletedValue).' provided.');
69+
}
70+
6771
$config['deletedValue'] = $annot->deletedValue;
6872
}
6973
}

src/SoftDeleteable/Mapping/Driver/Xml.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public function readExtendedMetadata($meta, array &$config)
5858
if ($this->_isAttributeSet($xml->{'soft-deleteable'}, 'hard-delete')) {
5959
$config['hardDelete'] = $this->_getBooleanAttribute($xml->{'soft-deleteable'}, 'hard-delete');
6060
}
61+
62+
$config['deletedValue'] = null;
63+
if ($this->_isAttributeSet($xml->{'soft-deleteable'}, 'deleted-value')) {
64+
$config['deletedValue'] = $this->_getAttribute($xml->{'soft-deleteable'}, 'deleted-value');
65+
}
6166
}
6267
}
6368

src/SoftDeleteable/Mapping/Driver/Yaml.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ public function readExtendedMetadata($meta, array &$config)
7070
}
7171
$config['hardDelete'] = $classMapping['soft_deleteable']['hard_delete'];
7272
}
73+
74+
$config['deletedValue'] = null;
75+
if (isset($classMapping['soft_deleteable']['deleted_value'])) {
76+
if (!is_string($classMapping['soft_deleteable']['deleted_value'])) {
77+
throw new InvalidMappingException('deletedValue must be string. ' . gettype($classMapping['soft_deleteable']['deleted_value']) . ' provided.');
78+
}
79+
$config['deletedValue'] = $classMapping['soft_deleteable']['deleted_value'];
80+
}
7381
}
7482
}
7583

0 commit comments

Comments
 (0)