Skip to content

Commit 6c77c3d

Browse files
committed
Merge pull request #10 from mathroc/feature/cleanup-identifier
remove $identifier from LockFile
2 parents df56788 + 7277deb commit 6c77c3d

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

spec/TH/Lock/FileLockSpec.php

+3-3
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, true);
84+
$this->beConstructedWith($this->lock_file, FileLock::EXCLUSIVE, FileLock::NON_BLOCKING, 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, true);
96+
$this->beConstructedWith($this->lock_file, FileLock::SHARED, FileLock::NON_BLOCKING, 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, true);
111+
$this->beConstructedWith($this->lock_file, FileLock::EXCLUSIVE, FileLock::NON_BLOCKING, true);
112112

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

src/FileFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function create(
4545

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

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

5050
return $lock;
5151
}

src/FileLock.php

+5-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class FileLock implements Lock
1717
private $lock_file;
1818
private $exclusive;
1919
private $blocking;
20-
private $identifier;
2120
private $fh;
2221
private $remove_on_release;
2322

@@ -28,22 +27,19 @@ class FileLock implements Lock
2827
* @param boolean $exclusive true for an exclusive lock, false for shared one
2928
* @param boolean $blocking true to wait for lock to be available,
3029
* false to throw exception instead of waiting
31-
* @param string|null $identifier resource identifier (default to $lock_file) for logging
3230
* @param boolean $remove_on_release remove file on release if no other lock remains
3331
* @param LoggerInterface $logger
3432
*/
3533
public function __construct(
3634
$lock_file,
3735
$exclusive = FileLock::EXCLUSIVE,
3836
$blocking = FileLock::NON_BLOCKING,
39-
$identifier = null,
4037
$remove_on_release = false,
4138
LoggerInterface $logger = null
4239
) {
4340
$this->lock_file = $lock_file;
4441
$this->exclusive = $exclusive;
4542
$this->blocking = $blocking;
46-
$this->identifier = $identifier?:$lock_file;
4743
$this->remove_on_release = $remove_on_release;
4844

4945
$this->logger = $logger ?: new NullLogger;
@@ -79,20 +75,20 @@ public function acquire()
7975
private function tryAcquire($operation, $lock_type)
8076
{
8177
$log_data = [
82-
'identifier' => $this->identifier,
78+
'lock_file' => $this->lock_file,
8379
'lock_type' => $lock_type
8480
];
8581

8682
if (!$this->flock($operation)) {
87-
$this->logger->debug('could not acquire {lock_type} lock on {identifier}', $log_data);
83+
$this->logger->debug('could not acquire {lock_type} lock on {lock_file}', $log_data);
8884

8985
throw new Exception(
90-
'Could not acquire '.$lock_type.' lock on '.$this->identifier
86+
'Could not acquire '.$lock_type.' lock on '.$this->lock_file
9187
);
9288

9389
}
9490

95-
$this->logger->debug('{lock_type} lock acquired on {identifier}', $log_data);
91+
$this->logger->debug('{lock_type} lock acquired on {lock_file}', $log_data);
9692
}
9793

9894
public function release()
@@ -109,7 +105,7 @@ public function release()
109105
fclose($this->fh);
110106
$this->fh = null;
111107

112-
$this->logger->debug('{lock_type} lock released on {identifier}', ['identifier' => $this->identifier]);
108+
$this->logger->debug('{lock_type} lock released on {lock_file}', ['lock_file' => $this->lock_file]);
113109
}
114110

115111
public function __destruct()

0 commit comments

Comments
 (0)