Skip to content

Instantly share code, notes, and snippets.

@nicholasruunu
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicholasruunu/792ff06ceb183b5e2512 to your computer and use it in GitHub Desktop.
Save nicholasruunu/792ff06ceb183b5e2512 to your computer and use it in GitHub Desktop.
final class DatabaseName implements Name {
private $db;
private $table;
public function __construct(Database $db, string $table) {
$this->db = $db;
$this->table = $table;
}
public function rename($name) {
$this->db->sql("UPDATE $this->table SET name = $name ...");
}
public function toString() {
return $this->db->sql("SELECT name FROM $this->table ...");
}
}
final class ConstantName implements Name {
private $origin;
private $name;
public function __construct(Name $origin, string $name) {
$this->origin = $origin;
$this->name = $name;
}
public function rename($name) {
$this->origin->rename($name);
}
public function toString() {
return $this->name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment