PHP code example of phpgt / cli

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

    

phpgt / cli example snippets


$app = new Application(
	"Twitter example application",
	new CliArgumentList(...$argv),
	new TweetCommand(),
	new ViewCommand(),
	new FollowCommand(),
	new DmCommand(),
	new LoginCommand()
);
$app->run();

class TweetCommand extends Command {
	public function __construct() {
		$this->setName("tweet");
		$this->setDescription("Send a Tweet to your timeline.");

		$this->setRequiredParameter(true, "message", "m");
		$this->setOptionalParameter(true, "location", "l");
	}

	public function run(?ArgumentValueList $arguments = null):int {
		if(!TwitterApi::isLoggedIn()) {
			$this->writeLine("You must login first.", StreamName::ERROR);
			return 1;
		}
		
		try {
			$uri = TwitterApi::sendTweet($arguments->get("message"));
			$this->writeLine("Sent! View online: $uri");
		}
			catch(TwitterApiException $exception) {
				$this->writeLine(
					"Error sending Tweet: "
					. $exception->getMessage(),
					StreamName::ERROR
				);
				return 2;
			}

			return 0;
	}
}

$this->output("some text", Palette::GREEN); // single green message, resets afterwards
$this->setOutputPalette(Palette::RED, Palette::BLACK); // set default fg/bg
$this->output("all output now uses the default palette");
$this->resetOutputPalette(); // reset to terminal default