I´m developing a site based on Zend Framework 3 and in some modules I need to send e-mails.
I´m using PERL Mail to do so. It willwill foward all e-mail send requests to Amazon SES service on production, and for development I´m using a free gmail account.
In my application I want to store the mail configuration in a local way using the local.php
file at that project/config/autoload directory
. In that way I can have different configurations for both development and production. So, I´ve created the following entries on my local.php
file:
'mail' => [
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'myusername@mydomain.com',
'password' => 'mypassword',
]
All fine, except that I don´t know how to get these parameters from my modules services and controllers.
Here is a service example that I need to access this parameter, located at module/User/src/service/UserManagerService
:
class UserManager
{
/**
* Doctrine entity manager.
* @var Doctrine\ORM\EntityManager
*/
private $entityManager;
public function __construct($entityManager)
{
$this->entityManager = $entityManager;
}
public function addUser($data)
{
**// Need to access the configuration data from here to send email**
}
}
This service has a factory:
<?php
namespace User\Service\Factory;
use Interop\Container\ContainerInterface;
use User\Service\UserManager;
class UserManagerFactory
{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$entityManager = $container->get('doctrine.entitymanager.orm_default');
return new UserManager($entityManager);
}
}
I´m pretty new to these ZF3 factories, services and controllers, so I´m little lost here.
How can I get the parameters stored in the local.php file here at this service ? Would that approach be the same for a controller ?