\Cake\MailerTransportFactory

Factory class for generating email transport instances.

Summary

Methods
Properties
Constants
setConfig()
getConfig()
config()
drop()
configured()
parseDsn()
setDsnClassMap()
getDsnClassMap()
dsnClassMap()
getRegistry()
setRegistry()
get()
No public properties found
No constants found
_buildTransport()
$_config
$_registry
$_dsnClassMap
N/A
No private methods found
No private properties found
N/A

Properties

$_config

$_config : array

Configuration sets.

Type

array

$_registry

$_registry : \Cake\Mailer\TransportRegistry

Transport Registry used for creating and using transport instances.

Type

\Cake\Mailer\TransportRegistry

$_dsnClassMap

$_dsnClassMap : array

An array mapping url schemes to fully qualified Transport class names

Type

array

Methods

setConfig()

setConfig(string|array  $key, array  $config = null) : void

This method can be used to define configuration adapters for an application.

To change an adapter's configuration at runtime, first drop the adapter and then reconfigure it.

Adapters will not be constructed until the first operation is done.

Usage

Assuming that the class' name is Cache the following scenarios are supported:

Setting a cache engine up.

Cache::setConfig('default', $settings);

Injecting a constructed adapter in:

Cache::setConfig('default', $instance);

Configure multiple adapters at once:

Cache::setConfig($arrayOfConfig);

Parameters

string|array $key

The name of the configuration, or an array of multiple configs.

array $config

An array of name => configuration data for adapter.

Throws

\BadMethodCallException

When trying to modify an existing config.

\LogicException

When trying to store an invalid structured config array.

getConfig()

getConfig(string  $key) : array|null

Reads existing configuration.

Parameters

string $key

The name of the configuration.

Returns

array|null —

Array of configuration data.

config()

config(string|array  $key, array|null  $config = null) : array|null

This method can be used to define configuration adapters for an application or read existing configuration.

To change an adapter's configuration at runtime, first drop the adapter and then reconfigure it.

Adapters will not be constructed until the first operation is done.

Usage

Assuming that the class' name is Cache the following scenarios are supported:

Reading config data back:

Cache::config('default');

Setting a cache engine up.

Cache::config('default', $settings);

Injecting a constructed adapter in:

Cache::config('default', $instance);

Configure multiple adapters at once:

Cache::config($arrayOfConfig);

Parameters

string|array $key

The name of the configuration, or an array of multiple configs.

array|null $config

An array of name => configuration data for adapter.

Throws

\BadMethodCallException

When trying to modify an existing config.

Returns

array|null —

Null when adding configuration or an array of configuration data when reading.

drop()

drop(string  $config) : boolean

Drops a constructed adapter.

If you wish to modify an existing configuration, you should drop it, change configuration and then re-add it.

If the implementing objects supports a $_registry object the named configuration will also be unloaded from the registry.

Parameters

string $config

An existing configuration you wish to remove.

Returns

boolean —

Success of the removal, returns false when the config does not exist.

configured()

configured() : array<mixed,string>

Returns an array containing the named configurations

Returns

array<mixed,string> —

Array of configurations.

parseDsn()

parseDsn(string  $dsn) : array

Parses a DSN into a valid connection configuration

This method allows setting a DSN using formatting similar to that used by PEAR::DB. The following is an example of its usage:

$dsn = 'mysql://user:pass@localhost/database?';
$config = ConnectionManager::parseDsn($dsn);

$dsn = 'Cake\Log\Engine\FileLog://?types=notice,info,debug&file=debug&path=LOGS';
$config = Log::parseDsn($dsn);

$dsn = 'smtp://user:secret@localhost:25?timeout=30&client=null&tls=null';
$config = Email::parseDsn($dsn);

$dsn = 'file:///?className=\My\Cache\Engine\FileEngine';
$config = Cache::parseDsn($dsn);

$dsn = 'File://?prefix=myapp_cake_core_&serialize=true&duration=+2 minutes&path=/tmp/persistent/';
$config = Cache::parseDsn($dsn);

For all classes, the value of scheme is set as the value of both the className unless they have been otherwise specified.

Note that querystring arguments are also parsed and set as values in the returned configuration.

Parameters

string $dsn

The DSN string to convert to a configuration array

Throws

\InvalidArgumentException

If not passed a string, or passed an invalid string

Returns

array —

The configuration array to be stored after parsing the DSN

setDsnClassMap()

setDsnClassMap(array  $map) : void

Updates the DSN class map for this class.

Parameters

array $map

Additions/edits to the class map to apply.

getDsnClassMap()

getDsnClassMap() : array

Returns the DSN class map for this class.

Returns

array

dsnClassMap()

dsnClassMap(array|null  $map = null) : array

Returns or updates the DSN class map for this class.

Parameters

array|null $map

Additions/edits to the class map to apply.

Returns

array

getRegistry()

getRegistry() : \Cake\Mailer\TransportRegistry

Returns the Transport Registry used for creating and using transport instances.

Returns

\Cake\Mailer\TransportRegistry

setRegistry()

setRegistry(\Cake\Mailer\TransportRegistry  $registry) : void

Sets the Transport Registry instance used for creating and using transport instances.

Also allows for injecting of a new registry instance.

Parameters

\Cake\Mailer\TransportRegistry $registry

Injectable registry object.

get()

get(string  $name) : \Cake\Mailer\AbstractTransport

Get transport instance.

Parameters

string $name

Config name.

Returns

\Cake\Mailer\AbstractTransport

_buildTransport()

_buildTransport(string  $name) : void

Finds and builds the instance of the required tranport class.

Parameters

string $name

Name of the config array that needs a tranport instance built

Throws

\InvalidArgumentException

When a tranport cannot be created.