Portable advisory file locking

@param  int    $operation  Type of lock (LOCK_SH, LOCK_EX, or LOCK_UN)
@return self
@see https://php.net/manual/en/function.flock.php
778555
final protected function flock($operation = LOCK_EX)
	{
		if ($operation === LOCK_EX or $operation == LOCK_SH) {
			$this->flocked = true;
		} else {
			$this->flocked = false;
		}
	}
1230088
public function lock($lockType, $nonBlockingLock = false)
    {
        if ($nonBlockingLock) {
            return flock($this->_fileHandle, $lockType | LOCK_NB);
        } else {
            return flock($this->_fileHandle, $lockType);
        }
    }
1052643
protected function openAndLock($file, $mode, $operation)
    {
        if (!$handle = fopen($file, $mode)) {
            return false;
        }
        if (!flock($handle, $operation)) {
            fclose($handle);
            return false;
        }
        return $handle;
    }
548021
public function orOn($localKey, $operator, $referenceKey)
    {
        $this->on($localKey, $operator, $referenceKey, 'or'); return $this;
    }
657940
private function change(string $operation, int $value): \Generator
    {
        if (!$this->isOpen()) {
            throw new FileException('The file has been closed.');
        }

        try {
            return yield from $this->worker->enqueue(new Internal\FileTask($operation, [$this->path, $value]));
        } catch (TaskException $exception) {
            $this->close();
            throw new FileException(sprintf('%s failed.', $operation), $exception);
        }
    }
1339918
public function release()
    {
        if ($this->locked) {
            flock($this->fp, LOCK_UN);
            fclose($this->fp);

            $this->fp = null;
            $this->locked = false;
        }

        return $this;
    }
603746
public function logicalOperator($operator = null)
    {
        if (is_null($operator)) {
            return $this->logicalOperator;
        }

        Helpers::ensureValidLogicalOperator($operator);

        $this->logicalOperator = $operator;

        return $this;
    }
841790
public function setStackOperations(array $operations)
    {
        $this->stackOperations = [];
        foreach ($operations as $operation) {
            $this->addStackOperation($operation);
        }

        return $this;
    }
700614
public function setOperation(\CampaignChain\CoreBundle\Entity\Operation $operation = null)
    {
        $this->operation = $operation;

        $this->setStartDate($this->operation->getStartDate());

        return $this;
    }
1095430
function releaseMutex($filename) {
		$ret = flock($this->fplock[md5($filename)], LOCK_UN);
		fclose($this->fplock[md5($filename)]);
		unset($this->fplock[md5($filename)]);
		if (! $ret) {
			$this->debug("Not able to release lock for $filename");
		}
		return $ret;
	}
109130
public function addOperation(Operation $operation) {
        $operations = $this->getOperations();
        $operations[] = $operation;
        $this->setOperations($operations);
    }
920981
function release()
    {
        $lockRes = static::_getLocksDir("{$this->realm}.lockfile");

        if ( null === $file = $this->file )
            if (false === $file = fopen($lockRes, 'w+') )
                throw new \RuntimeException(sprintf(
                    'Failed To Open Resource (%s).'
                    , $lockRes
                ));


        ## Release Lock Res.
        #
        $this->file = null;

        if (! flock($file, LOCK_UN) )
            throw new \RuntimeException(sprintf(
                'FAILED to release lock[%s] on resource (%s).'
                , $this->realm
                , $lockRes
            ));


        fclose($file);
        unlink($lockRes);

        return true;
    }
503616
public function awaitOperation(Operation $operation, $interval = 5)
    {
        while ($operation->getState() == OperationState::InProgress) {
            $operation = $this->getOperation($operation);
            if ($operation->getState() == OperationState::InProgress) {
                sleep($interval);
            }
        }

        return $operation;
    }
421067
private function operationSftp($operation)
    {
        $config = $this->operationFtpConfig($operation);

        $adapter    = new SftpAdapter($config);
        $filesystem = new Filesystem($adapter);

        $written = false;
        if ($stream = fopen($this->file->getLocation(), 'r+')) {
            $this->setLogs($this->file->getLocation(), 'sftpUploading');
            $written = $filesystem->writeStream($this->file->getName(), $stream);
            if (is_resource($stream)) {
                fclose($stream);
            }
            $this->setLogs($written, 'sftpConfirmed');
            if (!$written) {
                $this->setLogs('Could not confirm file upload via SFTP', 'error');
            } else {
                $this->setLogs($filesystem->has($this->file->getName()), 'sftpConfirmed2');
            }
        } else {
            $this->setLogs('Unable to open file for upload via SFTP.', 'error');
        }

        return $written;
    }
918321
public function addOperation($operation)
    {
        if (!in_array($operation, $this->operations, true)) {
            $this->operations[] = $operation;
        }
    }
172023
public function stream_lock(int $operation): bool
    {
        if ((LOCK_NB & $operation) == LOCK_NB) {
            $operation = $operation - LOCK_NB;
        }

        return $this->content->lock($this, $operation);
    }
854855
public function addOperation(\CampaignChain\CoreBundle\Entity\Operation $operations)
    {
        $this->operations[] = $operations;

        return $this;
    }