PHP code example of adt / command-lock
1. Go to this page and download the library: Download adt/command-lock library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
adt / command-lock example snippets
namespace App\Commands;
use ADT\CommandLock\CommandLock;
use ADT\CommandLock\Storage\FileSystemStorage;
use Exception;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
abstract class Command extends \Symfony\Component\Console\Command\Command
{
use CommandLock;
private string $locksDir;
abstract protected function executeCommand(InputInterface $input, OutputInterface $output): int;
public function setLocksDir(string $locksDir)
{
$this->locksDir = $locksDir;
}
/**
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->setStorage(new FileSystemStorage($this->locksDir));
$this->lock();
$status = $this->executeCommand($input, $output);
$this->unlock();
return $status;
}
}