PHP code example of viloveul / http

1. Go to this page and download the library: Download viloveul/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/ */

    

viloveul / http example snippets




// e.x : http://yourdomain.com/path/to/something?param1=data1&param2=data2

$request = Viloveul\Http\Server\RequestFactory::fromGlobals();

$param1 = $request->getQuery('param1', 'nothing');
$param2 = $request->getQuery('param2', 'nothing');
$param3 = $request->getQuery('param3', 'nothing');

var_dump($param1, $param2, $param3);

// OR you can assign to object

class SampleParam implements Viloveul\Http\Contracts\ServerRequestAssignment
{
	protected $attributes = [];
	public function setAttributes(array $attributes): void
	{
		$this->attributes = $attributes;
	}
	public function getAttributes(): array
	{
		return $this->attributes;
	}
}

$data = $request->loadQueryTo(new SampleParam);

var_dump($data);