netglue / psr-container-postmark
Postmark client factories for PSR Containers
Installs: 35 061
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 0
Open Issues: 4
Requires
- php: ~8.1 || ~8.2 || ~8.3
- psr/container: ^1.0.0 || ^2.0.0
- wildbit/postmark-php: ^2.9||^3.0||^4.0 || ^6.0
Requires (Dev)
- doctrine/coding-standard: ^12.0
- laminas/laminas-servicemanager: ^3.22.1
- phpunit/phpunit: ^10.5.5
- psalm/plugin-phpunit: ^0.18.4
- roave/security-advisories: dev-latest
- vimeo/psalm: ^5.18.0
This package is auto-updated.
Last update: 2024-10-31 00:20:49 UTC
README
Introduction
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.
Postmark is a reliable transactional email delivery service. These factories return clients from their official PHP library.
Install
composer require netglue/psr-container-postmark
Usage
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
'postmark_server_1'
and 'postmark_server_2'
Laminas Integration
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.
fin.