Skip to content

Instantly share code, notes, and snippets.

@AnrDaemon
Last active June 21, 2017 19:29
Show Gist options
  • Save AnrDaemon/c0d8b507e3675f29d0633304b963e307 to your computer and use it in GitHub Desktop.
Save AnrDaemon/c0d8b507e3675f29d0633304b963e307 to your computer and use it in GitHub Desktop.
<?php
final class Repository
{
public save(Entity $item) {}
public find($criteria): Entity {}
public __construct(PDO $db) {}
}
final class Entity
{
private $state = [];
public static createFromState(array $state): static
{
$self = new static();
$self->state = $state;
return $self;
}
public saveState(): array
{
return $this->state;
}
// Magic
private function __construct(){}
public function __set_state(array $state): static
{
return static::createFromState($state['state']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment