mailer library for sending emailsmailer library code
namespace VilniusPhp\Mailer;
class Mailer
{
public function __construct(array $options)
{
// ...
}
public function sendEmail($email, $subject, $body)
{
// ...
}
}
mailer usage in registration
use VilniusPhp\Mailer;
$mailer = new Mailer(['host' => '127.0.0.1:25']);
$mailer->sendEmail(
'[email protected]',
'Welcome to my site!',
$templating->render('email_content.html.twig')
);
mailer usage after successful order
use VilniusPhp\Mailer;
$mailer = new Mailer(['host' => '127.0.0.1:25']);
$mailer->sendEmail(
'[email protected]',
'Order successful!',
$templating->render('order.html.twig', ['order' => $order])
);
mailer code?
composer.json inside mailer
{
"name": "vilnius-php/mailer"
}
composer.json inside our services
{
"name": "...",
"require": {
"vilnius-php/mailer": "*"
}
}
mailer library code
namespace VilniusPhp\Mailer;
class Mailer
{
public function __construct(array $options)
{
// ...
}
public function sendEmail($email, $subject, $body)
{
// ...
}
}
mailer library code
namespace VilniusPhp\Mailer;
class Mailer
{
public function __construct(array $options)
{
// ...
}
public function sendEmail(array $emails, $subject, $body)
{
// ...
}
}
Given a version number MAJOR.MINOR.PATCH, increment the:
When you possibly break something when it's updated
Given that only API is used (aka contract)
The things you're allowed to use from the library
Software using Semantic Versioning MUST declare a public API. This API could be declared in the code itself or exist strictly in documentation. However it is done, it should be precise and comprehensive.
@internalIt's not that you cannot do that, it's just that it can break when you update the framework
mailer
git tag 2.0.0
git push --tags
composer.json inside User service
{
"name": "...",
"require": {
"vilnius-php/mailer": "^2.0.0"
}
}
composer.json inside Orders service
{
"name": "...",
"require": {
"vilnius-php/mailer": "^1.0.0"
}
}
UPGRADE.md inside mailer library
# Upgrade from 1.0 to 2.0
First argument in method `sendEmail` was changed from string
to array.
Previous:
```
$mailer->sendEmail($email, $subject, $body);
```
Updated:
```
$mailer->sendEmail(['Name Surname' => $email], $subject, $body);
```
vilnius-php/mailer requirements:
{
// ...
"require": {
"vilnius-php/email-validator": "^1.0"
}
}
Project requirements:
{
// ...
"require": {
"vilnius-php/mailer": "^1.0",
"vilnius-php/email-validator": "^1.0"
}
}
class EmailValidator
{
public function validateEmail($email)
{
// ...
}
// this was added in 1.1 version:
public function validateEmailList(array $emails)
{
// ...
}
}
namespace VilniusPhp\Mailer;
class Mailer
{
// ...
public function sendEmail(array $emails, $subject, $body)
{
// this call is added in 2.0.1
$this->emailValidator->validateEmailList($emails);
// ...
}
}
composer update vilnius-php/mailer
Is everything all right now?
Nope - fatal
vilnius-php/mailer
{
// ...
"require": {
"vilnius-php/email-validator": "^1.1"
}
}
composer update vilnius-php/mailer
Is everything all right now?
Nope - update fails
composer update vilnius-php/mailer --with-dependencies
class Mailer
{
// ...
public function sendEmail($email, $subject, $body)
{
// ...
}
}
class Mailer
{
// ...
public function sendEmail($emails, $subject, $body)
{
if (is_string($emails)) {
$emails = [$emails => $emails];
@trigger_error(
'Email as string will not be supported in 2.0',
E_USER_DEPRECATED
);
}
// ...
}
}
class Mailer
{
// ...
public function sendEmail(array $emails, $subject, $body)
{
// ...
}
}
class Mailer
{
/**
* @deprecated this will be removed in 2.0
* @use sendEmailToMany
*/
public function sendEmail($email, $subject, $body)
{
// ...
}
public function sendEmailToMany(array $emails, $subject, $body)
{
// ...
}
}
private propertiesprivate methods@internal
interface MailerInterface
{
public function sendEmail($email, $subject, $body);
}
/**
* @internal
*/
class Mailer implements MailerInterface
{
// ...
}
/** @var MailerInterface $mailer */
$mailer = $container->get('vilnius_php.mailer');