Esempio n. 1
0
 public function assignArrayToObject(Category $object, $data)
 {
     $targetForum = $this->forumManager->find($data["targetForum"]);
     $object->setName($data["name"]);
     $object->setImage($data["image"]);
     $object->setTargetForum($targetForum);
     $sources = $object->getSources();
     $newSourceIds = array();
     foreach ($data["sources"] as $sourceData) {
         $newSource = null;
         $oldSourceId = null;
         foreach ($sources as $source) {
             if ($sourceData["id"] == $source->getId()) {
                 $newSource = $source;
                 $newSourceIds[] = $newSource->getId();
                 break;
             }
         }
         if ($sourceData["type"] == "email") {
             if (!$newSource instanceof Category\Source\Email) {
                 if ($newSource) {
                     $this->em->remove($newSource);
                 }
                 $newSource = new Category\Source\Email();
             }
             $newSource->setServer($sourceData["server"]);
             $newSource->setUsername($sourceData["username"]);
             $newSource->setPassword($sourceData["password"]);
             $newSource->setSsl((bool) $sourceData["ssl"]);
             $newSource->setPort($sourceData["port"]);
         } else {
             if ($sourceData["type"] == "feed") {
                 if (!$newSource instanceof Category\Source\Feed) {
                     if ($newSource) {
                         $this->em->remove($newSource);
                     }
                     $newSource = new Category\Source\Feed();
                 }
                 $newSource->setUrl($sourceData["url"]);
             }
         }
         if ($newSource) {
             $newSource->setName($sourceData["name"]);
             $newSource->setCategory($object);
             $this->em->persist($newSource);
         }
     }
     // remove old
     foreach ($sources as $source) {
         if (!in_array($source->getId(), $newSourceIds)) {
             if ($source) {
                 $this->em->remove($source);
             }
         }
     }
     return $object;
 }
Esempio n. 2
0
 protected function getEmailConnection(Category\Source\Email $source)
 {
     if ($source->isSsl()) {
         $flags = "/imap/ssl/validate-cert";
     } else {
         if ($source->getPort() == 143) {
             $flags = "/imap/notls";
         } else {
             $flags = "/imap/ssl/novalidate-cert";
         }
     }
     $serverString = sprintf('{%s:%s%s}INBOX', $source->getServer(), $source->getPort(), $flags);
     $resource = imap_open($serverString, $source->getUsername(), $source->getPassword(), null, 1, array());
     if (false === $resource) {
         throw new AuthenticationFailedException($source->getUsername());
     }
     $check = imap_check($resource);
     $mailbox = $check->Mailbox;
     $connection = substr($mailbox, 0, strpos($mailbox, '}') + 1);
     $connection = new Connection($resource, $connection);
     return $connection;
 }