Documentation

ServiceBuilder extends AbstractHasDispatcher
in package
implements ServiceBuilderInterface, ArrayAccess, Serializable

Class that holds an event dispatcher

Clients and data can be set, retrieved, and removed by accessing the service builder like an associative array.

Table of Contents

Interfaces

ServiceBuilderInterface
Service builder used to store and build clients or arbitrary data. Client configuration data can be supplied to tell the service builder how to create and cache {@see \Guzzle\Service\ClientInterface} objects. Arbitrary data can be supplied and accessed from a service builder. Arbitrary data and other clients can be referenced by name in client configuration arrays to make them input for building other clients (e.g. "{key}").
ArrayAccess
Serializable

Properties

$builderConfig  : array<string|int, mixed>
$cachedFactory  : ServiceBuilderLoader
$clients  : array<string|int, mixed>
$eventDispatcher  : EventDispatcherInterface
$plugins  : array<string|int, mixed>

Methods

__construct()  : mixed
__serialize()  : mixed
to fix php 8.1 compatibility
__unserialize()  : mixed
to fix php 8.1 compatibility
addGlobalPlugin()  : self
Attach a plugin to every client created by the builder
addSubscriber()  : self
Add an event subscriber to the dispatcher
dispatch()  : Event
Helper to dispatch Guzzle events and set the event name on the event
factory()  : ServiceBuilderInterface
Create a new ServiceBuilder using configuration data sourced from an array, .js|.json or .php file.
get()  : ClientInterface|mixed
Get a ClientInterface object or arbitrary data from the service builder
getAllEvents()  : array<string|int, mixed>
Get a list of all of the events emitted from the class
getData()  : array<string|int, mixed>|null
Get data from the service builder without triggering the building of a service
getEventDispatcher()  : EventDispatcherInterface
Get the EventDispatcher of the request
offsetExists()  : mixed
offsetGet()  : mixed
offsetSet()  : mixed
offsetUnset()  : mixed
serialize()  : mixed
set()  : ServiceBuilderInterface
Register a service or arbitrary data by name with the service builder
setEventDispatcher()  : self
Set the EventDispatcher of the request
unserialize()  : mixed

Properties

$builderConfig

protected array<string|int, mixed> $builderConfig = array()

Service builder configuration data

$clients

protected array<string|int, mixed> $clients = array()

Instantiated client objects

$plugins

protected array<string|int, mixed> $plugins = array()

Plugins to attach to each client created by the service builder

Methods

__construct()

public __construct([array<string|int, mixed> $serviceBuilderConfig = array() ]) : mixed
Parameters
$serviceBuilderConfig : array<string|int, mixed> = array()

Service configuration settings:

  • name: Name of the service
  • class: Client class to instantiate using a factory method
  • params: array of key value pair configuration settings for the builder

__serialize()

to fix php 8.1 compatibility

public __serialize() : mixed

__unserialize()

to fix php 8.1 compatibility

public __unserialize(mixed $serialized) : mixed
Parameters
$serialized : mixed

dispatch()

Helper to dispatch Guzzle events and set the event name on the event

public dispatch(mixed $eventName[, array<string|int, mixed> $context = array() ]) : Event
Parameters
$eventName : mixed

Name of the event to dispatch

$context : array<string|int, mixed> = array()

Context of the event

Return values
Event

Returns the created event object

factory()

Create a new ServiceBuilder using configuration data sourced from an array, .js|.json or .php file.

public static factory([array<string|int, mixed>|string $config = null ][, array<string|int, mixed> $globalParameters = array() ]) : ServiceBuilderInterface
Parameters
$config : array<string|int, mixed>|string = null

The full path to an .json|.js or .php file, or an associative array

$globalParameters : array<string|int, mixed> = array()

Array of global parameters to pass to every service as it is instantiated.

Tags
throws
ServiceBuilderException

if a file cannot be opened

throws
ServiceNotFoundException

when trying to extend a missing client

Return values
ServiceBuilderInterface

get()

Get a ClientInterface object or arbitrary data from the service builder

public get(mixed $name[, mixed $throwAway = false ]) : ClientInterface|mixed
Parameters
$name : mixed

Name of the registered service or data to retrieve

$throwAway : mixed = false

Only pertains to retrieving client objects built using a configuration array. Set to TRUE to not store the client for later retrieval from the ServiceBuilder. If an array is specified, that data will overwrite the configured params of the client if the client implements FromConfigInterface and will not store the client for later retrieval.

Return values
ClientInterface|mixed

getAllEvents()

Get a list of all of the events emitted from the class

public static getAllEvents() : array<string|int, mixed>
Return values
array<string|int, mixed>

getData()

Get data from the service builder without triggering the building of a service

public getData(string $name) : array<string|int, mixed>|null
Parameters
$name : string

Name of the service to retrieve

Return values
array<string|int, mixed>|null

offsetExists()

public offsetExists(mixed $offset) : mixed
Parameters
$offset : mixed
Attributes
#[ReturnTypeWillChange]

offsetGet()

public offsetGet(mixed $offset) : mixed
Parameters
$offset : mixed
Attributes
#[ReturnTypeWillChange]

offsetSet()

public offsetSet(mixed $offset, mixed $value) : mixed
Parameters
$offset : mixed
$value : mixed
Attributes
#[ReturnTypeWillChange]

offsetUnset()

public offsetUnset(mixed $offset) : mixed
Parameters
$offset : mixed
Attributes
#[ReturnTypeWillChange]

set()

Register a service or arbitrary data by name with the service builder

public set(mixed $key, mixed $service) : ServiceBuilderInterface
Parameters
$key : mixed

Name of the client or data to register

$service : mixed

Client configuration array or arbitrary data to register. The client configuration array must include a 'class' (string) and 'params' (array) key.

Return values
ServiceBuilderInterface

unserialize()

public unserialize(mixed $serialized) : mixed
Parameters
$serialized : mixed

        
On this page

Search results