Skip to content

Commit df56788

Browse files
committed
Merge pull request #9 from mathroc/feature/cleanup-owner
remove $owner, that would be better handled at the logger level
2 parents f283dff + 47bbd05 commit df56788

File tree

4 files changed

+8
-18
lines changed

4 files changed

+8
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ There are two methods you can use on a `FileLock`:
122122

123123
And one on a `FileFactory`:
124124

125-
* `\TH\Lock\FileFactory::create($resource, $owner = null, $exclusive = FileLock::EXCLUSIVE, $blocking = FileLock::NON_BLOCKING)` used to create a `FileLock` for `$resource`
125+
* `\TH\Lock\FileFactory::create($resource, $exclusive = FileLock::EXCLUSIVE, $blocking = FileLock::NON_BLOCKING)` used to create a `FileLock` for `$resource`
126126

127127
## Notes
128128

spec/TH/Lock/FileLockSpec.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function it_should_throw_if_it_cannot_lock()
8181

8282
public function it_remove_its_lock_file_if_not_locked()
8383
{
84-
$this->beConstructedWith($this->lock_file, FileLock::EXCLUSIVE, FileLock::NON_BLOCKING, null, null, true);
84+
$this->beConstructedWith($this->lock_file, FileLock::EXCLUSIVE, FileLock::NON_BLOCKING, null, true);
8585

8686
$this->acquire();
8787
$this->release();
@@ -93,7 +93,7 @@ public function it_remove_its_lock_file_if_not_locked()
9393

9494
public function it_does_not_remove_its_lock_file_if_still_locked()
9595
{
96-
$this->beConstructedWith($this->lock_file, FileLock::SHARED, FileLock::NON_BLOCKING, null, null, true);
96+
$this->beConstructedWith($this->lock_file, FileLock::SHARED, FileLock::NON_BLOCKING, null, true);
9797

9898
touch($this->lock_file);
9999
flock(fopen($this->lock_file, 'r'), LOCK_SH|LOCK_NB);
@@ -108,7 +108,7 @@ public function it_does_not_remove_its_lock_file_if_still_locked()
108108

109109
public function it_can_acquire_then_release_and_acquire_again()
110110
{
111-
$this->beConstructedWith($this->lock_file, FileLock::EXCLUSIVE, FileLock::NON_BLOCKING, null, null, true);
111+
$this->beConstructedWith($this->lock_file, FileLock::EXCLUSIVE, FileLock::NON_BLOCKING, null, true);
112112

113113
$this->acquire();
114114
$this->release();

src/FileFactory.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@ public function __construct($lock_dir, $hash_algo = 'sha256', LoggerInterface $l
3030
/**
3131
* Create a FileLock for $resource
3232
* @param string $resource resource identifier
33-
* @param string|null $owner owner name (for logging)
3433
* @param boolean $exclusive true for an exclusive lock, false for shared one
3534
* @param boolean $blocking true to wait for lock to be available, false to throw exception instead of waiting
3635
* @return FileLock
3736
*/
3837
public function create(
3938
$resource,
40-
$owner = null,
4139
$exclusive = FileLock::EXCLUSIVE,
4240
$blocking = FileLock::NON_BLOCKING
4341
) {
@@ -47,7 +45,7 @@ public function create(
4745

4846
$path = $this->lock_dir.'/'.hash($this->hash_algo, serialize($resource)).'.lock';
4947

50-
$lock = new FileLock($path, $exclusive, $blocking, $resource, $owner, true, $this->logger);
48+
$lock = new FileLock($path, $exclusive, $blocking, $resource, true, $this->logger);
5149

5250
return $lock;
5351
}

src/FileLock.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class FileLock implements Lock
1818
private $exclusive;
1919
private $blocking;
2020
private $identifier;
21-
private $owner;
2221
private $fh;
2322
private $remove_on_release;
2423

@@ -30,7 +29,6 @@ class FileLock implements Lock
3029
* @param boolean $blocking true to wait for lock to be available,
3130
* false to throw exception instead of waiting
3231
* @param string|null $identifier resource identifier (default to $lock_file) for logging
33-
* @param string|null $owner owner name for logging
3432
* @param boolean $remove_on_release remove file on release if no other lock remains
3533
* @param LoggerInterface $logger
3634
*/
@@ -39,15 +37,13 @@ public function __construct(
3937
$exclusive = FileLock::EXCLUSIVE,
4038
$blocking = FileLock::NON_BLOCKING,
4139
$identifier = null,
42-
$owner = null,
4340
$remove_on_release = false,
4441
LoggerInterface $logger = null
4542
) {
4643
$this->lock_file = $lock_file;
4744
$this->exclusive = $exclusive;
4845
$this->blocking = $blocking;
4946
$this->identifier = $identifier?:$lock_file;
50-
$this->owner = $owner === null ? '' : $owner.': ';
5147
$this->remove_on_release = $remove_on_release;
5248

5349
$this->logger = $logger ?: new NullLogger;
@@ -84,20 +80,19 @@ private function tryAcquire($operation, $lock_type)
8480
{
8581
$log_data = [
8682
'identifier' => $this->identifier,
87-
'owner' => $this->owner,
8883
'lock_type' => $lock_type
8984
];
9085

9186
if (!$this->flock($operation)) {
92-
$this->logger->debug('{owner} could not acquire {lock_type} lock on {identifier}', $log_data);
87+
$this->logger->debug('could not acquire {lock_type} lock on {identifier}', $log_data);
9388

9489
throw new Exception(
9590
'Could not acquire '.$lock_type.' lock on '.$this->identifier
9691
);
9792

9893
}
9994

100-
$this->logger->debug('{owner} {lock_type} lock acquired on {identifier}', $log_data);
95+
$this->logger->debug('{lock_type} lock acquired on {identifier}', $log_data);
10196
}
10297

10398
public function release()
@@ -114,10 +109,7 @@ public function release()
114109
fclose($this->fh);
115110
$this->fh = null;
116111

117-
$this->logger->debug('{owner} lock released on {identifier}', [
118-
'identifier' => $this->identifier,
119-
'owner' => $this->owner
120-
]);
112+
$this->logger->debug('{lock_type} lock released on {identifier}', ['identifier' => $this->identifier]);
121113
}
122114

123115
public function __destruct()

0 commit comments

Comments
 (0)