Adding the Action Mailer framework, for sending emails from your Akelos application.
commit4874766702a5579e8459755ca610d97f34b0e37f
authorBermi <bermi@akelos.com>
Sat, 26 Jul 2008 14:45:16 +0000 (26 14:45 +0000)
committerBermi <bermi@akelos.com>
Sat, 26 Jul 2008 14:45:16 +0000 (26 14:45 +0000)
tree9698743b0b51a24e704d6b61d9cb42fabaecf506
parent61826f265540e3fa40122c21d2cb9f345b1d36d4
Adding the Action Mailer framework, for sending emails from your Akelos application.

ActionMailer is an Akelos service-layer package for creating email messages.

=== Generate a mailer ===

Creates a stub file using the generator:

{{{
./script/generate mailer Notifier
}}}

A file is created in your app/models directory named notifier.php:

{{{
class Notifier extends AkActionMailer{
}
}}}

There are some new conventions for the Action Mailer:

  * Action Mailer implementations have views. The above example will reference files in app/views/notifier
  * Each email that you want to send should have one associated method within the class.
  * You don't call that method. Ever.
  * Instead, you call some dynamic methods, as we'll see below.

=== Example: ===

==== The scenario ====

Let's assume we're sending an email to a new user to our website to thank them for signing up, and that user is an object coming from an Active Record that has already been created.

=== Notifier ===

Add the following method to your Notifier:

{{{
function signup_thanks($User){
  //Email header info MUST be added here
  $this->set(array(
    'recipients' => $User->email,
    'from' => 'accounts@example.com',
    'subject' => 'Thank you for registering with our website',
    // Email body parameters (for the view) go here
    'body' => array( 'User' => $User )
    ));
}
}}}

=== Controller ===

And the following snippet to the controller in your application that needs to send an email:

{{{
function show_page_after_account_creation(){
  Ak::import_mailer('notifier');
  $Notifier = new Notifier();
  $Notifier->deliver('signup_thanks', $this->User);
}
}}}

