nia/requestresponse-cli

Implementation of the request response pattern for the CLI environment.

This package's canonical repository appears to be gone and the package has been frozen as a result.

1.0.1 2016-09-24 09:52 UTC

This package is not auto-updated.

Last update: 2022-03-09 06:48:57 UTC


README

Implementation of the request response pattern for the CLI environment. This implementation does not support an interactive mode nor the stdin.

Installation

Require this package with Composer.

	composer require nia/requestresponse-cli

Tests

To run the unit test use the following command:

$ cd /path/to/nia/component/
$ phpunit --bootstrap=vendor/autoload.php tests/

How to use

The following sample shows you how to use the CLI request response component for a CLI script. For routing and presenting the nia/routing and nia/presenter component can be used.

	#! /usr/bin/php
	<?php
	// file: bin/cli

	use Nia\RequestResponse\Cli\CliRequest;
	use Nia\RequestResponse\Cli\CliResponse;

	require_once __DIR__ . '/../vendor/autoload.php';

	// create the request.
	$request = new CliRequest($_SERVER['argv'], STDIN);

	// [...]
	//
	//  routing:
	//      [...]
	//  controller/presenter:
	//      $response = $request->createResponse();
	//      $response->set<XYZ>(...);
	//
	// [...]

	// send the response.
	echo $response->getContent();
	exit ($response->getStatusCode());