lowerrocklabs/laravel-lockable 问题修复 & 功能扩展

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

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

lowerrocklabs/laravel-lockable

Composer 安装命令:

composer require lowerrocklabs/laravel-lockable

包简介

Laravel Lockable provides traits to allow for models to be locked

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This model allows for on-demand locking of models. You can integrate this with your permissions methodology of choice, or leave it stand-alone. This package allows you to determine whether a particular instance of a model is Locked or Not. Or it will independently prevent updating of a model instance.

Installation

Requires [PHP 7.3+ or 8.0+] and [Laravel 8.x or 9.x] (https://laravel.com/docs/8.x/releases or https://laravel.com/docs/9.x/releases)

You can install the package via composer:

composer require lowerrocklabs/laravel-lockable

You can publish and run the migrations with:

php artisan vendor:publish --tag="laravel-lockable-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="laravel-lockable-config"

This is the contents of the published config file, which controls the global lock duration, this is customisable on a per-model basis (see below).

return [
    // Name of the Table containing the locks
    'locks_table' => 'model_locks',
    
     // Name of the Table containing the lock watchers
    'lock_watchers_table' => 'model_lock_watchers',
    
    // Enable retrieval of lock status on retrieving a model
    'get_locked_on_retrieve' => true,
    
    // Prevent updating if a model is locked by another user
    'prevent_updating' => true,

    // Time in Seconds For Lock To Persist
    'duration' => '3600',
];

Usage

Model Configuration

In the Model(s) that you wish to be lockable, add the IsLockable Trait

use LowerRockLabs\Lockable\Traits\IsLockable;

and then set the Trait

use IsLockable;

In Your Component/Controller

Then use the acquireLock function to attempt to acquire a lock on the model, it will return false if there is an existing lock.

acquireLock()

You can override the existing lock by calling the releaseLock() function before acquireLock(), if you are using a permissions-based approach, it is suggested that you restrict this to approriate users.

releaseLock()

You can tell if a lock exists as follows, this will acquire the lock if one does not exist.

isLocked()

You can send a Broadcast to the user holding the lock with the following

requestLock()

Lock Duration

You can override the default Lock Duration (in seconds) which is taken from the configuration on a per-model basis by setting the following in your Model, for example, the following would limit the duration of a lock to 600 seconds.

public $modelLockDuration = "600";

Locks will clear when the Duration has expired, and an attempt is made to access the Model, or you can call the commands below, or add them to a schedule (as you see fit).

Commands

To Flush Expired Locks

php artisan locks:flushexpired

To Flush All Locks

php artisan locks:flushall

Events

Two Events will be fired during the Lock process, that can be used to fire Notifications or Logs if desired On Model Locking

LowerRockLabs\Lockable\Events\ModelWasLocked;

and On Model UnLocking

LowerRockLabs\Lockable\Events\ModelWasUnLocked;

An additional event will be fired when a user requests the release of the lock and On Model UnLocking

LowerRockLabs\Lockable\Events\ModelUnlockRequested;

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

lowerrocklabs/laravel-lockable 适用场景与选型建议

lowerrocklabs/laravel-lockable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 304 次下载、GitHub Stars 达 8, 最近一次更新时间为 2022 年 10 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「LowerRockLabs」 「laravel-lockable」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 lowerrocklabs/laravel-lockable 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 304
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-02