开发者

Compare two Doctrine_Record objects

开发者 https://www.devze.com 2023-01-19 11:30 出处:网络
How do I compare two Doctrine_Record objects to see if they are \"equal\"? On the domain login I am considering, t开发者_运维知识库wo objects are equal if they have the same properties values, except

How do I compare two Doctrine_Record objects to see if they are "equal"?

On the domain login I am considering, t开发者_运维知识库wo objects are equal if they have the same properties values, except the id and the created_at and updated_at fields (a la Timestampable).


First idea which comes into my mind is:

class User extends Doctrine_Record
{
  public function equals(User $user)
  {
    $left = $this->toArray();
    $right = $user->toArray();

    unset($left['id'], $left['created_at'], $left['updated_at']);
    unset($right['id'], $right['created_at'], $right['updated_at']);

    return $left == $right;
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消