Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.
Moderators: Chris Corbyn , General Moderators
audrey
Forum Newbie
Posts: 12 Joined: Sat Mar 03, 2007 2:19 pm
Post
by audrey » Sat Mar 31, 2007 2:51 pm
The __construct method in Swift.php currently has:
Code: Select all
public function __construct(Swift_IConnection &$object, $domain=false)
{
if (!$domain) $domain = !empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'SwiftUser';
If run from CLI, $_SERVER['SERVER_NAME'] will not exist. I suggest you change to:
Code: Select all
public function __construct(Swift_IConnection &$object, $domain=NULL)
{
$domain = !is_null($domain)
? $domain
: !empty($_SERVER['SERVER_NAME'])
? $_SERVER['SERVER_NAME']
: !empty($_SERVER['HOSTNAME'])
? $_SERVER['HOSTNAME']
: 'SwiftUser';
Personally, i'm just passing it as the second param to new Swift() but i thought somebody might want to see this.
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Sat Mar 31, 2007 11:58 pm
The logic will probably fail (see
http://us3.php.net/manual/sv/language.o ... .php#41251 ), and the nested ternary conditions are not clear to someone who wants to go in and read/edit the code. In this case, if statements, or even a seperate function or class would be better.
Last edited by
Benjamin on Sun Apr 01, 2007 12:14 am, edited 1 time in total.
audrey
Forum Newbie
Posts: 12 Joined: Sat Mar 03, 2007 2:19 pm
Post
by audrey » Sun Apr 01, 2007 12:12 am
A ternary always sounded to me like something that belongs in a nest.
Anyhoo, i think it's eminently readable. Indentation is crucial, of course.
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Sun Apr 01, 2007 12:17 am
Please see my revised post above, which cites an example.
audrey
Forum Newbie
Posts: 12 Joined: Sat Mar 03, 2007 2:19 pm
Post
by audrey » Sun Apr 01, 2007 3:28 am
Right you are!
And with the added braces, i'd have to agree that it would become unreadable. Otherwise, i have no problem following it.
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Sun Apr 01, 2007 7:29 am
It's probably a fair trade-off that it's setabble in the constructor anyway. I don't think anything in $_SERVER exists if running on CLI does it?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Apr 01, 2007 9:29 am
$_SERVER is mostly filled with environment variables when run from the command line.
audrey
Forum Newbie
Posts: 12 Joined: Sat Mar 03, 2007 2:19 pm
Post
by audrey » Sun Apr 01, 2007 11:12 am
This will quickly show you:
$ php -r 'phpinfo();' > phpinfo.txt