Skip to content

Commit

Permalink
修正
Browse files Browse the repository at this point in the history
  • Loading branch information
yunwuxin committed Apr 6, 2020
1 parent 8cbd0b4 commit 0817336
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/ModelMarkingStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ public function __construct(string $property = 'status', ?array $map = null)
$this->map = $map;
}

protected function getPlace($marking)
protected function convert($value, $flip = true)
{
if (empty($this->map)) {
return $marking;
return $value;
}
return $this->map[$marking];
if ($flip) {
return array_flip($this->map)[$value];
}
return $this->map[$value];
}

/**
Expand All @@ -31,7 +34,7 @@ protected function getPlace($marking)
*/
public function getMarking(object $subject)
{
$marking = $this->getPlace($subject->getAttr($this->property));
$marking = $this->convert($subject->getAttr($this->property));

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

$marking = key($marking);

$subject->setAttr($this->property, $this->getPlace($marking));
$subject->setAttr($this->property, $this->convert($marking, false));

$subject->save($context);
}
Expand Down

0 comments on commit 0817336

Please sign in to comment.