kingsquare / communibase-databag
Communibase dataBag
Installs: 4 353
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 4
Forks: 1
Open Issues: 2
Requires
- php: >=7.3
Requires (Dev)
- phpstan/phpstan-shim: ^0.11.8
- phpunit/phpunit: ^8
This package is auto-updated.
Last update: 2024-10-26 16:52:25 UTC
README
It's a bag, for CB data. If we need to create a CB object from CB data (array) we can use this dataBag object as a private entity class property. The dataBag can contain one or more entities. For each entity we can get/set properties by path. If we need to persist the entity back into CB use getState to fetch the (updated) data array.
namespace Communibase; /** * @author Kingsquare (source@kingsquare.nl) * @copyright Copyright (c) Kingsquare BV (http://www.kingsquare.nl) */ class ExamplePerson { /** * @var DataBag */ private $databag; /** * @param array<string,mixed> $personData */ private function __construct(array $personData) { $this->databag = DataBag::fromEntityData('person', $personData); } /** * @param array<string,mixed> $personData */ public static function fromPersonData(array $personData): ExamplePerson { return new self($personData); } public function getFirstName(): string { return (string)$this->databag->get('person.firstName'); } public function setFirstName(string $firstName): void { $this->databag->set('person.firstName', $firstName); } /** * @return array<string,mixed> */ public function getState(): array { return $this->databag->getState('person'); } } // $person = $personRepository->findById($communibasePersonId); // returns ExamplePerson::fromPersonData($fetchedCbData) // $person->setFirstName('John'); // $personRepository->persist($person); // does $cbConnector->update('Person', $person->getState('person'));