Overview

Namespaces

  • NGS
    • Client
      • Exception
    • Converter
    • Patterns
  • PHP

Classes

  • ApplicationProxy
  • CrudProxy
  • DomainProxy
  • HttpRequest
  • QueryString
  • ReportingProxy
  • RestHttp
  • StandardProxy
  • Overview
  • Namespace
  • Class
  • Tree

Class RestHttp

HTTP client used communication with platform Should not be used directly, instead use domain patterns Requests can be monitored via NGS\Client\RestHttp::addSubscriber()

Namespace: NGS\Client
Located at Client/RestHttp.php
Methods summary
public
# __construct( string $service, string $username = null, string $password = null )

Creates new client instance

Creates new client instance

Parameters

$service
string
$service Service base url
$username
string
$username
$password
string
$password
public
# setAuth( string $username, string $password )

Set username/password used for http authentication

Set username/password used for http authentication

Parameters

$username
string
$username
$password
string
$password
public
# getUsername( )
public
# setCertificate( mixed $certPath )
public static NGS\Client\RestHttp
# instance( NGS\Client\RestHttp $http = null )

Gets or sets singleton instance of rest Http

Gets or sets singleton instance of rest Http

Parameters

$http
NGS\Client\RestHttp

Returns

NGS\Client\RestHttp
public mixed
# sendRequest( string $uriSegment, string $method = 'GET', null $body = null, array $expectedCode = null, string $accept = 'application/json' )

Sends http request

Sends http request

Parameters

$uriSegment
string
$uriSegment Appended to REST service uri
$method
string
$method HTTP method
$body
null
$body Request body
$expectedCode
array
$expectedCode Expected http codes, throw exception
$accept
string
$accept

Returns

mixed

Throws

NGS\Client\Exception\InvalidRequestException|NGS\Client\Exception\NotFoundException|NGS\Client\Exception\RequestException|NGS\Client\Exception\SecurityException
NGS\Client\Exception\RequestException
public static
# parseResult( mixed $response, mixed $class = null )
public
# getLastResult( )
public
# addSubscriber( callable $subscriber )

Subscribe a callable to listen to HTTP request events

Subscribe a callable to listen to HTTP request events

Example use for simple logging:

$http = RestHttp::instance();
$http->addSubscriber(function($event, $context) {
    if ($event === RestHttp::EVENT_REQUEST_SENT) {
        echo 'request sent';
        print_r($context);
    }
});

Parameters

$subscriber
callable
$subscriber

Throws

InvalidArgumentException
protected
# dispatch( mixed $event, array $context )

Dispatches event to all subscribed listeners

Dispatches event to all subscribed listeners

Parameters

$event
mixed
$event
$context
array
$context
Constants summary
string EVENT_REQUEST_BEFORE 'request.before'
#
string EVENT_REQUEST_SENT 'request.sent'
#
string EVENT_REQUEST_ERROR 'request.error'
#
Properties summary
protected array $subscribers array()
#
protected string $service
#
protected string $username
#
protected string $auth
#

Authentication string

Authentication string

protected mixed $certPath
#
protected array $lastResponse
#
protected static NGS\Client\RestHttp $instance
#

Singleton instance

Singleton instance

API documentation generated by ApiGen 2.8.0