Pharaoh HTTP: Get and set the values of the current HTTP request

Recommend this page to a friend!
  Info   Documentation   View files (11)   Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2019-10-25 (9 months ago) Not yet rated by the usersTotal: 44 All time: 9,870 This week: 242
Version License PHP version Categories
pharaoh-http 1.0Custom (specified...5HTTP, PHP 5
Description Author

This class can get and set the values of the current HTTP request.

It provides classes that allow getting the values of the current HTTP request values like HTTP method, parameters, client details, etc..

The package can also provide classes that can also set or get the values of the current HTTP response like HTTP response status, response headers and body data, etc..

Picture of Moamen Eltouny
  Performance   Level  
Name: Moamen Eltouny <contact>
Classes: 11 packages by
Country: Egypt Egypt
Innovation award
Innovation award
Nominee: 5x

Details

[PHP] Pharaoh HTTP

Latest Stable Version Total Downloads License

Pharaoh-HTTP provides a quick and easy controlling of Request and Response.

Install

Install the latest version using Composer:

$ composer require raggitech/pharaoh-http

the include the vendor autoload file.

Usage

Getting the Instances:

$request = \RaggiTech\Http\Request::getInstance();
$response = \RaggiTech\Http\Response::getInstance();

Request

<a name="method"></a>

method

Get the request's method:

echo $request->method; //GET or POST or PUT or PATCH or DELETE

<a name="status"></a>

status

Get the request's status code:

echo $request->status; //200

<a name="secured"></a>

secured

Is it a secured request (HTTPS) (Returns Boolean) :

echo $request->secured; //true

<a name="time"></a>

time

Get the request's time :

echo $request->time; //float

//OR int
echo (int)$request->time;

<a name="headers"></a>

headers

Get the header value of a given key:

echo $request->headers->host; //localhost

<a name="server"></a>

server

Get the server value of a given key:

echo $request->server->http_host; //localhost

<a name="url"></a>

url

echo $request->current(); // localhost/pharaoh/http/?name=Raggi

// get current url with scheme
echo $request->current(true); // http://localhost/pharaoh/http/?name=Raggi

// get the base url
echo $request->base(); // http://localhost

// get the route url
echo $request->forRoute(); // localhost/pharaoh/http

?

<a name="files"></a>

files (uploaded files)

// for example the file input is FN.

########################################
# File Object
########################################
// single file
$file = $request->file('FN');
// OR
$file = $request->files->FN;

// Multi files (name, index)
$file = $request->file('FN', 1);
// OR 
$file = $request->files->FN[1];

########################################
# File Properties
########################################

echo $file->name; // name
echo $file->extension; // extension
echo $file->type; // mime type
echo $file->path; // current path
echo $file->error; // error code

########################################
# File Methods
########################################

// get full name with extension
echo $file->fullName(); // image.jpg

// check if the file has no error
echo $file->isValid(); // true

// get readable size of the file
echo $file->readableSize(); // 2MB

// save uploaded file to path
$file->save('path'); // true

// or save uploaded file to path with a new name
$file->save('path', 'file.jpg'); // true

<a name="isMethod"></a>

isMethod()

Check if the request method is equal to the given method name:

echo $request->isMethod('PUT') // false

<a name="isGet"></a>

isGet()

Check if it is a GET request:

echo $request->isGet() // true

<a name="isPost"></a>

isPost()

Check if it is a POST request:

echo $request->isPost() // false

<a name="isPut"></a>

isPut()

Check if it is a PUT request:

echo $request->isPut() // false

<a name="isPatch"></a>

isPatch()

Check if it is a PATCH request:

echo $request->isPatch() // false

<a name="isDelete"></a>

isDelete()

Check if it is a DELETE request:

echo $request->isDelete() // false

<a name="isAjax"></a>

isAjax()

Check if it is a XML Http Request:

echo $request->isAjax() // false

<a name="query"></a>

query()

Get a query value/values using DotArray:

// localhost/pharaoh/http/?name=Raggi
echo $request->query('name') // Raggi

<a name="input"></a>

input()

Get a post value/values using DotArray:

echo $request->input('full_name') // Moamen Eltouny

<a name="hasQuery"></a>

hasQuery()

Check if the request has the given query key using DotArray:

echo $request->hasQuery('full_name') // false

<a name="hasInput"></a>

hasInput()

Check if the request has the given input key using DotArray:

echo $request->hasInput('full_name') // true

<a name="client"></a>

client

$client = $request->client;

##############################
# Bot
##############################
// check if it's a bot
var_dump($client->isBot());

// get the bot's name
echo $client->bot();

##############################
# Main Information
##############################

// get user agent
echo $client->agent;

// get user ip
echo $client->ip;

// get referer
echo $client->referer;

// get user languages list
echo $client->languages;

// get user language
echo $client->language;

// get user language's variant
echo $client->variant;

##############################
# Device
##############################
$device = $client->device;

// Browser Engine name
echo $device->name; // WebKit

// Browser (name, version)
echo $device->browser->name; // Chrome
echo $device->browser->version; // 77.0.3865.120

// Platform (name, version)
echo $device->platform->name; // Windows
echo $device->platform->version; // 10.0


// Device Type
var_dump($device->isDesktop); // true

// if it's a phone
if($device->isPhone){
    var_dump(
        $device->isMobile, // true
        $device->isTablet, // false
        
        $device->isiOS, // true
        $device->isAndroid, // false
    );
}

Response

<a name="status"></a>

status()

Get/Set the response's status code:

echo $response->status(); //200

$response->status(404);
echo $response->status(); //404

<a name="setHeader"></a>

<a name="setHeaders"></a>

setHeader() & setHeaders()

Get header or multi headers:

$response->setHeader('Location', 'https://raggitech.com');

$response->setHeaders([
    'Content-Type: application/pdf',
    'Content-Disposition: attachment; filename="downloaded.pdf"',
    'original.pdf',
]);

<a name="set"></a>

<a name="append"></a>

<a name="prepend"></a>

set() & append() & prepend()

Set content or append to it or prepend to it:

$response->set('<h1>content</h1>');

$response->append('FOOTER');
$response->prepend('HEADER');

<a name="json"></a>

json()

Set JSON output:

$response->json([
    'data' => [
        [
            'name' => 'Moamen Eltouny',
            'nickname' => 'Raggi'
        ]
    ]
]);

/*
{
    "data": [
        {
            "name": "Moamen Eltouny",
            "nickname": "Raggi"
        }
    ]
}
*/

<a name="variables"></a>

variables

Get/Set Variables:

$response->page_title = "RaggiTech";
echo $response->page_title; // RaggiTech

var_dump($response->getVariables());

$response->append('FOOTER');
$response->prepend('HEADER');

License

MIT license

  Files  
File Role Description
request (5 files)
composer.json Data Auxiliary data
composer.lock Data Auxiliary data
LICENSE Lic. License text
README.md Doc. Documentation
request.php Class Class source
response.php Class Class source

  Files  /  request  
File Role Description
   Agent.php Class Class source
   Client.php Class Class source
   Files.php Class Class source
   SingleFile.php Class Class source
   URL.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:44
This week:0
All time:9,870
This week:242

For more information send a message to info at phpclasses dot org.