HTTPManager

Extends\org\turbocommons\src\main\php\model\BaseStrictClass

Class that contains functionalities related to the HTTP protocol and its most common requests

package

Default

Methods

Class that contains functionalities related to the HTTP protocol and its most common requests

__construct(boolean $asynchronous = false)
Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275

Arguments

$asynchronous

boolean

Specify if the HTTP manager instance will work in asynchronous or synchronous mode. (Synchronous mode is NOT recommended on client side languages)

Protection to prevent accessing undefined properties to this class

__get(string $name): void
inherited
Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275

Arguments

$name

string

The property name

Protection to prevent creating extra properties to this class

__set(string $name,string $value): void
inherited
Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275

Arguments

$name

string

The property name

$value

string

The property value

Get the number of created queues. Some may be running and some may be not

countQueues(): integer
Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275
see \org\turbocommons\src\main\php\managers\$this->queue()

Response

integer

The number of existing queues

Create a new http queue. Requests can then be added to this queue with the queue() method.

createQueue(string $name): void
Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275
see \org\turbocommons\src\main\php\managers\$this->queue()

Arguments

$name

string

The name we want to define for this queue

Delete a previously created global POST parameter so it is not sent with all the http manager requests anymore

deleteGlobalPostParam(string $parameterName)
Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275

Arguments

$parameterName

string

The name of the POST parameter that will be deleted

Remove the specified queue from this manager.

deleteQueue(string $name): void

Make sure the queue is not running when calling this method, or an exception will happen

Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275
see \org\turbocommons\src\main\php\managers\$this->queue()

Arguments

$name

string

The name for the queue we want to remove

Launch one or more http requests without caring about their execution order.

execute(string|array|\org\turbocommons\src\main\php\managers\httpmanager\HTTPManagerBaseRequest $requests,callable $finishedCallback = null,callable $progressCallback = null): void
Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275

Arguments

$requests

string|array|\org\turbocommons\src\main\php\managers\httpmanager\HTTPManagerBaseRequest

One or more requests to be inmediately launched (at the same time if possible). Each request can be defined as a string that will be used as a GET request url, or as an HTTPManagerBaseRequest instance in case we want to define parameters and callbacks.

$finishedCallback

callable

A method to be executed once all the http requests have finished (either succesfully or with errors). The callback will receive two parameters: results (an array with information about each request result in the same order as provided to this method) and anyError (true if any of the requests has failed)

$progressCallback

callable

Executed after each one of the urls finishes (either successfully or with an error). A string with the requested url and the total requests to perform will be passed to this method.

This method generates a GET url query from a set of key/value pairs

generateUrlQueryString(array|\org\turbocommons\src\main\php\model\HashMapObject $keyValuePairs): string

A query string is the part of an url that contains the GET parameters. It is placed after the ? symbol and contains a list of parameters and values that are sent to the url.

Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275
see https://en.wikipedia.org/wiki/Query_string\org\turbocommons\src\main\php\model\HashMapObject

Arguments

$keyValuePairs

array|\org\turbocommons\src\main\php\model\HashMapObject

An associative array or a HashMapObject containing key/value pairs that will be used to construct the query string. Note that when a value is an object or array, it will be encoded as a JSON string on the resulting query

Response

string

A valid query string that can be used with any url: http://www.url.com?query_string (Note that ? symbol is not included)

Get the value for a previously defined global POST parameter

getGlobalPostParam(string $parameterName): string
Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275

Arguments

$parameterName

string

The name of the POST parameter that we want to read

Response

string

The parameter value

Get the Http headers for a given url.

getUrlHeaders(string $url,callable $successCallback,callable $errorCallback): void

Note that crossdomain security rules may prevent this method from working correctly

Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275

Arguments

$url

string

The url for which we want to get the http headers.

$successCallback

callable

Executed when headers are read. An array of strings will be passed to this method containing all the read headers with each header line as an array element.

$errorCallback

callable

Executed if headers cannot be read. A string containing the error description and the error code will be passed to this method.

Check if the specified parameter name is defined as a global POST parameter

isGlobalPostParam(string $parameterName): boolean
Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275

Arguments

$parameterName

string

The name of the POST parameter that we want to check

Response

boolean

True if the parameter exists, false otherwise

Tells if there's currently a working internet connection available or not.

isInternetAvailable(callable $yesCallback,callable $noCallback): void
Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275

Arguments

$yesCallback

callable

Executed if the internet connection is available and working

$noCallback

callable

Executed if the internet connection is NOT available

Check if the specified queue is currently executing http requests

isQueueRunning(string $name): boolean
Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275
see \org\turbocommons\src\main\php\managers\$this->queue()

Arguments

$name

string

The name for the queue we want to check

Response

boolean

True if the specified queue is actually running its http requests

loadResourcesFromList

loadResourcesFromList( $todo)
Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275

Arguments

$todo

queue

queue( $todo)
Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275

Arguments

$todo

Set the value for a POST parameter that will be stored as a global POST parameter which will be always sent with all the http manager requests

setGlobalPostParam(string $parameterName,string $value)
Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275

Arguments

$parameterName

string

The name of the POST parameter that will be always sent to all the http requests

$value

string

The value that the POST parameter will have

Test if the specified url exists by trying to connect to it.

urlExists(string $url,callable $yesCallback,callable $noCallback): void

Note that crossdomain security rules may prevent this method from working correctly if you try to check the existence of an url that does not allow CORS outside your application domain.

Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in phar://D:/Storage/Backups/Git/TurboBuilder/TurboBuilder-Node/src/main/libs/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275

Arguments

$url

string

A full valid internet address to check

$yesCallback

callable

Executed if the url exists

$noCallback

callable

Executed if the url does not exist (or is not accessible).

Properties

If we want to use relative urls on all the requests that are executed by this class, we can define here a root url. All the request urls will then be composed as baseUrl + requestUrl.

baseUrl :

This property is useful when all the requests in our application share the same root url, which can be defined here.

Type(s)

Defines if the http comunications made by this class will be synchronous (code execution will be stopped while waiting for the response) or asynchronous (execution flow will continue and response will be processed once received) Note: Synchronous requests are normally NOT, NOT a good idea on client side languages

asynchronous :

Type(s)

Defines how much miliseconds will the http requests wait before failing with a timeout.

timeout :

If set to 0, no value will be specifically defined, so the platform default will be used.

Type(s)

If this flag is enabled, any request that is made by this service which uses http:// instead of https:// will throw an exception. When disabled, non secure http:// requests will be allowed

isOnlyHttps :

Type(s)

Defines a list with internet urls that will be used to test network availability by the isInternetAvailable() method. We mainly use globally available CDN urls, cause these are not blocked by cross-orining policies on the browsers and are widely available and replicated.

internetCheckLocations :

It may be interesting to add your own server side url at the bengining of this list, so it will be the first one to be tested, and you will also check that your server is correctly responding. Note that when an url request is successful, process ends and internet connection is considered to be working.

Type(s)