z0s / console
Simple console framework to quickly create command line PHP scripts
1.0.2
2022-10-17 14:55 UTC
Requires
- php: >=8.0
- kcs/class-finder: dev-master
- psr/container: ^2.0
- symfony/console: ^6.0
Requires (Dev)
- roave/security-advisories: dev-latest
This package is not auto-updated.
Last update: 2024-11-10 21:51:39 UTC
README
Installation
You can include it in your project using: composer require z0s/console
Requirements
- PSR-11 compatible container
- PHP8.0 or higher
bin/console example
<?php
$autoloaderPath = __DIR__ . '/../vendor/autoload.php';
if(!file_exists($autoloaderPath)) {
throw new RuntimeException('Error, composer is not setup correctly.. Please run composer install');
}
$autoloader = require $autoloaderPath;
# Container
$container = new \League\Container\Container();
# Autowiring
$container->delegate(new \League\Container\ReflectionContainer());
# Load the CLI
$cli = new \z0s\Console\Console($container, $autoloader);
# Define the class scope to load commands from
$cli->setCommandsNamespace('z0s\\Commands');
# Define the name
$cli->setConsoleName('z0s');
# Define the version
$cli->setVersion('0.0.1');
# Run the cli
$cli->run();
Command example
<?php
namespace z0s\Commands;
/**
* @property string $stringInput
*/
class Command extends \z0s\Console\ConsoleCommand
{
protected string $signature = 'command {--stringInput=Hello World : Some string to pass into the command }';
protected string $description = 'This is an example command';
public function handle(): void
{
$this->out($this->stringInput);
}
}