コード例 #1
0
ファイル: LockFileTest.php プロジェクト: gielfeldt/lock
 public function testFileCreation()
 {
     $service = new Lock\LockService(['storage' => new Lock\Storage\File($this->path . '/does/not/exist')]);
     $lock1 = $service->acquire('lock1');
     $this->assertFalse($lock1 instanceof Lock\LockItemInterface);
 }
コード例 #2
0
ファイル: lock.php プロジェクト: gielfeldt/lock
<?php

namespace Gielfeldt\Lock\Example;

require 'vendor/autoload.php';
use Gielfeldt\Lock;
$lockService = new Lock\LockService(['storage' => new Lock\Storage\Memory()]);
print "'mylock' is locked: " . $lockService->isLocked('mylock') . "\n";
print "Locking 'mylock'\n";
$lock = $lockService->acquire('mylock');
print "'mylock' is locked: " . $lockService->isLocked('mylock') . "\n";
$lock->bind('release', function ($lock) {
    print "RELEASE EVENT 2: " . $lock->getName() . "\n";
});
$lock->release();
print "'mylock' is locked: " . $lockService->isLocked('mylock') . "\n";
コード例 #3
0
ファイル: lock2.php プロジェクト: gielfeldt/lock
<?php

namespace Gielfeldt\Lock\Example;

require 'vendor/autoload.php';
use Gielfeldt\Lock;
$lockService = new Lock\LockService(['storage' => new Lock\Storage\Memory()]);
$lock1 = $lockService->acquire('mylock');
$lock2 = $lockService->acquire('mylock');
$lock3 = $lockService->acquire('mylock2');
$lock1->setAutoRelease(false);
$lock2->setAutoRelease(false);
#$lock3->setAutoRelease(false);
$lock1->bind('release', function ($lock) {
    print "RELEASE EVENT 1: " . $lock->getName() . "( " . $lock->getIdentifier() . ")\n";
});
$lock2->bind('release', function ($lock) {
    print "RELEASE EVENT 2: " . $lock->getName() . "( " . $lock->getIdentifier() . ")\n";
});
$lock3->bind('release', function ($lock) {
    print "RELEASE EVENT 3: " . $lock->getName() . "( " . $lock->getIdentifier() . ")\n";
});
#$lock1->release();
#$lock2->release();
#$lock3->release();