Comments (5)
That's possible
<?php
declare(strict_types=1);
namespace App\Model;
use function Makasim\Values\add_object;
use function Makasim\Values\get_object;
use function Makasim\Values\get_objects;
use function Makasim\Values\set_object;
class Campaign
{
private $values = [];
private $objects = [];
public function setState(CampaignState $state): void
{
set_object($this,'state', $state);
add_object($this, 'previousStates', $state);
}
public function getState(): CampaignState
{
return get_object($this, 'state');
}
public function getPreviousStates(): array
{
return get_objects($this, 'previousStates');
}
}
from yadm.
Ohhh, thank you.
I will try it.
from yadm.
My test:
<?php
declare(strict_types=1);
require_once __DIR__.'/vendor/autoload.php';
use MongoDB\Client;
use Makasim\Yadm\Hydrator;
use Makasim\Yadm\Storage;
use function Makasim\Values\add_object;
use function Makasim\Values\get_object;
use function Makasim\Values\get_objects;
use function Makasim\Values\set_object;
use function Makasim\Values\get_value;
use function Makasim\Values\set_value;
use function Makasim\Yadm\get_object_id;
class CampaignState
{
private $values = [];
private $objects = [];
public function setTitle(string $title): void
{
set_value($this, 'title', $title);
}
public function getTitle(): string
{
return get_value($this, 'title');
}
}
class Campaign
{
private static $i = 0;
private $values = [];
private $objects = [];
public function setState(CampaignState $state): void
{
set_value($this, 'i', self::$i);
set_object($this, 'state', $state);
add_object($this, 'previousStates', $state);
}
public function getState(): CampaignState
{
return get_object($this, 'state');
}
public function getPreviousStates(): array
{
return iterator_to_array(get_objects($this, 'previousStates', CampaignState::class));
}
}
$collection = (new Client())->selectCollection('acme_demo', 'orders');
$hydrator = new Hydrator(Campaign::class);
$storage = new Storage($collection, $hydrator);
$campaign = new Campaign();
$state = new CampaignState();
$state->setTitle('1.- 123');
$campaign->setState($state);
$state2 = new CampaignState();
$state2->setTitle('2.- 123');
$campaign->setState($state2);
$storage->insert($campaign);
$foundCampaign = $storage->findOne(['_id' => get_object_id($campaign)]);
var_dump($foundCampaign);
var_dump($foundCampaign->getPreviousStates());
from yadm.
@rubenrua Working?
from yadm.
Yes.
from yadm.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yadm.