Last active
June 21, 2017 19:29
-
-
Save AnrDaemon/c0d8b507e3675f29d0633304b963e307 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?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