for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @author stev leibelt <[email protected]>
* @since 2013-07-01
*/
namespace Net\Bazzline\Component\Lock;
use InvalidArgumentException;
use RuntimeException;
* Class RuntimeLock
*
* @package Net\Bazzline\Component\Lock
class RuntimeLock implements LockInterface
{
/** @var string */
private $name;
/** @var boolean */
private $isLocked;
* @param string $name
* @throws InvalidArgumentException
public function __construct($name = '')
if (strlen($name) > 0) {
$this->setResource($name);
}
* @return bool
public function isLocked()
return ((!is_null($this->isLocked)) && ($this->isLocked == true));
===
When comparing two booleans, it is generally considered safer to use the strict comparison operator.
* @throws \RuntimeException
public function acquire()
if ($this->isLocked()) {
throw new RuntimeException(
'Can not acquire lock, lock already exists.'
);
$this->isLocked = true;
public function release()
if (!$this->isLocked()) {
'Can not release lock, no lock exists.'
$this->isLocked = false;
* @return mixed|string
public function getResource()
return (is_null($this->name)) ? str_replace('\\', '_', get_class($this)) : $this->name;
* @param mixed|string $resource
public function setResource($resource)
$this->name = (string) $resource;
When comparing two booleans, it is generally considered safer to use the strict comparison operator.