/** * @param User $user * @return UserSession */ public function getByUser(User $user) { $userSession = $this->getBy(function (UserSession $userSession) use($user) { return $userSession->getUser()->getId() === $user->getId(); })->first(); return $userSession ?: null; }
/** * @param User $user * @return UserSession */ public function getByUser(User $user) { $criteria = Criteria::create(); $expr = Criteria::expr(); $criteria->where($expr->eq('userId', $user->getId())); $sessions = $this->getAll($criteria, true); return $sessions->getNextElement(); }
public function __construct(User $user) { $this->token = md5(uniqid($user->getId(), true)); }