Page 1 of 1

Proposal for a possible new PHP5 branch (EDIT | Ok and PHP4)

Posted: Wed Nov 01, 2006 10:27 am
by Chris Corbyn
Since this is a fair bit different (and more complex) I may just release it under a different branch and keep the existing Swift under development as-is. I could of course provide yet another compat file to wrapper it all up.

I'm growing ever concious of the size of the Swift.php file and could do with some major refactoring in the area of Message composition mostly among other things.

My initial thoughts (spurred from the Java mailer I'm building) are something like this:

Code: Select all

<?php

try {
	
	//Create a new instance of the mailer using whatever connection
	$mailer = new Swift(new Swift_SMTP("host.tld"));
	
	//Start composing a message (caching can occur inside the message object)
	$message = new Swift_Message("My Subject");
	$message->setFrom(new Swift_Address("Chris", "chris@w3style.co.uk"));
	
	//Build the message up
	$part1 = new Swift_Part("Foobar", "text/html");
	$message->add($part1);
	
	$part2 = new Swift_Part("Foobar plain");
	$message->add($part2);
	
	$att = new Swift_Attachment("/home/d11twq/mydocument.pdf");
	$att->setContentType("application/pdf");
	$message->add($att);
	
	//Send to a list of addresses (Swift_Address is a single address)
	$recipients = new Swift_AddressList();
	$recipients->addTo("Chris", "chris@w3style.co.uk");
	$recipients->addTo("Joe", "joe@bloggs.com");
	$recipients->addCc("Jim", "jim@henderson.tld");
	$recipients->addBcc("some@address.com");
	
	//Deliver the message to the recipients
	$mailer->send($message, $recipients);
	$mailer->close();
	
} catch (Swift_ConnectionException $e) {
	//handle failed connection
} catch (Swift_MimeException $e) {
	//handle failed message building
} catch (Swift_IOException $e) {
	//handle failed command
}
I'm aware it's a bit of a steep learning curve from Swift as it is now but in terms of modularity it's heaps better with all Message components extending a Mime class, Recipients contained into their own groups, the ability to loop with an already built (and compiled) message etc.

Just wanted to pick your brains really?

Posted: Wed Nov 01, 2006 10:33 am
by John Cartwright
Who is your target audience? A newbie is just looking for a quick plug and play code or a developer that understands whats going on here? Your answer will pretty much justify whether or not this format is the right direction for Swift.

Posted: Wed Nov 01, 2006 10:41 am
by Chris Corbyn
Jcart wrote:Who is your target audience? A newbie is just looking for a quick plug and play code or a developer that understands whats going on here? Your answer will pretty much justify whether or not this format is the right direction for Swift.
Well yeah, Swift as of now is newbie friendly (I hope). This is a bit more targeted at pure OOP developers.

I could make the underbelly of Swift work in this fashion (even on PHP4, less the exceptions) but keep the interface the same using the "Swift" class and provide an alternative Swift class for the advanced version (or vice versa). Perhaps that would keep everybody happy since non-OO developers who are happy with the existing implementation need not be concious of the re-structuring. I believe I may be able to re-assess some areas to save a bit more memory in the process of doing this too.

It would be a few weeks or so away yet while I get the Java implementation finished off.

Posted: Wed Nov 01, 2006 10:42 am
by Luke
I think it's a great idea... :)

Posted: Wed Nov 01, 2006 11:18 am
by John Cartwright
Just thought I would add, I defiantly do like the adjustments.

Posted: Wed Nov 01, 2006 11:21 am
by Maugrim_The_Reaper
I would aggregate as many of the steps as possible - but maintain the individual breakouts as you described above. It wouldn't be too difficult to keep both sides happy from there (thinking of a Facade more than a big Swift class just duplicating code from the alternate API). Breaking BC is always to drag out a few sore folk ;).

Posted: Wed Nov 01, 2006 3:38 pm
by Chris Corbyn
Ok brilliant, this will happen then :) The biggest change existing users will need to make will be to change "new Swift(...)" to "new SimpleSwift(...)" or something. SimpleSwift just being a wrapper around the new API to provide the same interface as we have now.