PHP code example of webservco / command
1. Go to this page and download the library: Download webservco/command 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/ */
webservco / command example snippets
use WebServCo\Command\Contract\CommandRunnerInterface;
use WebServCo\Command\Contract\OutputInterface;
use WebServCo\Command\Service\OptionsParser;
final class ExampleCommand implements CommandRunnerInterface
{
public function __construct(private OutputInterface $output)
{
}
public function run(): bool
{
// php bin/import --file=data.csv --dry-run
$optionsParser = new OptionsParser(['file:', 'dry-run']);
$file = $optionsParser->getStringValue('file');
$isDryRun = $optionsParser->getBoolValue('dry-run');
// Prints the line and writes it to the log at debug level.
$this->output->write(sprintf('Demonstrating %s', $file));
return true;
}
}
use WebServCo\Command\Factory\OutputServiceFactory;
$outputFactory = new OutputServiceFactory();
// \WebServCo\Command\Contract\OutputInterface
$output = $outputFactory->createOutputService($logger);