Postmark client factories for PSR Containers
This very small library provides PSR-11 compatible factories for creating Postmark HTTP clients for either servers for sending mail, or the admin client for managing your account.
composer require netglue/psr-container-postmark
By default, the container will look for application configuration using the id
config which is a generally accepted standard. If your PSR-11 container doesn't return an associative array when calling
$container->get('config') then this lib will likely be useless to you.
Postmark-specific configuration is, by default, expected underneath the
'postmark' key, though this can be modified.
Assuming defaults, your configuration for the clients should look like this:
return [ 'postmark' => [ 'server_token' => 'Your Server Token', 'server_timeout' => 30, // The default is 30, as per Postmark's libs so this option can be omitted 'admin_token' => 'Your Account Token', // Only required if you are using the Admin client to manage an account ], ];
You would then wire up your container so that a key of your choosing is mapped to the factory classes, perhaps:
return [ 'dependencies' => [ 'factories' => [ Postmark\PostmarkClient::class => Netglue\PsrContainer\Postmark\ClientFactory::class, Postmark\PostmarkAdminClient::class => Netglue\PsrContainer\Postmark\AdminClientFactory::class, ], ], ];
If you run multiple servers for some reason, you can wire up the factory in the following way to use different configuration for different servers:
return [ 'dependencies' => [ 'factories' => [ 'EmailServer1' => [Netglue\PsrContainer\Postmark\ClientFactory::class, 'postmark_server_1'], 'EmailServer2' => [Netglue\PsrContainer\Postmark\ClientFactory::class, 'postmark_server_2'], ], ], ];
Given the above container setup, you'd need to specify two top-level configuration arrays with a server key in each for
Because I use Laminas (Formerly Zend) components a lot, this lib will auto-wire dependencies (if you choose to allow it) during composer installation thanks to laminas-component-installer.