2017 © Pedro Peláez
 

library request

Allow to get data both from HTTP requests (e.g. $_POST, $_GET) and CLI without changing code

image

lisennk/request

Allow to get data both from HTTP requests (e.g. $_POST, $_GET) and CLI without changing code

  • Sunday, October 16, 2016
  • by Lisennk
  • Repository
  • 1 Watchers
  • 1 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

:alien: Request

Latest Stable Version License Build Status, (*1)

One Request Class To Rule Them All., (*2)

Lisennk\Request allow to get data both from HTTP requests (e.g. $_POST, $_GET) and CLI without changing code. For exmaple, you have a script love.php. You can open it in your browser (e.g. http://localhost/love.php?name=Alice) or run via console (php love.php --name="Alice") — with Lisennk\Request you can read passed data, both ?name=Alice and --name="Alice" in the same way, just like this:, (*3)

echo Request::input('name'); // outputs "Alice"

:new_moon_with_face: Possibilities and usage

Following the example above, we can also:, (*4)

<?php

use Lisennk\Request;

$request = Request::instance();
echo $request->input('name'); // outputs "Alice"

Or you can do it like this:, (*5)

echo $request->name; // outputs "Alice"

You can use all methods like in Laravel Facades, via static call:, (*6)

echo Request::input('name'); // outputs "Alice"

You can use placeholder (i.e. default value) that will be returned if input doesnt exist:, (*7)

echo Request::input('name', 'Unknown Name'); // outputs "Unknown Name" if "name" doesnt passed
echo $request->input('name', 'Unknown Name'); // the same same, outputs "Unknown Name" if "name" doesnt passed

You can use has method to check if value exist:, (*8)

if (Request::has('name')) echo 'Name passed!'; // outputs "Name passed!" if there is value with "name" key

You can use second parameter of "has" method to check if value exist and that its equal to needed, (*9)

if ($request->has('name', 'Alice')) echo 'The name is Alice!'; // outputs "the name is Alice"
if (Request::has('name', 'Bob')) echo 'Bob is here!'; // we know that name is "Alice", not "Bob", so here we will not get any output

You can use notEmpty method to check if there is any data passed to the script, (*10)

if ($request->notEmpty()) echo 'There is something to work with!';

:squirrel: Installation

You can install it with Composer:, (*11)

composer require lisennk/request

:last_quarter_moon_with_face: Contributions

Feel free to create issues and pull requests. Please, star repository, if you like it., (*12)

The Versions

16/10 2016

dev-master

9999999-dev

Allow to get data both from HTTP requests (e.g. $_POST, $_GET) and CLI without changing code

  Sources   Download

MIT

The Development Requires

by serewann

cli http request getopts post get argv

15/10 2016

v1.0

1.0.0.0

  Sources   Download

MIT

The Development Requires

by serewann