开发者

Multi Stage with Zend Framework - where to configure/store form emails?

On our development servers, When we work with forms and we test them, normally we use our own emails so that, when we test, we can receive those results and see if it's all working.

When we change to production, we must change those emails to "production" emails.

Often, we tend to forget that, and not so uncommonly we are receiving data that we shouldn't and, at the same time, our production beneficiaries aren't receiving what they should.

How can we deal with this, in a way that, according to the Environment variable definition, we can either have one email to be applied on our forms submissions, or another email?

Update - Important clarifications:

1)

I'm not that concerned with status messages, or emails that we use while stress testing something odd, no bug notifications, nothing like that.

It's a much simple concept: - We have some subscription forms and 开发者_运维问答a contact form. On the prod ENV that will correspond to two or three different emails. No more than that.

2)

Let's suppose we are extending Zend_Form for form creation and that, we have something among this lines (more or less):

$this->request->setMethod('POST')
->setPost(array(
'name'
=> 'Some Name',
'email'
=> 'contact@email.com',
'message'
=> "This is my test message."
));
$this->dispatch('/about/contact');

Update 2:

Can or should we have on my application.ini file something like:

[production]
contact.email.address = "trueemail@email.com"
contact.email.name = "John Stuart"

joinus.email.address = "anotheremail@email.com"
joinus.email.name = "Patricia Bill"


[development : production]
contact.email.address = "my@email.com"
contact.email.name = "Devname"

joinus.email.address = "my@email.com"
joinus.email.name = "Devname"

Or should we do this on another way ?

If we have like 10 different emails, this still is a laborious work and repetitive, because, if we have 10 forms, or development environment email will be repeated 10 times! :s

Another doubt that I have here is, once this is defined on the application.ini:

How can I call those emails address and names ?

What would be a acceptable way for doing it ?


This is hard to answer without knowing how your application is structured, how the forms are created and where the recipient details come from. But can you not simply check the APPLICATION_ENV at the point where you set the email address?

if (APPLICATION_ENV == 'development') {
    $email = 'yourtestemail@example.com'; // your test email address
} else {
    $email = 'normalemail@example.com'; // whatever the email should be
}

Edit: Since you implied you are creating your forms by extending Zend_Form, how about adding a base class for your contact forms which contains the logic I have above? Something like this:

class Yourapp_Form extends Zend_Form
{
    protected $_recipientEmail;

    public function setRecipientEmail($email)
    {
        $this->_recipientEmail = $email;
    }

    public function getRecipientEmail()
    {
        if (APPLICATION_ENV == 'develpoment') {
            return 'yourtestemail@example.com';
        } else {
            return $this->_recipientEmail;
        }
    }
}

you'd then use it in a similar way to how you currently use Zend_Form, so something like:

class Yourapp_Contact_Form extends Yourapp_Form
{
    public function init()
    {
        $this->addElement([...]);
        $this->setRecipientEmail('foo@example.com'); // <-- production email address
    }
}


I'm not really sure to understand what you want, however, if what you are looking for is a way to handle some logic to happen depending on your environment, here is a solution.

Write a Service, which you load anywhere (prod, dev, etc.). This service will take in charge of checking whether it should notify you or not depending on your APPLICATION_ENV.

The main advantage using a Service against an hard-coded if condition is to allow you to don't care about the availability of your method or not.

The component would act in a similar way to Zend_Log, and maybe, this component may fit your need better, depending on your use case.

With Zend_Log, you can set a priority to filter depending on your APPLICATION_ENV in your config.ini.

[development]
resources.log.stream.filterName = "Priority"
resources.log.stream.filterParams.priority = Zend_Log::DEBUG
[production]
resources.log.stream.filterName = "Priority"
resources.log.stream.filterParams.priority = Zend_Log::DEBUG

Zend_Log provides several so-called writters, which are either, files, email, firebug, etc.

Finally, try to minimize (if any) the use of "APPLICATION_ENV specific function, components, etc." use as in a real production environement, and use the provided tools (like Zend_Log, FirePHP, configuration tools, and mock object) if you want usefull debug informations.


Edit against your update:

Your solution is absolutely acceptable, even if you need to "repeat" x10. However, I'll go in slightly different way.

Something like that:

[production]
app.contacts.service1.name    = "Paul Dupont"
app.contacts.service1.email   = "paul.dupont@example.com"
app.contacts.service1.company = "Another Best Company"
app.contacts.service1.name  = "Kristina Dupuis"
app.contacts.service1.email = "k.dupuis@example.com"
[development]
app.contacts.service1.name    = "Me"
app.contacts.service1.email   = "me@example.com"
app.contacts.service1.company = "THE best company"
app.contacts.service1.name  = "Myself"
app.contacts.service1.email = "myself@example.com"

Right, it's a bit a heavy if you have a lot of service, but it's more more flexible than any hard-coded solution.

To use that, I'll go for:

  1. action helper, action helper are intended to be used only in Controller, easy, quick.
    OR
  2. A domain model object through a Service, flexible, and config.ini update free (if more service why not store in database)

Both would have a similar skeleton

interface Service // Service means here the competent service of your company
{

public function getEmail() {}

public function getContactName() {}

public function getCompanyName() {}

}

// usage, somewhere in your code :
$this->request->setMethod('POST')
->setPost(array(
'name'    => $serviceService->getService('contactus')->getContactName(),
'email'   => $serviceService->getService('contactus')->getEmail(),
'message' => "This is my test message."
));
$this->dispatch('/about/contact');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