You could also import the model into you controller as usual, but before you'll need to `require(AK_LIB_'DIR.'/AkActionMailer.php')`.

=== View ===

The body of the email comes from a .tpl file in app/views/notifier - In this example; app/views/notifier/signup_thanks.tpl:

{{{
Dear {User.first_name} {User.last_name},
Thanks for signing up with us!
}}}

==== HTML and Text messages ====

If you want to send two alternative messages (text/plain and text/html), the Akelos convention is to have two views like:

{{{
app/views/notifier/signup_thanks.text.plain.tpl
app/views/notifier/signup_thanks.text.html.tpl
}}}

If you add images to your html message Akelos will embed them automatically into the message body unless you set the attribute `_attach_html_images` to false in you mailer.

You can find more documentation on the Action Mailer at the AkActionMailer inline documentation and on the unit tests, document configuration, helpers and receiving emails.

----

Added new system for retrieving configurations from YAML files.

You just need to call Ak::getSettings($namespace), where namespace is "config/$namespace.yml"

----

Added new AkMailerTest, for testing ActionMailer models. This tester will copy your application views from the app/views to test/fixtures/app/views unless you implicitly set AkMailerTest::avoid''copying''views to true.

----

Adding Ak::import_mailer() which works like Ak::import(), but imports lib/AkActionMailer.php before doing so. We might deprecate this once we drop support for PHP4.

----

Whenever a charset is not supported by mb_* AkelosAkCharset will now default to the PhpRecoding engine on that specific recoding task.

----

Adding Ak::first() and Ak::last(), which work like PHP functions shift(), and pop() but without modifying source array.

----

Added a new system for unifying in-function static vars used mainly for performance improvements framework-wide.

Before we had

{{{
class A{
  function b($var){
    static $chache;
    if(!isset($cache[$var])){
      $cache[$var] = some_heavy_function($var);
    }
    return $cache[$var];
  }
}
}}}

Now imagine we want to create an application server which handles multiple requests on a single instantiation, with the showcased implementation this is not possible as we can't reset $cache, unless we hack badly every single method that uses this strategy.

We can refresh this static values the new `Ak::getStaticVar` method. So from previous example we will have to replace

{{{
static $chache;
}}}

with

{{{
$chache =&amp; Ak::getStaticVar(__CLASS__.'::'.__FUNCTION__);
}}}

You should not use this strategy on those situations where static vars should never be modified from other methods different of the model implementing it.

git-svn-id: http://svn.akelos.org/trunk@977 a2fa5c27-f921-0410-a72c-bf682d381be0
69 files changed:
CHANGELOG.txt
config/mailer.yml [new file with mode: 0644]
lib/Ak.php
lib/AkActionMailer.php [new file with mode: 0644]
lib/AkActionMailer/AkActionMailerQuoting.php [new file with mode: 0644]
lib/AkActionMailer/AkMailBase.php [new file with mode: 0644]
lib/AkActionMailer/AkMailComposer.php [new file with mode: 0644]
lib/AkActionMailer/AkMailDelivery/AkPhpMailDelivery.php [new file with mode: 0644]
lib/AkActionMailer/AkMailDelivery/AkSmtpDelivery.php [new file with mode: 0644]
lib/AkActionMailer/AkMailDelivery/AkTestDelivery.php [new file with mode: 0644]
lib/AkActionMailer/AkMailEncoding.php [new file with mode: 0644]
lib/AkActionMailer/AkMailMessage.php [new file with mode: 0644]
lib/AkActionMailer/AkMailParser.php [new file with mode: 0644]
lib/AkActionMailer/AkMailPart.php [new file with mode: 0644]
lib/AkActionView.php
lib/AkActionView/helpers/mail_helper.php [new file with mode: 0644]
lib/AkCharset.php
lib/AkUnitTest.php
lib/utils/generators/mailer/USAGE [new file with mode: 0644]
lib/utils/generators/mailer/mailer_generator.php [new file with mode: 0644]
lib/utils/generators/mailer/templates/mailer.tpl [new file with mode: 0644]
lib/utils/generators/mailer/templates/model_fixture.tpl [new file with mode: 0644]
lib/utils/generators/mailer/templates/unit_test.tpl [new file with mode: 0644]
lib/utils/generators/mailer/templates/view.tpl [new file with mode: 0644]
lib/utils/generators/mailer/templates/view_reference.tpl [new file with mode: 0644]
test/fixtures/app/helpers/example_helper.php [new file with mode: 0644]
test/fixtures/app/helpers/mailer_helper.php [new file with mode: 0644]
test/fixtures/app/models/first_mailer.php [new file with mode: 0644]
test/fixtures/app/models/funky_path_mailer.php [new file with mode: 0644]
test/fixtures/app/models/helper_mailer.php [new file with mode: 0644]
test/fixtures/app/models/render_mailer.php [new file with mode: 0644]
test/fixtures/app/models/second_mailer.php [new file with mode: 0644]
test/fixtures/app/models/test_mailer.php [new file with mode: 0644]
test/fixtures/app/views/first_mailer/share.tpl [new file with mode: 0644]
test/fixtures/app/views/helper_mailer/use_example_helper.tpl [new file with mode: 0644]
test/fixtures/app/views/helper_mailer/use_helper.tpl [new file with mode: 0644]
test/fixtures/app/views/helper_mailer/use_helper_method.tpl [new file with mode: 0644]
test/fixtures/app/views/helper_mailer/use_mail_helper.tpl [new file with mode: 0644]
test/fixtures/app/views/second_mailer/share.tpl [new file with mode: 0644]
test/fixtures/app/views/test_mailer/alternative_message_from_templates.text.html.tpl [new file with mode: 0644]
test/fixtures/app/views/test_mailer/alternative_message_from_templates.text.plain.tpl [new file with mode: 0644]
test/fixtures/app/views/test_mailer/implicitly_multipart_example.ignored.tpl [new file with mode: 0644]
test/fixtures/app/views/test_mailer/implicitly_multipart_example.text.html.tpl [new file with mode: 0644]
test/fixtures/app/views/test_mailer/implicitly_multipart_example.text.plain.tpl [new file with mode: 0644]
test/fixtures/app/views/test_mailer/implicitly_multipart_example.text.yaml.tpl [new file with mode: 0644]
test/fixtures/app/views/test_mailer/implicitly_multipart_example.tpl [new file with mode: 0644]
test/fixtures/app/views/test_mailer/multipart_rendering.text.html.tpl [new file with mode: 0644]
test/fixtures/app/views/test_mailer/multipart_rendering.text.plain.tpl [new file with mode: 0644]
test/fixtures/app/views/test_mailer/signed_up.tpl [new file with mode: 0644]
test/fixtures/app/views/test_mailer/signed_up_with_url.tpl [new file with mode: 0644]
test/fixtures/data/action_mailer/path.with.dots/funky_path_mailer/multipart_with_template_path_with_dots.tpl [new file with mode: 0644]
test/fixtures/data/action_mailer/path.with.dots/multipart_with_template_path_with_dots.tpl [new file with mode: 0644]
test/fixtures/data/action_mailer/raw_email [new file with mode: 0644]
test/fixtures/data/action_mailer/raw_email10 [new file with mode: 0644]
test/fixtures/data/action_mailer/raw_email11 [new file with mode: 0644]
test/fixtures/data/action_mailer/raw_email12 [new file with mode: 0644]
test/fixtures/data/action_mailer/raw_email13 [new file with mode: 0644]
test/fixtures/data/action_mailer/raw_email2 [new file with mode: 0644]
test/fixtures/data/action_mailer/raw_email3 [new file with mode: 0644]
test/fixtures/data/action_mailer/raw_email4 [new file with mode: 0644]
test/fixtures/data/action_mailer/raw_email5 [new file with mode: 0644]
test/fixtures/data/action_mailer/raw_email6 [new file with mode: 0644]
test/fixtures/data/action_mailer/raw_email7 [new file with mode: 0644]
test/fixtures/data/action_mailer/raw_email8 [new file with mode: 0644]
test/fixtures/data/action_mailer/raw_email9 [new file with mode: 0644]
test/fixtures/data/action_mailer/raw_email_quoted_with_0d0a [new file with mode: 0644]
test/fixtures/data/action_mailer/raw_email_with_partially_quoted_subject [new file with mode: 0644]
test/fixtures/data/action_mailer/testing.mp3 [new file with mode: 0644]
test/unit/lib/AkActionMailer.php [new file with mode: 0644]