Permalink
Browse files

Refactored module to use PhlyContact namespace

- Refactored all classes and paths to use the PhlyContact namespace
- To make the module forward-compatible, pushed view scripts down a level, under
  the phly-contact directory.
- Added ability to redirect to the contact page from thank-you if not accessed
  via a redirect.
- Modified configuration to assume a Dumb CAPTCHA adapter and Sendmail mail
  transport by default, but retained the definition for the ReCaptcha to
  simplify usage.
- Added a sample "local" configuration
- Added a README.md file
  • Loading branch information...
1 parent 0625023 commit 1a3557013c0e6fb83fc7a0faea922c52a33c18d0 @weierophinney weierophinney committed Mar 17, 2012
View
@@ -0,0 +1 @@
+.vimproject
View
@@ -1,9 +1,8 @@
<?php
-namespace Contact;
+namespace PhlyContact;
-use InvalidArgumentException,
- Zend\Module\Consumer\AutoloaderProvider;
+use Zend\Module\Consumer\AutoloaderProvider;
class Module implements AutoloaderProvider
{
@@ -13,37 +12,16 @@ public function getAutoloaderConfig()
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php'
),
+ 'Zend\Loader\StandardAutoloader' => array(
+ 'namespaces' => array(
+ __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
+ ),
+ ),
);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
-
- public function getProvides()
- {
- return array(
- 'name' => 'Blog',
- 'version' => '0.1.0',
- );
- }
-
- public function getDependencies()
- {
- return array(
- 'php' => array(
- 'required' => true,
- 'version' => '>=5.3.1',
- ),
- 'ext/mongo' => array(
- 'required' => true,
- 'version' => '>=1.2.0',
- ),
- 'CommonResource' => array(
- 'required' => true,
- 'version' => '>=0.1.0',
- )
- );
- }
}
View
@@ -0,0 +1,67 @@
+PhlyContact
+====
+
+This is a simple ZF2 module implementing a contact form.
+
+Requirements
+----
+
+* PHP >= 5.3.3
+* Zend Framework 2, specifically:
+ * Zend\Captcha (used for CAPTCHA functionality on the forms)
+ * Zend\Form (the contact form itself; currently supports beta3 or earlier)
+ * Zend\Mail (for sending the contact emails)
+ * Zend\Module (implements a ZF2 module)
+ * Zend\Mvc (provides a controller)
+ * Zend\Validator (uses the Hostname validator in the contact form when
+ validating email addresses)
+ * Zend\View (provides view scripts for the PhpRenderer, and utilizes
+ ViewModels in the controller)
+
+Installation
+----
+
+Install the module by cloning it into ./vendor/ and enabling it in your
+application.config.php file.
+
+You will need to configure the following:
+
+* The CAPTCHA to use, and any options related to it.
+* The mail transport to use, and any options related to it.
+* If you wish to alter the root path in the site to which the controller will
+ resolve, you will need to override the routing configuration.
+* If you wish to modify the output, you will need to create alternate templates,
+ and configure overrides in your configuration to ensure your versions are
+ used.
+
+Sample configuration for use in your application autoload configuration is
+provided, demonstrating usage of the ReCaptcha CAPTCHA adapter, the SMTP mail
+transport, and setting mail message defaults. This is in
+`config\module.phly-contact.local.config.php`.
+
+License
+----
+
+Copyright (c) 2012, Matthew Weier O'Phinney
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice, this
+ list of conditions and the following disclaimer in the documentation and/or
+ other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -1,5 +1,5 @@
<?php
return array (
- 'Contact\\Controller\\ContactController' => __DIR__ . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Contact' . DIRECTORY_SEPARATOR . 'Controller' . DIRECTORY_SEPARATOR . 'ContactController.php',
- 'Contact\\Form\\ContactForm' => __DIR__ . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Contact' . DIRECTORY_SEPARATOR . 'Form' . DIRECTORY_SEPARATOR . 'ContactForm.php',
+ 'PhlyContact\\Controller\\ContactController' => __DIR__ . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'PhlyContact' . DIRECTORY_SEPARATOR . 'Controller' . DIRECTORY_SEPARATOR . 'ContactController.php',
+ 'PhlyContact\\Form\\ContactForm' => __DIR__ . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'PhlyContact' . DIRECTORY_SEPARATOR . 'Form' . DIRECTORY_SEPARATOR . 'ContactForm.php',
);
View
@@ -1,23 +1,40 @@
<?php
-$config = array(
-'di' => array(
+$config = array('di' => array(
'definition' => array('class' => array(
- 'Contact\Controller\ContactController' => array(
+ 'PhlyContact\Controller\ContactController' => array(
'setContactForm' => array(
+ 'required' => true,
'form' => array(
'required' => true,
- 'type' => 'Contact\Form\ContactForm',
+ 'type' => 'PhlyContact\Form\ContactForm',
+ ),
+ ),
+ 'setMessage' => array(
+ 'required' => true,
+ 'message' => array(
+ 'required' => true,
+ 'type' => 'Zend\Mail\Message',
+ ),
+ ),
+ 'setMailTransport' => array(
+ 'required' => true,
+ 'transport' => array(
+ 'required' => true,
+ 'type' => 'Zend\Mail\Transport',
),
),
),
- 'Contact\Form\ContactForm' => array(
+ 'PhlyContact\Form\ContactForm' => array(
'__construct' => array(
- 'options' => array(
+ 'required' => true,
+ 'captchaAdapter' => array(
'required' => true,
- 'type' => 'Zend\Captcha\ReCaptcha',
+ 'type' => 'Zend\Captcha\Adapter',
),
),
),
+ // The following is provided in order to simplify configuration of a
+ // ReCaptcha adapter.
'Zend\Captcha\ReCaptcha' => array(
'setPrivkey' => array(
'privkey' => array(
@@ -42,6 +59,8 @@
),
),
),
+ // The following is provided in order to allow injection of a To:
+ // address, From: address, and sender.
'Zend\Mail\Message' => array(
'addTo' => array(
'emailOrAddressList' => array(
@@ -76,75 +95,91 @@
),
)),
'instance' => array(
+ // Default preferences are sane defaults; they utilize features that
+ // do not need API keys or other configuration in most cases.
+ 'preferences' => array(
+ 'Zend\Captcha\Adapter' => 'Zend\Captcha\Dumb',
+ 'Zend\Mail\Transport' => 'Zend\Mail\Transport\Sendmail',
+ ),
+
+ // Defaults for mail message... these will clue the end-user in that
+ // they need to override in app configuration.
'Zend\Mail\Message' => array('parameters' => array(
'Zend\Mail\Message::addTo:emailOrAddressList' => 'EMAIL HERE',
'Zend\Mail\Message::addTo:name' => "NAME HERE",
+ 'Zend\Mail\Message::setSender:emailOrAddressList' => 'EMAIL HERE',
+ 'Zend\Mail\Message::setSender:name' => "NAME HERE",
)),
+ // Template map for the two templates we provide for the PhpRenderer
'Zend\View\Resolver\TemplateMapResolver' => array('parameters' => array(
'map' => array(
- 'contact/index' => __DIR__ . '/../view/contact/index.phtml',
- 'contact/thank-you' => __DIR__ . '/../view/contact/thank-you.phtml',
+ 'contact/index' => __DIR__ . '/../view/phly-contact/contact/index.phtml',
+ 'contact/thank-you' => __DIR__ . '/../view/phly-contact/contact/thank-you.phtml',
),
)),
+ // Paths for the TemplatePathStack if used
'Zend\View\Resolver\TemplatePathStack' => array('parameters' => array(
'paths' => array(
- 'contact' => __DIR__ . '/../view',
+ 'contact' => __DIR__ . '/../view/phly-contact',
),
)),
- 'Contact\Controller\ContactController' => array('parameters' => array(
+ // Injection points for the controller
+ 'PhlyContact\Controller\ContactController' => array('parameters' => array(
'message' => 'Zend\Mail\Message',
- 'form' => 'Contact\Form\ContactForm',
+ 'transport' => 'Zend\Mail\Transport',
+ 'form' => 'PhlyContact\Form\ContactForm',
)),
- 'Contact\Form\ContactForm' => array('parameters' => array(
- 'recaptcha' => 'Zend\Captcha\ReCaptcha',
+ // Injection points for the form
+ 'PhlyContact\Form\ContactForm' => array('parameters' => array(
+ 'captchaAdapter' => 'Zend\Captcha\Adapter',
)),
+ // If using a ReCaptcha, define these
'Zend\Captcha\ReCaptcha' => array('parameters' => array(
'pubkey' => 'RECAPTCHA_PUBKEY_HERE',
'privkey' => 'RECAPTCHA_PRIVKEY_HERE',
)),
+ // Routes
'Zend\Mvc\Router\RouteStack' => array('parameters' => array(
'routes' => array(
- 'contact-form' => array(
+ 'contact' => array(
'type' => 'Literal',
'options' => array(
'route' => '/contact',
'defaults' => array(
- 'controller' => 'Contact\Controller\ContactController',
+ 'controller' => 'PhlyContact\Controller\ContactController',
'action' => 'index',
),
),
- ),
-
- 'contact-process' => array(
- 'type' => 'Literal',
- 'options' => array(
- 'route' => '/contact/process',
- 'defaults' => array(
- 'controller' => 'Contact\Controller\ContactController',
- 'action' => 'process',
+ 'may_terminate' => true,
+ 'child_routes' => array(
+ 'process' => array(
+ 'type' => 'Literal',
+ 'options' => array(
+ 'route' => '/process',
+ 'defaults' => array(
+ 'action' => 'process',
+ ),
+ ),
),
- ),
- ),
-
- 'contact-thank-you' => array(
- 'type' => 'Literal',
- 'options' => array(
- 'route' => '/contact/thank-you',
- 'defaults' => array(
- 'controller' => 'Contact\Controller\ContactController',
- 'action' => 'thank-you',
+ 'thank-you' => array(
+ 'type' => 'Literal',
+ 'options' => array(
+ 'route' => '/thank-you',
+ 'defaults' => array(
+ 'action' => 'thank-you',
+ ),
+ ),
),
),
),
),
)),
),
-),
-);
+));
return $config;
@@ -1,83 +0,0 @@
-<?php
-$config['production'] = array(
- 'di' => array('instance' => array(
- 'alias' => array(
- 'contact-contact' => 'Contact\Controller\ContactController',
- ),
-
- 'preferences' => array(
- 'Zend\Mail\AbstractTransport' => 'Zend\Mail\Transport\Smtp',
- ),
-
- 'Zend\Mail\Mail' => array('methods' => array(
- 'addTo' => array(
- 'email' => 'your@emailhe.re',
- 'name' => "Your Name Here",
- ),
- )),
-
- 'Zend\Mail\Transport\Smtp' => array('methods' => array(
- '__construct' => array(
- 'host' => 'localhost',
- 'config' => array(
- 'port' => 25,
- ),
- ),
- )),
-
- 'Zend\View\PhpRenderer' => array(
- 'methods' => array(
- 'setResolver' => array(
- 'resolver' => 'Zend\View\TemplatePathStack',
- 'options' => array(
- 'script_paths' => array(
- 'contact' => __DIR__ . '/../views',
- ),
- ),
- ),
- ),
- ),
-
- 'Contact\Controller\ContactController' => array('parameters' => array(
- 'mailer' => 'Zend\Mail\Mail',
- 'transport' => 'Zend\Mail\Transport\Smtp',
- )),
- )),
-
- 'routes' => array(
- 'contact-form' => array(
- 'type' => 'Zend\Mvc\Router\Http\Literal',
- 'options' => array(
- 'route' => '/contact',
- 'defaults' => array(
- 'controller' => 'contact-contact',
- 'action' => 'index',
- ),
- ),
- ),
- 'contact-process' => array(
- 'type' => 'Zend\Mvc\Router\Http\Literal',
- 'options' => array(
- 'route' => '/contact/process',
- 'defaults' => array(
- 'controller' => 'contact-contact',
- 'action' => 'process',
- ),
- ),
- ),
- 'contact-thank-you' => array(
- 'type' => 'Zend\Mvc\Router\Http\Literal',
- 'options' => array(
- 'route' => '/contact/thank-you',
- 'defaults' => array(
- 'controller' => 'contact-contact',
- 'action' => 'thank-you',
- ),
- ),
- ),
- ),
-);
-$config['staging'] = $config['production'];
-$config['testing'] = $config['production'];
-$config['development'] = $config['production'];
-return $config;
Oops, something went wrong.

0 comments on commit 1a35570

Please sign in to comment.