PHP code example of circli / console

1. Go to this page and download the library: Download circli/console 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/ */

    

circli / console example snippets



class ExampleCommandDefinition extends \Circli\Console\Definition
{
    protected function configure(): void
    {
        $this->setName('example:command');
        $this->setCommand(function($input, $output) {
            return 0;
        });
    }
}

$application = new Application();
$application->addDefinition(new ExampleCommandDefinition());

$application->run();

class ExampleInput extends \Circli\Console\AbstractInput
{
    public function getFrom(): \DateTimeInterface
    {
        $rawDate = $this->getArgument('from') ?: 'now';
        
        return new \DateTimeImmutable($rawDate);
    }
}

class ExampleCommandDefinition extends \Circli\Console\Definition
{
    protected function configure(): void
    {
        $this->setName('example:command');
        $this->addArgument('from', InputArgument::REQUIRED);
        $this->setCommand(function(ExampleInput $input, $output) {
            $from = $input->getFrom();
            return 0;
        });
    }
    
    public function transformInput(InputInterface $input, OutputInterface $output): InputInterface
    {
        return new ExampleInput();
    }

}

use Circli\Console\Application;
use Circli\Console\ContainerCommandResolver;
use Circli\Console\Definition;

$application = new Application(new ContainerCommandResolver($psr11container));
$application->addDefinition(new class extends Definition {
    protected function configure(): void
    {
        $this->setName('example:command');
        $this->setCommand('keyInContainer');
    }
});
$application->run();

use Symfony\Component\Console\Application;
use Circli\Console\Command;

$application = new Application();
$application->add(new \Circli\Console\Command(new CmdDefinition()));
$application->run();