Cygnite - A Modern Toolkit For Web Developers

The Elegant Way of Building Full-Featured Web Applications

Cygnite Dynamic Routing



HTTP Requests


Interacting with HTTP requests and response very easy. Cygnite provides a object-oriented wrapper for PHP super global variables. HTTP request object created from $_GET, $_POST, $_SERVER, $_COOKIE, $_FILES, $_ENV global variables.

Creating A Requests

You may create a request using createFromGlobals() method, it is equivalent of calling __construct() method.

 use Cygnite\Http\Requests\Request;

 $request = Request::createFromGlobals();


 $request = new Request($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_ENV, $content = "");

Accessing Request Data

Request object stored in Ioc container. You may access the current HTTP request object in your controller action using the application object:

 public function profileAction($id)
    $app = $this->app();
    $request = $app->request;

    // profile/1/?foo=bar 
    echo $request->input('foo'); // output: bar

The Request object holds the information of current request. You may access request information via properties:

Accessing Query String Data

 $request->query->all(); // retrieving all query string data


Note: This is similar to calling $_GET and $request->query returns Collection object.

Accessing Post Data

 $request->post->all(); // retrieving all post data

 $request->post->get("foo"); // specific post data

Note: This is similar to calling $_POST and $request->post returns Collection object.

Accessing Request Data


Note: This is similar to calling $_REQUEST. You can use when you are not aware about the form of request, whether query string, post, delete, put, or patch data. If request is JSON it will return the value from JSON object.

Accessing Server Data


Note: This is similar to calling $_SERVER.

Accessing Header Data


Note: This are special $_SERVER values with keys prefixed with "HTTP_", $request->header/ $request->getHeader() returns a Collection object.

Accessing ENV Data


Note: This is similar to calling $_ENV.

Accessing FILES Data


Note: This is similar to calling $_FILES.

Accessing Put, Patch, Delete Data

Unlike other methods put, patch, delete property returns Collection object, but difference is it returns with x-www-form-urlencoded content type.





All above request data properties are wrapped into \Cygnite\Foundation\Collection object. Which is the data holder class. Below are mostly used methods over all global properties:

set($key, $value),

Read more about Collection class.

Getting the Method

Determine which HTTP method ($_GET or $_POST) used for the request using getMethod() :


HTTP Methods Spoofing

Generally HTML forms allows only GET or POST methods. However you you can spoof other methods by adding a hidden input field with the name "_method" and the value should be the HTTP method which you would like to spoof. For an example:

 <form method="POST">
    <input type="hidden" name="_method" value="DELETE">

Alternatively you can use X-HTTP-METHOD-OVERRIDE header to set the HTTP method.

Simulating a Request

You can also simulate the request from given URL instead creating request from PHP globals.

 $request->create('/hello-world' , 'GET', ['name' => 'Sanjoy']);

Request Body

The request body render from the php://input stream.

Getting Raw Body


Checking If Request Is JSON


Getting JSON Body


Determining Is Ajax Request


Checking If HTTPS


Getting The Client IP Address


Getting Full URL


Getting Referrer URL


Getting Path Info


Getting Authentication Information


Setting Trusted Proxies

 use Cygnite\Http\Requests\Request;

 Request::setTrustedProxies(["", ""]);

You may also add trusted proxy headers.

 use Cygnite\Http\Requests\Request;
 use Cygnite\Http\Requests\RequestHeaderConstants;

 Request::setTrustedHeaderName(RequestHeaderConstants::CLIENT_HOST, "X-Proxy-Ip");

Follow Us On Facebook Twitter Google+ Linkedin
Released Under The MIT Public License. Copyrights @2012-2017. Powered by- Sanjoy Dey Productions.