Skip to content

Commit 4857fc2

Browse files
committed
wip
0 parents  commit 4857fc2

File tree

7 files changed

+174
-0
lines changed

7 files changed

+174
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/tests export-ignore

.github/workflows/phpunit.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
6+
name: phpunit
7+
8+
jobs:
9+
phpunit:
10+
uses: spiral/gh-actions/.github/workflows/phpunit.yml@master
11+
with:
12+
os: >-
13+
['ubuntu-latest']
14+
php: >-
15+
['8.1', '8.2']
16+
stability: >-
17+
['prefer-stable']

.github/workflows/psalm.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
6+
name: static analysis
7+
8+
jobs:
9+
psalm:
10+
uses: spiral/gh-actions/.github/workflows/psalm.yml@master
11+
with:
12+
os: >-
13+
['ubuntu-latest']
14+
php: >-
15+
['8.1']

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# IDEA
2+
.idea/
3+
*.iml
4+
5+
# Composer
6+
composer.phar
7+
vendor
8+
composer.lock
9+
10+
# OS
11+
.DS_Store
12+
Thumbs.db
13+
*.exe
14+
15+
# Other
16+
.phpunit.result.cache
17+
.php_cs.cache
18+
clover.xml
19+
.env
20+
builds
21+

composer.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"name": "spiral/symfony-lock-driver",
3+
"type": "library",
4+
"description": "RoadRunner: HTTP and PSR-7 worker",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Pavel Buchnev (butschster)",
9+
"email": "pavel.buchnev@spiralscout.com"
10+
},
11+
{
12+
"name": "Alexander Strizhak",
13+
"email": "gam6itko@gmail.com"
14+
}
15+
],
16+
"homepage": "https://spiral.dev/",
17+
"support": {
18+
"docs": "https://roadrunner.dev/docs",
19+
"issues": "https://github.com/roadrunner-server/roadrunner/issues",
20+
"forum": "https://forum.roadrunner.dev/",
21+
"chat": "https://discord.gg/V6EK4he"
22+
},
23+
"require": {
24+
"php": ">=8.1",
25+
"roadrunner-php/lock": "^1.0",
26+
"symfony/lock": "^6.0"
27+
},
28+
"require-dev": {
29+
"phpunit/phpunit": "^10.0",
30+
"vimeo/psalm": "^5.9"
31+
},
32+
"autoload": {
33+
"psr-4": {
34+
"Spiral\\RoadRunner\\Symfony\\Lock\\": "src"
35+
}
36+
},
37+
"autoload-dev": {
38+
"psr-4": {
39+
"Spiral\\RoadRunner\\Symfony\\Lock\\Tests\\": "tests"
40+
}
41+
},
42+
"funding": [
43+
{
44+
"type": "github",
45+
"url": "https://github.com/sponsors/roadrunner-server"
46+
}
47+
],
48+
"scripts": {
49+
"analyze": "psalm"
50+
},
51+
"config": {
52+
"sort-packages": true
53+
},
54+
"minimum-stability": "dev",
55+
"prefer-stable": true,
56+
"extra": {
57+
"branch-alias": {
58+
"dev-main": "1.0-dev"
59+
}
60+
}
61+
}

src/RoadRunnerStore.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Spiral\RoadRunner\Symfony\Lock;
6+
7+
use RoadRunner\Lock\LockInterface as RrLockInterface;
8+
use Symfony\Component\Lock\Key;
9+
use Symfony\Component\Lock\PersistingStoreInterface;
10+
use Symfony\Component\Lock\SharedLockStoreInterface;
11+
12+
final class RoadRunnerStore implements SharedLockStoreInterface
13+
{
14+
private string $processId;
15+
16+
public function __construct(
17+
private readonly RrLockInterface $rrLock,
18+
?string $processId = null
19+
) {
20+
$this->processId = $processId ?? '*';
21+
}
22+
23+
public function save(Key $key): void
24+
{
25+
$this->rrLock->lock((string) $key, $this->processId);
26+
}
27+
28+
public function exists(Key $key): bool
29+
{
30+
return $this->rrLock->exists((string) $key, $this->processId);
31+
}
32+
33+
public function putOffExpiration(Key $key, float $ttl): void
34+
{
35+
$this->rrLock->updateTTL((string) $key, $this->processId, $ttl);
36+
}
37+
38+
public function delete(Key $key): void
39+
{
40+
$this->rrLock->forceRelease((string) $key);
41+
}
42+
43+
public function saveRead(Key $key): void
44+
{
45+
$this->rrLock->lockRead((string) $key, $this->processId);
46+
}
47+
}

tests/RoadRunnerStoreTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Spiral\RoadRunner\Symfony\Lock;
6+
7+
use PHPUnit\Framework\TestCase;
8+
9+
final class RoadRunnerStoreTest extends TestCase
10+
{
11+
12+
}

0 commit comments

Comments
 (0)