Skip to content

Latest commit

 

History

History
56 lines (44 loc) · 1.18 KB

README.md

File metadata and controls

56 lines (44 loc) · 1.18 KB

sic-bundle

Single Instance Console Command Bundle

provides the ability to ban more than one command instance

add bundle in bundles.php

return [
   ...
   GepurIt\SingleInstanceCommandBundle\SingleInstanceCommandBundle::class => ['all' => true],
   ...
];

to mark command as single instance, add interface to your command, and add method getLockName()

class MyCommand extends Command implements SingleInstanceInterface {
    ...
    
    /**
     * get`s lock name for command execution, based on input
     * @param InputInterface $input
     * @return string
     */
    public function getLockName(InputInterface $input): string
    {
        return $this->getName();
    }
    
    ...
}

to allow to run the same command with different args, use $input in getLockName() method


class MyCommand extends Command implements SingleInstanceInterface {
    ...
    
    /**
     * get`s lock name for command execution, based on input
     * @param InputInterface $input
     * @return string
     */
    public function getLockName(InputInterface $input): string
    {
        return $this->getName().':'.$input->getArgument('myArg');
    }
    
    ...
}