| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Copyright (c) 2011-2012 Andreas Heigl<[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a copy | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * of this software and associated documentation files (the "Software"), to deal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * in the Software without restriction, including without limitation the rights | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * copies of the Software, and to permit persons to whom the Software is | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * furnished to do so, subject to the following conditions: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * The above copyright notice and this permission notice shall be included in | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * all copies or substantial portions of the Software. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * THE SOFTWARE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @category  ContactForm | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * @package   HeiglContact | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * @author    Andreas Heigl<[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * @copyright 2011-2012 Andreas Heigl | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * @license   http://www.opesource.org/licenses/mit-license.php MIT-License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * @version   0.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  * @since     06.03.2012 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * @link      http://github.com/heiglandreas/php.ug | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | namespace Org_Heigl\Contact\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | use Zend\Mvc\Controller\AbstractActionController; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | use Zend\Mail\Transport\TransportInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | use Org_Heigl\Contact\Form\ContactForm; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | use Zend\Mail\Message as Message; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | use Zend\View\Model\ViewModel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  * The Contact-Form Controller | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  * @category  ContactForm | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  * @package   OrgHeiglContact | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  * @author    Andreas Heigl<[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  * @copyright 2011-2012 Andreas Heigl | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  * @license   http://www.opensource.org/licenses/mit-license.php MIT-License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  * @version   0.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  * @since     06.03.2012 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  * @link      http://github.com/heiglandreas/OrgHeiglContact | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | class ContactController extends AbstractActionController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * THe storage of the form-object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @var ContactForm $form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     protected $form; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * Storage of the message | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * @var Message $message | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     protected $message = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * Storage of the default transport | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @var Transport $transport | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     protected $transport = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * Create the Controller-Instance | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * @param ContactForm $form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     public function __construct(ContactForm $form = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         if (null !== $form) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |              $this->setContactForm($form); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * Set the default message | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @param Message $message the message to set as default | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      * @return ContactController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     public function setMessage(Message $message) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         $this->message = $message; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      * Set the default transport | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      * @param Transport $transport The transport to set as default | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      * @return ContactController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     public function setTransport(TransportInterface $transport) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         $this->transport = $transport; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      * Set the given form as contact-form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      * @param ContactForm $form | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |      * @return ContactController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     public function setContactForm(ContactForm $contactForm) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         $this->form = $contactForm; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         $this->form->init(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |      * Display a contact-form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     public function indexAction() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |         return array('form' => $this->form); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |      * Process the form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     public function processAction() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |         if (!$this->request->isPost()) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |             return $this->redirect()->toRoute('contact'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         $post = $this->request->getPost(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         $form = $this->form; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         $form->setData($post); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |         if (!$form->isValid()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |             $view = new ViewModel(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |                         'error' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |                         'form'  => $form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |             )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |             $view->setTemplate('org_heigl/contact/contact/index'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |             return $view; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |         // send email... | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |         $this->sendEmail($form->getData()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |         return $this->redirect()->toRoute('contact/thank-you'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |      * Send the email | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |      * @param array $params The parameters to include in the email | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |      * @return boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |     protected function sendEmail($values) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |         $from    = $values['from']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |         $subject = '[Contact Form] ' . $values['subject']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |         $body    = $values['body']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |         $this->message->addFrom($from) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |                       ->addReplyTo($from) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |                       ->setSubject($subject) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |                       ->setBody($body); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |         $this->transport->send($this->message); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |      * Display a thank-you message | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |      * @return void | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 191 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 192 |  |  |     public function thankYouAction() | 
            
                                                        
            
                                    
            
            
                | 193 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 194 |  |  |         $headers = $this->request->getHeaders(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 195 |  |  |         if (!$headers->has('Referer') | 
            
                                                        
            
                                    
            
            
                | 196 |  |  |             || !preg_match('#/contact$#', | 
            
                                                        
            
                                    
            
            
                | 197 |  |  |         $headers->get('Referer')->getFieldValue()) | 
            
                                                        
            
                                    
            
            
                | 198 |  |  |         ) { | 
            
                                                        
            
                                    
            
            
                | 199 |  |  |             return $this->redirect()->toRoute('contact'); | 
            
                                                        
            
                                    
            
            
                | 200 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 201 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 202 |  |  |         return array(); | 
            
                                                        
            
                                    
            
            
                | 203 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 204 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 205 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 206 |  |  |  | 
            
                        
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..