Request

class Request implements Libraries

Properties

static protected $instance

Methods

public static create() No description
protected __construct() No description
public post($url = null, $data = []) No description
public get($url = null) No description

Details

at line 10

create()

public static create()
at line 17

__construct()

protected __construct()
at line 19

post()

public post($url = null, $data = [])

Parameters

$url
$data
at line 33

get()

public get($url = null)

Parameters

$url

Source code

<?php

    namespace App\Khan\Libraries;
    use App\Khan\Contracts\Libraries\Libraries as LibrariesContract;

    class Request implements LibrariesContract {

    	protected static $instance = null;

        public static function create(){
            if(is_null(self::$instance)){
                self::$instance = new Request();
            }
            return self::$instance;
        }

        protected function __construct(){}

        public function post($url = null, $data = []){
        	if(is_null($url)){ return false; }
        	$ch = curl_init($url);
			curl_setopt($ch, CURLOPT_POST, true);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
			$result = curl_exec($ch);
			if(curl_errno($ch)){
				echo 'Curl error: '. curl_error($ch);
			}
			curl_close($ch);
			return $result;
        }

        public function get($url = null){
        	if(is_null($url)){ return false; }
        	return file_get_contents($url);
        }

    }