From b82f2c74d1fdb0e0aaaa4c93a2a904e376b310a2 Mon Sep 17 00:00:00 2001 From: Fbenas Date: Sun, 7 Jun 2020 02:59:59 +0100 Subject: First pass at a php IRC helperfor I/O handling --- .gitignore | 2 ++ composer.json | 22 +++++++++++++ src/Application.php | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/Command.php | 21 ++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 .gitignore create mode 100644 composer.json create mode 100644 src/Application.php create mode 100644 src/Command.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d1502b0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +vendor/ +composer.lock diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..0c689db --- /dev/null +++ b/composer.json @@ -0,0 +1,22 @@ +{ + "name": "fbeans/blairc", + "type": "library", + "description": "Symfony Filesystem Component", + "keywords": [], + "version": "0.1", + "authors": [ + { + "name": "Fbenas", + "email": "phil@pgburton.com" + } + ], + "require": { + "symfony/console": "^5.2" + }, + "autoload": { + "psr-4": { + "FBeans\\BlaIRC\\": "src/" + } + }, + "minimum-stability": "dev" +} diff --git a/src/Application.php b/src/Application.php new file mode 100644 index 0000000..88843ac --- /dev/null +++ b/src/Application.php @@ -0,0 +1,95 @@ +setInput(new ArgvInput()); + } + + public function fromStdin() + { + return $this->setInput(new ArrayInput($this->readStdin())); + } + + public function toConsole() + { + return $this->setOutput(new ConsoleOutput); + } + + public function toIRC() + { + return null; + } + + public function __construct(InputInterface $input = null, OutputInterface $output = null) + { + $this->setInput($input)->setOutput($output); + } + + public function setInput(InputInterface $input = null) + { + $this->input = $input; + + return $this; + } + + public function setOutput(OutputInterface $output = null) + { + $this->output = $output; + + return $this; + } + + public function run() + { + $this->application = new SymfonyApplication(); + $command = $this->command(); + + $this->application->add($command); + $this->application->setDefaultCommand($command->getName()); + $this->application->run($this->input, $this->output); + } + + protected function readStdin() + { + $stream = fopen("php://stdin", "r"); + $input_string = fgets($stream, 128); + $input_string = rtrim($input_string); + + $input_array = explode(' ', $input_string); + + fclose($stream); + + return $input_array; + } +} diff --git a/src/Command.php b/src/Command.php new file mode 100644 index 0000000..6fb3770 --- /dev/null +++ b/src/Command.php @@ -0,0 +1,21 @@ +execute_callback, $input, $output); + } + + public function setExecuteCallback(Closure $callable) + { + $this->execute_callback = $callable; + } +} -- cgit v1.2.3