{ if (!$obj) { $obj = json_decode(' { "title": "New idea" } '); } unset($obj->id); return new Idea($obj); } public function put($obj) { $obj->id = $this->id; $patch = json_diff($this, $obj); if (count($patch) == 0) { return; } foreach ($obj as $key => $value) { $this->{$key} = $value; } foreach ($this as $key => $value) { if (!isset($obj->{$key})) { unset($this->{$key}); } } $this->save(); } } JsonStore::addMysqlConfig('Idea', array("table" => "ideas", "keyColumn" => "integer/id", "columns" => array("json" => "json", "integer/id" => "id", "string/title" => "title", "string/feasibility" => "feasibility")));
return $clone; } public function put($obj) { $obj->id = $this->id; $obj->password = $this->password; foreach ($obj as $key => $value) { $this->{$key} = $value; } foreach ($this as $key => $value) { if (!isset($obj->{$key})) { unset($this->{$key}); } } } public function checkPassword($password) { $hash = hash($this->password->algorithm, $this->password->salt . $password); return $hash == $this->password->hash; } public function setPassword($password) { $this->password = new StdClass(); $this->password->salt = openssl_random_pseudo_bytes(20); $this->password->algorithm = "sha256"; // yeah, I know - but bcrypt is only built-in for PHP 5.5+ $this->password->hash = hash($this->password->algorithm, $this->password->salt . $password); } } JsonStore::addMysqlConfig('User', array("table" => "users", "keyColumn" => "integer/id", "columns" => array("integer/id" => "id", "string/username" => "username", "string/name" => "name", "string/password/salt" => "pw_salt", "string/password/algorithm" => "pw_algo", "string/password/hash" => "pw_hash")));