Ejemplo n.º 1
0
 /**
  * prepare parts of message
  * @throws Exception
  */
 protected function _prepareParts()
 {
     //
     $headerSize = self::HEADER_SIZE;
     $max = Helper::getLimit('normal');
     if ($this->_isUnicode) {
         // max length sms to unicode
         $max = Helper::getLimit('unicode');
         // can't compress message
         $this->getPdu()->getDcs()->setTextCompressed(FALSE)->setTextAlphabet(DCS::ALPHABET_UCS2);
         // type alphabet is UCS2
     }
     // if message is compressed
     if ($this->getPdu()->getDcs()->getTextCompressed()) {
         $max = Helper::getLimit('compress');
         $headerSize++;
     }
     $parts = $this->_splitMessage($max, $headerSize);
     $header = count($parts) > 1;
     $uniqid = rand(0, 65535);
     // message will be splited, need headers
     if ($header) {
         $this->getPdu()->getType()->setUdhi(1);
     }
     foreach ($parts as $index => $text) {
         $params = $header ? array('SEGMENTS' => count($parts), 'CURRENT' => $index + 1, 'POINTER' => $uniqid) : NULL;
         $part = NULL;
         $size = 0;
         switch ($this->getPdu()->getDcs()->getTextAlphabet()) {
             case DCS::ALPHABET_DEFAULT:
                 PDU::debug("Helper::encode7bit()");
                 list($size, $part) = Helper::encode7bit($text);
                 break;
             case DCS::ALPHABET_8BIT:
                 PDU::debug("Helper::encode8BitMessage()");
                 list($size, $part) = Helper::encode8Bit($text);
                 break;
             case DCS::ALPHABET_UCS2:
                 PDU::debug("Helper::encode16BitMessage()");
                 list($size, $part) = Helper::encode16Bit($text);
                 break;
             default:
                 throw new Exception("Unknown alphabet");
         }
         if ($header) {
             $size += $headerSize;
         }
         $this->_parts[] = new Data\Part($this, $part, $size, $params);
     }
 }