why is not print all session value in php di injection container function

58 views Asked by At

I am using print_r(Auth::user()); in container injection function but this container function not allow here

 $user=Auth::user();

 print_r($user);

my main container function code.

      protected static function _makeContainer() 
        {
          $user=Auth::user();
          print_r($user);
          die;
          $config = Config::cache();
          $dbConfig = $config['database'];
          // Create our new php-di container
          $builder = new ContainerBuilder();
          $builder->useAutowiring(true);
          $builder->addDefinitions([
            'config'            => $config,
            PDO::class          => di_autowire()->constructor(
                "mysql:host={$dbConfig['host']};dbname={$dbConfig['database']}",
                $dbConfig['username'],
                $dbConfig['password'],
                ['ATTR_DEFAULT_FETCH_MODE' => PDO::FETCH_OBJ]
            ),
            PHPMailer::class    => di_autowire()->constructor(true),
            'Simcify\Mailer'    => factory(function($mail) {
                $mail->SMTPDebug = 0;
                $mail->isSMTP();
                $mail->Host = env('SMTP_HOST');
                $mail->SMTPAuth = env("SMTP_AUTH");
                $mail->Username = env('MAIL_USERNAME');
                $mail->Password = env('SMTP_PASSWORD');
                $mail->SMTPSecure = env('MAIL_ENCRYPTION');
                $mail->Port = env('SMTP_PORT');
                return $mail;
            })->parameter('mail', get('PHPMailer\PHPMailer\PHPMailer')),
            Session::class      => di_autowire()
        ]);
        
        Container::setInstance($builder->build());
     }

I want to use the dynamic connection string according to the user session.

0

There are 0 answers