Skip to content

Commit

Permalink
Fixes from functional testing
Browse files Browse the repository at this point in the history
- Config doesn't always appear to be an object; cast to an array before testing
- captcha options should be nested one level deeper
  • Loading branch information
weierophinney committed May 29, 2012
1 parent 810cc28 commit 5030b29
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 23 deletions.
6 changes: 3 additions & 3 deletions config/module.config.php
Expand Up @@ -77,11 +77,11 @@
),
'view_manager' => array(
'template_map' => array(
'contact/index' => __DIR__ . '/../view/phly-contact/contact/index.phtml',
'contact/thank-you' => __DIR__ . '/../view/phly-contact/contact/thank-you.phtml',
'phly-contact/contact/index' => __DIR__ . '/../view/phly-contact/contact/index.phtml',
'phly-contact/contact/thank-you' => __DIR__ . '/../view/phly-contact/contact/thank-you.phtml',
),
'template_path_stack' => array(
'contact' => __DIR__ . '/../view/phly-contact',
'phly-contact' => __DIR__ . '/../view',
),
),
);
6 changes: 4 additions & 2 deletions config/module.phly-contact.local.config.php
Expand Up @@ -13,8 +13,10 @@
// This is simply configuration to pass to Zend\Captcha\Factory
'captcha' => array(
'class' => 'recaptcha',
'pubkey' => 'RECAPTCHA_PUBKEY_HERE',
'privkey' => 'RECAPTCHA_PRIVKEY_HERE',
'options' => array(
'pubkey' => 'RECAPTCHA_PUBKEY_HERE',
'privkey' => 'RECAPTCHA_PRIVKEY_HERE',
),
),

// This sets the default "to" and "sender" headers for your message
Expand Down
7 changes: 6 additions & 1 deletion src/PhlyContact/Service/ContactCaptchaFactory.php
Expand Up @@ -2,16 +2,21 @@

namespace PhlyContact\Service;

use Traversable;
use Zend\Captcha\Factory as CaptchaFactory;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Stdlib\ArrayUtils;

class ContactCaptchaFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $services)
{
$config = $services->get('config');
$spec = $config->phly_contact->captcha;
if ($config instanceof Traversable) {
$config = ArrayUtils::iteratorToArray($config);
}
$spec = $config['phly_contact']['captcha'];
$captcha = CaptchaFactory::factory($spec);
return $captcha;
}
Expand Down
6 changes: 1 addition & 5 deletions src/PhlyContact/Service/ContactControllerFactory.php
Expand Up @@ -11,18 +11,14 @@ class ContactControllerFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $services)
{
$config = $services->get('config');
$form = $services->get('PhlyContactForm');
$message = $services->get('PhlyContactMailMessage');
$transport = $services->get('PhlyContactMailTransport');
$events = $services->get('EventManager');

$controller = new ContactController();
$controller->setServiceManager($services);
$controller->setEventManager($events);
$controller->setContactForm($form);
$controller->setMessage($message);
$controller->setMailTransport($transport);
$controller->setContactForm($form);

return $controller;
}
Expand Down
7 changes: 6 additions & 1 deletion src/PhlyContact/Service/ContactFormFactory.php
Expand Up @@ -2,17 +2,22 @@

namespace PhlyContact\Service;

use Traversable;
use PhlyContact\Form\ContactFilter;
use PhlyContact\Form\ContactForm;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Stdlib\ArrayUtils;

class ContactFormFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $services)
{
$config = $services->get('config');
$name = $config->phly_contact->form->name;
if ($config instanceof Traversable) {
$config = ArrayUtils::iteratorToArray($config);
}
$name = $config['phly_contact']['form']['name'];
$captcha = $services->get('PhlyContactCaptcha');
$filter = new ContactFilter();
$form = new ContactForm($name, $captcha);
Expand Down
21 changes: 13 additions & 8 deletions src/PhlyContact/Service/ContactMailMessageFactory.php
Expand Up @@ -2,30 +2,35 @@

namespace PhlyContact\Service;

use Traversable;
use Zend\Mail\Message;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Stdlib\ArrayUtils;

class ContactMailMessageFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $services)
{
$config = $services->get('config');
$config = $config->phly_contact->message;
if ($config instanceof Traversable) {
$config = ArrayUtils::iteratorToArray($config);
}
$config = $config['phly_contact']['message'];

$message = new Message();

if (isset($config->to)) {
$message->addTo($config->to);
if (isset($config['to'])) {
$message->addTo($config['to']);
}

if (isset($config->from)) {
$message->addFrom($config->from);
if (isset($config['from'])) {
$message->addFrom($config['from']);
}

if (isset($config->sender) && isset($config->sender->address)) {
$address = $config->sender->address;
$name = isset($config->sender->name) ? $config->sender->name : null;
if (isset($config['sender']) && isset($config['sender']['address'])) {
$address = $config['sender']['address'];
$name = isset($config['sender']['name']) ? $config['sender']['name'] : null;
$message->setSender($address, $name);
}

Expand Down
11 changes: 8 additions & 3 deletions src/PhlyContact/Service/ContactMailTransportFactory.php
Expand Up @@ -2,18 +2,23 @@

namespace PhlyContact\Service;

use Traversable;
use Zend\Mail\Transport;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Stdlib\ArrayUtils;

class ContactMailTransportFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $services)
{
$config = $services->get('config');
$config = $config->phly_contact->mail_transport;
$class = $config->class;
$options = $config->options;
if ($config instanceof Traversable) {
$config = ArrayUtils::iteratorToArray($config);
}
$config = $config['phly_contact']['mail_transport'];
$class = $config['class'];
$options = $config['options'];

switch ($class) {
case 'Zend\Mail\Transport\Sendmail':
Expand Down

0 comments on commit 5030b29

Please sign in to comment.