承接 locky42/leopard-user 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

locky42/leopard-user

最新稳定版本:1.0.0

Composer 安装命令:

composer require locky42/leopard-user

包简介

A library for handling user authentication and management.

README 文档

README

locky42/leopard-user provides base user/auth/RBAC building blocks for Leopard projects.

Features

  • Base Doctrine models:
    • Leopard\User\Models\BaseUser
    • Leopard\User\Models\BaseRole
    • Leopard\User\Models\BasePermission
  • Authentication service with session restore
  • Authorization service for role/permission checks
  • Contract-first model mapping (UserInterface, RoleInterface, PermissionInterface)

Requirements

  • PHP ^8.3
  • locky42/leopard-doctrine

Doctrine Integration

Package bootstrap registers resolve-target mappings and model paths automatically.

Registered default mappings:

  • UserInterface -> BaseUser
  • RoleInterface -> BaseRole
  • PermissionInterface -> BasePermission

Quick Start

Authentication

use Leopard\User\Contracts\Models\UserInterface;
use Leopard\User\Models\BaseUser;
use Leopard\User\Services\AuthenticationService;

$userFinder = function (string $identifier) use ($entityManager): ?UserInterface {
    return $entityManager->getRepository(BaseUser::class)
        ->findOneBy(['username' => $identifier]);
};

$userFinderById = function (int $id) use ($entityManager): ?UserInterface {
    return $entityManager->getRepository(BaseUser::class)->find($id);
};

$authService = new AuthenticationService($userFinder, $userFinderById);

$user = $authService->attempt('john', 'password123');
if ($user !== null) {
    echo 'Login successful';
}

Authorization

use Leopard\User\Services\AuthorizationService;

$authzService = new AuthorizationService();

if ($authzService->hasRole($user, 'admin')) {
    echo 'User is admin';
}

if ($authzService->hasPermission($user, 'posts.delete')) {
    echo 'User can delete posts';
}

Services API

AuthenticationService

  • authenticate(string $identifier, string $password): ?UserInterface
  • login(UserInterface $user): bool
  • logout(): bool
  • getCurrentUser(): ?UserInterface
  • isAuthenticated(): bool
  • attempt(string $identifier, string $password): ?UserInterface
  • destroySession(): void

AuthorizationService

  • hasRole(UserInterface $user, string $roleName): bool
  • hasAnyRole(UserInterface $user, array $roleNames): bool
  • hasAllRoles(UserInterface $user, array $roleNames): bool
  • hasPermission(UserInterface $user, string $permissionName): bool
  • hasAnyPermission(UserInterface $user, array $permissionNames): bool
  • hasAllPermissions(UserInterface $user, array $permissionNames): bool
  • getUserRoles(UserInterface $user): array
  • getUserPermissions(UserInterface $user): array

ContractFactory Integration

In application code, use ContractFactory to map contracts to your own entities:

use Leopard\Core\Factory\ContractFactory;
use Leopard\User\Contracts\Models\UserInterface;
use Leopard\User\Contracts\Models\RoleInterface;
use Leopard\User\Contracts\Models\PermissionInterface;
use App\Models\User;
use App\Models\Role;
use App\Models\Permission;

ContractFactory::register(UserInterface::class, User::class);
ContractFactory::register(RoleInterface::class, Role::class);
ContractFactory::register(PermissionInterface::class, Permission::class);

Testing

From repository root:

vendor/bin/phpunit --testsuite=leopard-user

or

composer test:user

License

MIT

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固