PHPackages                             notamedia/yii2-locker - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. notamedia/yii2-locker

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

notamedia/yii2-locker
=====================

Yii2 Locker Extension

1.0.0-beta(8y ago)21141MITPHPPHP &gt;=5.6.0

Since Jul 28Pushed 8y ago3 watchersCompare

[ Source](https://github.com/notamedia/yii2-locker)[ Packagist](https://packagist.org/packages/notamedia/yii2-locker)[ RSS](/packages/notamedia-yii2-locker/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (2)Dependencies (5)Versions (3)Used By (0)

Yii2 Locker Extension
=====================

[](#yii2-locker-extension)

Extension includes following features:

- Activate/Deactivate resource lock by unique identifier.
- Check and block request if exists active lock.

For license information check the [LICENSE](LICENSE.md)-file.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist notamedia/yii2-locker

```

or add

```
"notamedia/yii2-locker": "1.0.0"

```

to the require section of your composer.json.

Configuration
-------------

[](#configuration)

To use this extension, simply add the following code in your application configuration:

```
return [
    //....
    'components' => [
        //....
        'lockManager' => [
            'class' => LockManager::class,
            'lockTime' => [
                LockManager::DEFAULT_LOCK_TIME_KEY => 900,
            ]
        ],
        //....
    ],
    //....
];
```

- Note: you may set custom time for each resource, simple add to `lockTime`, key - resource class and value - time in seconds
- Note: if your db driver non mysql, you need set custom `'initTimeExpressionValue' = '...'` and `'diffExpressionValue' = '...'`
- Note: if you want to use custom lock class, you need set new `LockInterface::class` definitions like

```
'container' => [
    '...',
    'definitions' => [
        '...',
        LockInterface::class => Lock::class
        '...'
    ],
    '...'
]

```

connect following actions in your controllers and configure routing

```
return [
    //....
    'lock' => [
        'class' => LockAction::class,
        'modelClass' => $this->modelClass,
        'checkAccess' => [$this, 'checkAccess']
    ],
    'unlock' => [
        'class' => UnlockAction::class,
        'modelClass' => $this->modelClass,
        'checkAccess' => [$this, 'checkAccess'],
    ],
    //....
];
```

- Note: you may set `'lockManager' = '...'` attribute if your LockManager component has other key

attach behavior to check lock, or you can check by yourself

```
return [
    //....
    [
        'class' => LockControlFilter::class,
        'only' => ['update']
    ],
    //....
];
```

- Note: you may set `'lockManager' = '...'` attribute if your LockManager component has other key

connect and execute [migration](/src/migrations/m000000_000000_create_table_lock.php), example:

For yii2 &gt; 2.0.10

```
'controllerMap' => [
    //...
    'migrate' => [
        'class' => MigrateController::class,
        'migrationNamespaces' => [
            'notamedia\locker\migrations',
        ],
        //...
    ],
    //...
 ]
```

For yii2 &lt; 2.0.10 create new migration and use extends

```
class mxxxxxx_xxxxxx_create_table_lock extends m000000_000000_create_table_lock
```

Usage
-----

[](#usage)

Methods:

- `LockAction` - activates lock and returns `204` status code if successful
- `UnlockAction` - deactivates lock and returns `204` status code if successful

Exceptions
----------

[](#exceptions)

- `LockAnotherUserException` - exception if lock set another user, status code `500`
- `LockNotExistException` - exception if lock not exist, status code `500`
- `LockNotExpiredException` - exception if lock actual and its time not expired, status code `500`

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 57.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~151 days

Total

2

Last Release

3107d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f4ee0f9569dfa9de7a91997c66a30781937442876adceff9dd1ec0065262de8c?d=identicon)[Nik Samokhvalov](/maintainers/Nik%20Samokhvalov)

---

Top Contributors

[![niksamokhvalov](https://avatars.githubusercontent.com/u/8028275?v=4)](https://github.com/niksamokhvalov "niksamokhvalov (8 commits)")[![xeurun](https://avatars.githubusercontent.com/u/1073935?v=4)](https://github.com/xeurun "xeurun (6 commits)")

---

Tags

lockingrestfulyii2-extensionyii2locklocker

### Embed Badge

![Health badge](/badges/notamedia-yii2-locker/health.svg)

```
[![Health](https://phpackages.com/badges/notamedia-yii2-locker/health.svg)](https://phpackages.com/packages/notamedia-yii2-locker)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[dmstr/yii2-cookie-consent

Yii2 Cookie Consent Widget

1454.6k](/packages/dmstr-yii2-cookie-consent)[imanilchaudhari/yii2-currency-converter

This extension will help to find out current currency conversion rate.

1911.7k](/packages/imanilchaudhari-yii2-currency-converter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
