PHP Class Minishlink\WebPush\WebPush

显示文件 Open project: minishlink/web-push Class Usage Examples

Protected Properties

Property Type Description
$auth array
$browser Buzz\Browser

Public Methods

Method Description
__construct ( array $auth = [], array $defaultOptions = [], integer | null $timeout = 30, Buzz\Client\AbstractClient $client = null ) WebPush constructor.
flush ( ) : array | boolean Flush notifications. Triggers the requests.
getAutomaticPadding ( ) : integer
getBrowser ( ) : Buzz\Browser
getDefaultOptions ( ) : array
isAutomaticPadding ( ) : boolean
sendNotification ( string $endpoint, string | null $payload = null, string | null $userPublicKey = null, string | null $userAuthToken = null, boolean $flush = false, array $options = [], array $auth = [] ) : array | boolean Send a notification.
setAutomaticPadding ( integer $automaticPadding ) : WebPush
setBrowser ( Buzz\Browser $browser ) : WebPush
setDefaultOptions ( array $defaultOptions )

Private Methods

Method Description
prepareAndSend ( array $notifications )
sendRequest ( string $url, array $headers, string $content ) : Buzz\Message\MessageInterface | null

Method Details

__construct() public method

WebPush constructor.
public __construct ( array $auth = [], array $defaultOptions = [], integer | null $timeout = 30, Buzz\Client\AbstractClient $client = null )
$auth array Some servers needs authentication
$defaultOptions array TTL, urgency, topic
$timeout integer | null Timeout of POST request
$client Buzz\Client\AbstractClient

flush() public method

Flush notifications. Triggers the requests.
public flush ( ) : array | boolean
return array | boolean If there are no errors, return true. If there were no notifications in the queue, return false. Else return an array of information for each notification sent (success, statusCode, headers, content)

getAutomaticPadding() public method

public getAutomaticPadding ( ) : integer
return integer

getBrowser() public method

public getBrowser ( ) : Buzz\Browser
return Buzz\Browser

getDefaultOptions() public method

public getDefaultOptions ( ) : array
return array

isAutomaticPadding() public method

public isAutomaticPadding ( ) : boolean
return boolean

sendNotification() public method

Send a notification.
public sendNotification ( string $endpoint, string | null $payload = null, string | null $userPublicKey = null, string | null $userAuthToken = null, boolean $flush = false, array $options = [], array $auth = [] ) : array | boolean
$endpoint string
$payload string | null If you want to send an array, json_encode it
$userPublicKey string | null
$userAuthToken string | null
$flush boolean If you want to flush directly (usually when you send only one notification)
$options array Array with several options tied to this notification. If not set, will use the default options that you can set in the WebPush object
$auth array Use this auth details instead of what you provided when creating WebPush
return array | boolean Return an array of information if $flush is set to true and the queued requests has failed. Else return true

setAutomaticPadding() public method

public setAutomaticPadding ( integer $automaticPadding ) : WebPush
$automaticPadding integer Max padding length
return WebPush

setBrowser() public method

public setBrowser ( Buzz\Browser $browser ) : WebPush
$browser Buzz\Browser
return WebPush

setDefaultOptions() public method

public setDefaultOptions ( array $defaultOptions )
$defaultOptions array Keys 'TTL' (Time To Live, defaults 4 weeks), 'urgency', and 'topic'

Property Details

$auth protected_oe property

protected array $auth
return array

$browser protected_oe property

protected Browser,Buzz $browser
return Buzz\Browser