kylearch/ephemeral-users 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kylearch/ephemeral-users

Composer 安装命令:

composer require kylearch/ephemeral-users

包简介

Laravel package for ephemeral (non-persistent) user instances

README 文档

README

A Laravel package for creating ephemeral (non-persistent) user instances. Perfect for handling anonymous users, session-based users, or any scenario where you need a User object without database persistence.

Features

  • 🚫 Prevent Accidental Persistence - Ephemeral users throw exceptions when save attempts are made
  • 📝 Automatic Logging - Track code paths that attempt to persist ephemeral users
  • 🔧 Configurable Behavior - Choose between throwing exceptions or silently preventing saves
  • 🎯 Type Safe - Full type hinting and interface support
  • 📦 Easy Integration - Simple trait-based implementation

Installation

Add the package to your Laravel application:

composer require kylearch/ephemeral-users

Publish the configuration file (optional):

php artisan vendor:publish --tag=ephemeral-users-config

Usage

Basic Setup

Implement the interface and use the trait in your User model:

use KyleArch\EphemeralUsers\Contracts\EphemeralUser as EphemeralUserContract;
use KyleArch\EphemeralUsers\Concerns\HasEphemeralState;

class User extends Authenticatable implements EphemeralUserContract
{
    use HasEphemeralState;

    // Your existing User model code...
}

Creating Ephemeral Users

// Create an ephemeral user instance
$ephemeralUser = User::ephemeral([
    'id' => 'session-abc123',
    'email' => 'anonymous@example.com',
    'name' => 'Anonymous User',
]);

// Check if a user is ephemeral
if ($ephemeralUser->isEphemeral()) {
    // Handle ephemeral user logic
}

// Get the ephemeral identifier
$identifier = $ephemeralUser->getEphemeralIdentifier(); // 'session-abc123'

Persistence Protection

Attempting to save an ephemeral user will:

  1. Log the attempt (if logging is enabled)
  2. Throw an EphemeralPersistenceException (if configured)
  3. Prevent the save operation
$ephemeralUser = User::ephemeral(['id' => 'test']);

try {
    $ephemeralUser->save(); // Throws EphemeralPersistenceException
} catch (EphemeralPersistenceException $e) {
    // Handle the exception
    $user = $e->getEphemeralUser();
}

Configuration

The package supports the following configuration options:

return [
    // Throw exception on persist attempts (default: true)
    'throw_on_persist' => env('EPHEMERAL_THROW_ON_PERSIST', true),

    // Log persist attempts (default: true)
    'log_attempts' => env('EPHEMERAL_LOG_PERSIST', true),

    // Log channel to use
    'log_channel' => env('EPHEMERAL_LOG_CHANNEL', 'stack'),

    // Log level for persist attempts
    'log_level' => env('EPHEMERAL_LOG_LEVEL', 'warning'),
];

Use Cases

  • Anonymous Users: Handle session-based users without database records
  • Testing: Create test users without database persistence
  • API Integration: Represent external users without local persistence
  • Guest Checkout: Allow guest users with full User object interface
  • Sample/Demo Flows: Enable trial experiences without account creation

License

MIT

kylearch/ephemeral-users 适用场景与选型建议

kylearch/ephemeral-users 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.36k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2025 年 10 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 kylearch/ephemeral-users 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 kylearch/ephemeral-users 我们能提供哪些服务?
定制开发 / 二次开发

基于 kylearch/ephemeral-users 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.36k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-20