/**
  * Private method inserts the purchase record and clears the tracking cookie.
  * 
  * The method will cancel the purchase operation if the email address is not valid and will write a 
  * notice message to the application log.
  *  
  * @param \Application\Controller\Document $oDocument
  * @param string $mEmail
  * @return bool
  */
 private function doPurchase(Document $oDocument, $mEmail)
 {
     //Grab componenets from the DI contained
     $oPurchaseDao = $this->getServiceLocator()->get('PurchaseTable');
     $oTracker = $this->getServiceLocator()->get('DocumentTracker');
     $oLog = $this->getServiceLocator()->get('AppLog');
     $oEmailFilter = $this->getServiceLocator()->get('EmailFilter');
     $oValidator = $this->getServiceLocator()->get('EmailValidator');
     //Filter the email address received from the form input.
     $sEmail = $oEmailFilter->filter($mEmail);
     //Check if the email is of a valid format
     if ($oValidator->isValid($sEmail)) {
         $oPurchase = new Purchase();
         $oPurchase->setEmail($sEmail);
         $oPurchase->setDocument($oDocument);
         //Store the purchase record in the database.
         $oPurchaseDao->insert($oPurchase);
         $oLog->info('Document purchased');
         //clear the tracking cookie
         $oTracker->deleteCookie();
         return true;
     } else {
         //Add a message to the application log if an invalid email is found.
         $oLog->log(Logger::NOTICE, 'Invalid email detected during purchase');
     }
     return false;
 }
Esempio n. 2
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testAttachUnPersistedDocument()
 {
     $oDocument = new Document();
     $oDocument->setTitle('Foobar');
     $oDocument->setInfo('Foobar, Foobar, Foobar');
     $oPurchase = new Purchase();
     $oPurchase->setEmail('*****@*****.**');
     $oPurchase->setDocument($oDocument);
 }