tenaga / http
Fast & Simple HTTP Component
This package is auto-updated.
Last update: 2025-06-27 03:11:20 UTC
README
Http Foundation for Tenaga Framework Inspired by PatrickLouys/http
How to install?
composer require tenaga\Http
Usage?
Request
Request give some function to access superglobals PHP variables. How to initialize? write some code like below
use Tenaga\Http\Request; $request = new Request; $request->set();
Then you can call some function below
# Get value from $_REQUEST superglobals variables $request->all($key, $default = null); # Get value from $_POST superglobals variables $request->post($key, $default = null); # Get value from $_GET superglobals variables $request->get($key, $default = null); # Get value from $_FILES superglobals variables $request->file($key, $default = null); # Get value from $_COOKIE[$key] superglobals variables $request->cookie($key, $default = null); # Get all parameters key & value that passe by $_GET and $_POST $request->parameters(); # Get uri, i.e : test.com/test1/test2/... $request->uri(); # Get url path, i.e : test1/test2/test3/.../... $request->path(); # Get method that receive $request->method(); # Get HTTP_ACCEPT for current request $request->httpAccept(); # Get HTTP_REFERER for current request $request->referer(); # Get user agent for current request $request->userAgent(); # The IP address from which the user is viewing the current page. $request->ipAddress(); # Check if the current page using https, that will return boolean $request->isSecure();
Response
Response give some function to prepare response in string type of variables. To initialize write some code below.
use Tenaga\Http\Response; $response = new Response;
Then you can call some function below
# Set up the response $response->setResponse($response); # Get the response, you must add it at end $response->getResponse(); # Append the current response $response->appendResponse($response);
Header
Header will give you some function to manipulate header. To initialize write some code below.
use Tenaga\Http\Header; $header = new Header;
Then you can some function below
# Set status code $header->setStatusCode($statusCode , $statusText = null); # Set content type that will show $header->setContentType($type, $charset = NULL); # Set expires $header->setExpired($date); # Set header $header->setHeader($name,$value); # Get all header $header->getAllHeader();
Cookie
Cookie will give you to easily manipulate and add cookie. To initialize write some code below.
use Tenaga\Http\Cookie; $cookie = new Cookie;
Then you can some function below
# Set cookie by just passing the cookie by an array prepare(array $cookie); # Set cookie name setName(string $name); # Set cookie value setValue($value); # Set Cookie expired setExpired(int $time); # Set cookie path setPath($path); # Set Cookie Domain setDomain($domain); # Set cookie secure (optional), default : false setSecure(bool $secure); # Set Http only (optional), default : false setHttpOnly(bool $httpOnly); # Create the cookie create();
To use cookie you must write code like this
$cookie->prepare ->setName('ExampleCookie') ->setValue('Example') ->setExpired(3600) ->setPath('/') ->setDomain('localhost.com') ->setSecure(true) ->setHttpOnly(true) ->create();
You can call some or all of them, but you must use prepare for preparing cookie and at the end create() function for making the cookie
Or you can use prepare() function to create new cookie.
/** * List Of key of array * 0 => name * 1 => value * 2 => expire * 3 => path * 4 => domain (optional) * 5 => secure (optional) * 6 => httponly (optional) */ $cookieData = [ 'ExampleCookie', 'Example', 3600, '/', 'localhost.com' ]; $cookie->prepare($cookieData)->create();