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
$cachedFactory
protected
static ServiceBuilderLoader
$cachedFactory
Cached instance of the service builder loader
$clients
protected
array<string|int, mixed>
$clients
= array()
Instantiated client objects
$eventDispatcher
protected
EventDispatcherInterface
$eventDispatcher
$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
addGlobalPlugin()
Attach a plugin to every client created by the builder
public
addGlobalPlugin(EventSubscriberInterface $plugin) : self
Parameters
- $plugin : EventSubscriberInterface
-
Plugin to attach to each client
Return values
selfaddSubscriber()
Add an event subscriber to the dispatcher
public
addSubscriber(EventSubscriberInterface $subscriber) : self
Parameters
- $subscriber : EventSubscriberInterface
-
Event subscriber
Return values
selfdispatch()
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
Return values
ServiceBuilderInterfaceget()
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|mixedgetAllEvents()
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>|nullgetEventDispatcher()
Get the EventDispatcher of the request
public
getEventDispatcher() : EventDispatcherInterface
Return values
EventDispatcherInterfaceoffsetExists()
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]
serialize()
public
serialize() : mixed
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
ServiceBuilderInterfacesetEventDispatcher()
Set the EventDispatcher of the request
public
setEventDispatcher(EventDispatcherInterface $eventDispatcher) : self
Parameters
- $eventDispatcher : EventDispatcherInterface
Return values
selfunserialize()
public
unserialize(mixed $serialized) : mixed
Parameters
- $serialized : mixed