-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skipped properties work independently of MappedObject
- Loading branch information
Showing
4 changed files
with
59 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Orisai\ObjectMapper\Processing; | ||
|
||
use Orisai\Exceptions\Logic\InvalidState; | ||
use Orisai\ObjectMapper\Context\SkippedPropertiesContext; | ||
use Orisai\ObjectMapper\MappedObject; | ||
use WeakMap; | ||
|
||
final class SkippedPropertiesContextMap | ||
{ | ||
|
||
/** @var WeakMap<MappedObject, SkippedPropertiesContext|null> */ | ||
private WeakMap $map; | ||
|
||
public function __construct() | ||
{ | ||
$this->map = new WeakMap(); | ||
} | ||
|
||
public function setSkippedPropertiesContext(MappedObject $object, ?SkippedPropertiesContext $context): void | ||
{ | ||
if ($context === null) { | ||
$this->map->offsetUnset($object); | ||
} else { | ||
$this->map->offsetSet($object, $context); | ||
} | ||
} | ||
|
||
public function hasSkippedPropertiesContext(MappedObject $object): bool | ||
{ | ||
return $this->map->offsetExists($object); | ||
} | ||
|
||
public function getSkippedPropertiesContext(MappedObject $object): SkippedPropertiesContext | ||
{ | ||
$context = $this->map->offsetExists($object) | ||
? $this->map->offsetGet($object) | ||
: null; | ||
|
||
if ($context === null) { | ||
throw InvalidState::create() | ||
->withMessage('Check partial object existence with hasSkippedPropertiesContext()'); | ||
} | ||
|
||
return $context; | ||
} | ||
|
||
} |