aeviiq / storage-manager
Storage Manager Component
Installs: 17 076
Dependents: 1
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- php: ^8.1
- doctrine/common: ^3.4
- doctrine/persistence: ^2.1|^3.0
- myclabs/deep-copy: ^1.11
- symfony/http-foundation: ^6.0
Requires (Dev)
- phpstan/phpstan: ^1.8
- phpstan/phpstan-phpunit: ^1.1
- phpstan/phpstan-strict-rules: ^1.4
- phpunit/phpunit: ^9.5
- psalm/plugin-phpunit: ^0.17.0
- thecodingmachine/phpstan-strict-rules: ^1.0
- vimeo/psalm: ^4.27
README
Why
To provide an easy way to store data with references to Doctrine entities, without storing the entities or their proxies themselves. A deep copy of the original object is made, in which any entity will be detached and have their identifiers stored with them. These will be used to retrieve a managed entity upon load().
The objects are saved as a copy, meaning referential changes will not affect the object that is stored. To persist any changes, save() the object. See example below.
Support for readonly properties
To copy an object, the StorageManager uses the DeepCopy component from MyClabs. This component does not yet have support for the newly introducted readonly properties in PHP 8.1.
They do have an open ticket to support this.
Installation
composer require aeviiq/storage-manager
Usage
final class Foo { public function __construct(private readonly StorageManagerInterface $storageManager) { } public function __invoke(): void { $object = new stdClass(); $object->foo = 'foo'; $this->storageManager->save('some_key', $object); // These changes are made after the save() call and will not be there upon load(). $object->foo = 'bar'; $loadedObject = $this->storageManager->load('some_key'); $object === $loadedObject; // false $loadedObject->foo === 'bar' // false } }