Ticket #124 (new defect)

Opened 2 months ago

Exception using Solar_Mail_Transport_Adapter_Smtp

Reported by: Benjamin Kaineder/PACE Assigned to: pmjones
Priority: trivial Component: code
Keywords: mail smtp transport Cc:

Description

Problem

When using the Smtp Adapter (instead of the default Phpmail), an exception occurs upon using factory(): "Object with name 'smtp' not in registry.".

This is because the Smtp class expects to find an object keyed 'smtp' (can be configured) in the registry, therefore introducing a dependency on the caller to create this object before instantiating the transport, which makes it more inconvenient to use.

Steps to reproduce

public function actionTest()
{
    // create a transport - and watch it going down
    $transport = Solar::factory('Solar_Mail_Transport', array(
        'adapter' => 'Solar_Mail_Transport_Adapter_Smtp',
     ));
}

The output is as follows:

  'exception' => 
  Solar_Exception::__set_state(array(
     '_info' => 
    array (
      'name' => 'smtp',
    ),
     '_class' => 'Solar_Registry',
     'message' => 'Object with name \'smtp\' not in registry.',
     'string' => '',
     'code' => 'ERR_NOT_IN_REGISTRY',
     'file' => 'D:\\Inetpub\\playground\\HIOC\\Solar\\Solar.php',
     'line' => 375,
     'trace' => 
    array (
      0 => 
      array (
        'file' => 'D:\\Inetpub\\playground\\HIOC\\Solar\\Solar.php',
        'line' => 580,
        'function' => 'factory',
        'class' => 'Solar',
        'type' => '::',
        'args' => 
        array (
          0 => 'Solar_Exception',
          1 => 
          array (
            'class' => 'Solar_Registry',
            'code' => 'ERR_NOT_IN_REGISTRY',
            'text' => 'Object with name \'smtp\' not in registry.',
        in D:\Inetpub\playground\HIOC\Solar\Solar.php on line 375

Proposed solution

Make 'smtp' default to null - in Solar/Mail/Transport/Adapter/Smtp.php change line 32-34 from:

protected $_Solar_Mail_Transport_Adapter_Smtp = array(
    'smtp' => 'smtp',
);

to:

protected $_Solar_Mail_Transport_Adapter_Smtp = array(
    'smtp' => null,
);

Remark: I'm aware that you could also set 'smtp' in $config to null like so:

$transport = Solar::factory('Solar_Mail_Transport', array(
    'adapter' => 'Solar_Mail_Transport_Adapter_Smtp',
    'smtp' => null,
));

So the object will be created by dependency(), but you still have to set this in the caller.

Attachments


Add/Change #124 (Exception using Solar_Mail_Transport_Adapter_Smtp)