Class TransportFactory
Factory class for generating email transport instances.
Property Summary
-
$_config protected static
array<string, mixed>
Configuration sets.
-
$_dsnClassMap protected static
array<string, string>
An array mapping url schemes to fully qualified Transport class names
-
$_registry protected static
Cake\Mailer\TransportRegistry|null
Transport Registry used for creating and using transport instances.
Method Summary
-
_buildTransport() protected static
Finds and builds the instance of the required tranport class.
-
configured() public static
Returns an array containing the named configurations
-
drop() public static
Drops a constructed adapter.
-
get() public static
Get transport instance.
-
getConfig() public static
Reads existing configuration.
-
getConfigOrFail() public static
Reads existing configuration for a specific key.
-
getDsnClassMap() public static
Returns the DSN class map for this class.
-
getRegistry() public static
Returns the Transport Registry used for creating and using transport instances.
-
parseDsn() public static
Parses a DSN into a valid connection configuration
-
setConfig() public static
This method can be used to define configuration adapters for an application.
-
setDsnClassMap() public static
Updates the DSN class map for this class.
-
setRegistry() public static
Sets the Transport Registry instance used for creating and using transport instances.
Method Detail
_buildTransport() ¶ protected static
_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
Returns
void
Throws
InvalidArgumentException
When a tranport cannot be created.
configured() ¶ public static
configured(): array<string>
Returns an array containing the named configurations
Returns
array<string>
drop() ¶ public static
drop(string $config): bool
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
bool
get() ¶ public static
get(string $name): Cake\Mailer\AbstractTransport
Get transport instance.
Parameters
-
string
$name Config name.
Returns
Cake\Mailer\AbstractTransport
getConfig() ¶ public static
getConfig(string $key): mixed|null
Reads existing configuration.
Parameters
-
string
$key The name of the configuration.
Returns
mixed|null
getConfigOrFail() ¶ public static
getConfigOrFail(string $key): mixed
Reads existing configuration for a specific key.
The config value for this key must exist, it can never be null.
Parameters
-
string
$key The name of the configuration.
Returns
mixed
Throws
InvalidArgumentException
If value does not exist.
getDsnClassMap() ¶ public static
getDsnClassMap(): array<string, string>
Returns the DSN class map for this class.
Returns
array<string, string>
getRegistry() ¶ public static
getRegistry(): Cake\Mailer\TransportRegistry
Returns the Transport Registry used for creating and using transport instances.
Returns
Cake\Mailer\TransportRegistry
parseDsn() ¶ public static
parseDsn(string $dsn): array<string, mixed>
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
Returns
array<string, mixed>
Throws
InvalidArgumentException
If not passed a string, or passed an invalid string
setConfig() ¶ public static
setConfig(array<string, mixed>|string $key, mixed $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
-
array<string, mixed>|string
$key The name of the configuration, or an array of multiple configs.
-
mixed
$config optional Configuration value. Generally an array of name => configuration data for adapter.
Returns
void
Throws
BadMethodCallException
When trying to modify an existing config.
LogicException
When trying to store an invalid structured config array.
setDsnClassMap() ¶ public static
setDsnClassMap(array<string, string> $map): void
Updates the DSN class map for this class.
Parameters
-
array<string, string>
$map Additions/edits to the class map to apply.
Returns
void
setRegistry() ¶ public static
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.
Returns
void