Wrench\BasicServer

class BasicServer
constant EVENT_SOCKET_CONNECT

Events

property rateLimiter

protected

property originPolicy

protected

property uri

protected string

The URI of the server

property options

protected array

Options

property logger

protected Closure

A logging callback

The default callback simply prints to stdout. You can pass your own logger in the options array. It should take a string message and string priority as parameters.

property listeners

protected array<string

Event listeners

Add listeners using the addListener() method.

property connectionManager

protected ConnectionManager

Connection manager

property applications

protected array<string

Applications

property protocol

protected Protocol

__construct($uri, $options = array())

Constructor

Parameters:
  • $uri (string) –
  • $options (array) –
configure($options)
Parameters:
  • $options
configureRateLimiter()
configureOriginPolicy()

Configures the origin policy

addAllowedOrigin($origin)

Adds an allowed origin

Parameters:
  • $origin (array) –
configureLogger()

Configures the logger

Returns:void
configureConnectionManager()

Configures the connection manager

Returns:void
getConnectionManager()

Gets the connection manager

Returns:WrenchConnectionManager
getUri()
Returns:string
setLogger($logger)

Sets a logger

Parameters:
  • $logger (Closure) –
Returns:

void

run()

Main server loop

Returns:void This method does not return!
log($message, $priority = 'info')

Logs a message to the server log

The default logger simply prints the message to stdout. You can provide a logging closure. This is useful, for instance, if you’ve daemonized and closed STDOUT.

Parameters:
  • $message (string) – Message to display.
  • $priority
Returns:

void

notify($event, $arguments = array())

Notifies listeners of an event

Parameters:
  • $event (string) –
  • $arguments (array) – Event arguments
Returns:

void

addListener($event, $callback)

Adds a listener

Provide an event (see the Server::EVENT_* constants) and a callback closure. Some arguments may be provided to your callback, such as the connection the caused the event.

Parameters:
  • $event (string) –
  • $callback (Closure) –
Returns:

void

getApplication($key)

Returns a server application.

Parameters:
  • $key (string) – Name of application.
Returns:

Application The application object.

registerApplication($key, $application)

Adds a new application object to the application storage.

Parameters:
  • $key (string) – Name of application.
  • $application (object) – The application object
Returns:

void

configureProtocol()

Configures the protocol option