Skip to content

Commit 0817336

Browse files
committed
修正
1 parent 8cbd0b4 commit 0817336

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/ModelMarkingStore.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ public function __construct(string $property = 'status', ?array $map = null)
1717
$this->map = $map;
1818
}
1919

20-
protected function getPlace($marking)
20+
protected function convert($value, $flip = true)
2121
{
2222
if (empty($this->map)) {
23-
return $marking;
23+
return $value;
2424
}
25-
return $this->map[$marking];
25+
if ($flip) {
26+
return array_flip($this->map)[$value];
27+
}
28+
return $this->map[$value];
2629
}
2730

2831
/**
@@ -31,7 +34,7 @@ protected function getPlace($marking)
3134
*/
3235
public function getMarking(object $subject)
3336
{
34-
$marking = $this->getPlace($subject->getAttr($this->property));
37+
$marking = $this->convert($subject->getAttr($this->property));
3538

3639
if (!$marking) {
3740
return new Marking();
@@ -52,7 +55,7 @@ public function setMarking(object $subject, Marking $marking, array $context = [
5255

5356
$marking = key($marking);
5457

55-
$subject->setAttr($this->property, $this->getPlace($marking));
58+
$subject->setAttr($this->property, $this->convert($marking, false));
5659

5760
$subject->save($context);
5861
}

0 commit comments

Comments
 (0)