/** * @param DataMapper $mapper * @param User $user * @param string $type * @return Token */ public function createToken(DataMapper $mapper, User $user, $type) { $this->assert($mapper->getEntityClass() == Token::class); $code = preg_replace('/[^a-zA-Z0-9\\_\\-]+/', null, Rand::getString(100)); return $mapper->create(['user' => $user, 'code' => sprintf('%d.%d.%s', $user->getId(), time(), $code), 'type' => $type]); }
/** * @return int|null */ public function getRecordIdOrNull() { return $this->existingRecord ? $this->existingRecord->getId() : null; }