Code: Select all
<?php
class MailerController extends Base
{
public function __construct()
{
}
public function Mailer()
{
$mailer = $this->LoadExtension('Swift', array('Swift', 'Swift/Swift_SMTP_Connection'), array('Swift', 'Swift_SMTP_Connection'), array('', 'smtp.YOUR-ISP.com'));
}
}
?>Now here is where the problems come in! Swift has to first require swift.php, then the smtp_connection.php BUT it then has to initiate the smtp_connection class before the swift class while passing the instance of the smtp_class to the swift initiation...
maybe that did not make sence but look at it from here: http://www.swiftmailer.org/documentation/5#view
now here is what I tried with my LoadExtension method:
Code: Select all
public function LoadExtension($extension, $files, $classes, $params)
{
if (is_array($files))
{
foreach ($files as $key => $val)
{
require_once './Extensions/'.$extension.'/'.$val.'.php';
if ('' !== $classes[$key])
{
if ('' !== $params[$key])
{
//really don't know if this will even work the way I want it to
$tmp[] = new $classes[$key]($params[$key]);
}
else
{
$tmp[] = new $classes[$key];
}
}
}
}
else
{
require_once './Extensions/'.$extension.'/'.$files.'.php';
}
}Now this is not picking on d11wtq because if I was just going to use it once in one place then I would just do it all manually, no problems but this is more of a situation that might come up often and I don't want to have to copy / paste a whole bunch of code every time, I just want to be able to use my handy LoadExtension() method and if something needs changed then it's easier.
What my question is: is there a clean, simple way to do such a thing as what I want to do? Does anyone have any ideas on how to make something like my LoadExtension() method work with different libraries and whatnot so no matter what kind of structure (within reason) it requires to load it, I still can with the same method? OR should I just give up and just copy/paste the code every time?