Closed Jud closed 10 years ago
There are better ways to approach this. Using your password example
class User
{
public function properties()
{
return array('pwhash' => new Types\String());
}
public function setPassword($password)
{
$this->pwhash = password_hash($password);
}
...
@mtibben - man, your right. I swear I tried creating a setter and it didn't work. I might work on a few doc fixes so this stuff becomes more obvious.
@mtibben actually I just tried implementing this with custom getters/setters and I get a 'No getter available for $x' error.
If you were suggesting that I would be able to do User->password = 'xyz'
, I don't believe that is the case. If you were suggesting to use User->setPassword('xyz')
I think pheasant could do better than that.
@lox is there a way to do custom magic getters and setters in pheasant right now?
I can accomplish what I want with a simple onHydrate and public property! #81 fixes this.
In some cases, it could be useful to have attributes that are not persisted to the DB. For instance, user models could have a virtual
password
property that is bcrypt'ed in a beforeSave handler, and stored in a column calledencrypted_password
.We are using virtual attribute support together with onHydrate callbacks to normalize our data model as we migrate data to different tables, which allows us to keep model property access consistent, even across data migrations.
These changes allow you to define virtual properties in your schema, which makes sense if you think of the schema as the DomainObject schema, and not the mysql schema. So the property definitions become:
If you are interested in this pull, I'll add tests.