PHP code example of jinexus-framework / jinexus-http

1. Go to this page and download the library: Download jinexus-framework/jinexus-http library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jinexus-framework / jinexus-http example snippets


use JiNexus\Http\Request\Request;
use JiNexus\Http\Request\Factory\RequestFactory;

// From the current super-globals...
$request = new Request();

// ...or via the factory.
$request = RequestFactory::build();

// ...or with explicit data (ideal for tests and CLI contexts).
$request = new Request([
    'cookie' => $_COOKIE,
    'file'   => $_FILES,
    'post'   => ['name' => 'jinexus'],
    'get'    => ['page' => '2'],   // note: the 'get' key populates the query bag
    'server' => $_SERVER,
]);

$request->query->get('page');          // '2'
$request->query->get('missing', 1);    // 1 (default when absent)
$request->post->has('name');           // true
$request->post->all();                 // ['name' => 'jinexus']
count($request->query);                // Countable
foreach ($request->server as $k => $v) { /* IteratorAggregate */ }

$request->query->add(['sort' => 'asc']); // merge/overwrite
$request->query->remove('page');         // delete

$request->isAjax();    // true when the X-Requested-With header is "XMLHttpRequest"
$request->isSecure();  // true when the HTTPS server value is truthy
$request->baseUrl();   // e.g. "https://example.com/app"

use JiNexus\Http\Http\Http;
use JiNexus\Http\Http\Factory\HttpFactory;

$http = new Http($request);
$http->request;             // the RequestInterface it was constructed with

$http = HttpFactory::build(); // builds a Request internally and wraps it