-
-
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.
Raw values work independently of MappedObject
- Loading branch information
Showing
6 changed files
with
67 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Orisai\ObjectMapper\Processing; | ||
|
||
use Orisai\Exceptions\Logic\InvalidState; | ||
use Orisai\ObjectMapper\MappedObject; | ||
use WeakMap; | ||
use function sprintf; | ||
|
||
final class RawValuesMap | ||
{ | ||
|
||
/** @var WeakMap<MappedObject, mixed> */ | ||
private WeakMap $map; | ||
|
||
public function __construct() | ||
{ | ||
$this->map = new WeakMap(); | ||
} | ||
|
||
/** | ||
* @param mixed $values | ||
*/ | ||
public function setRawValues(MappedObject $object, $values): void | ||
{ | ||
$this->map->offsetSet($object, $values); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getRawValues(MappedObject $object) | ||
{ | ||
if (!$this->map->offsetExists($object)) { | ||
throw InvalidState::create() | ||
->withMessage(sprintf( | ||
'Cannot get raw values as they were never set. You may achieve it by setting %s::setFillRawValues(true)', | ||
Options::class, | ||
)); | ||
} | ||
|
||
return $this->map->offsetGet($object); | ||
} | ||
|
||
} |
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