get getEnvironment() from a service

There is no need to inject container. In fact, it is not a good idea to inject container because you’re making your class dependent on the DI.

You should inject environment parameter:

services.yml

notification:
  class:      NotificationService
  arguments: ["%kernel.environment%"]

NotificationService.php

<?php

private $env;

public function __construct($env)
{
    $this->env = $env;
}

public function mailStuff()
{
    if ( $this->env == "dev" ) {
        mail( '[email protected]', $lib, $txt, $entete );  
    } else {
        mail( $to->getEmail(), $lib, $txt, $entete );
    }
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)