public function send(MessageInterface $message, $skipErrors = true) {
        $this->clearErrors();

        $storePath = $this->getParam('store_path');
        if (empty($storePath)) {
            throw new ConfigurationException(__CLASS__ . ' is not configured properly. Please set "store_path" parameter.');
        }

        $pathChmod = $this->getParam('path_chmod');
        $dir = realpath($storePath);
        if (!is_dir($dir)) {
            if (!mkdir($storePath, $pathChmod, true)) {
                return false;
            }
        }

        $format = $this->getParam('format');
        foreach ($message->getRecipient() as $recipient) {
            $savePath = $storePath . DIRECTORY_SEPARATOR . $this->getFileName($recipient);
            $content = sprintf($format, $recipient, $message->getText());

            $return = file_put_contents($savePath, $content);
            if($return === false) {
                $errorMsg = sprintf("Error while saving file \"%s\" with SMS message.", $savePath);
                $this->addError(new SendingError($recipient, self::ERROR_NOT_SAVED, $errorMsg));
                if (!$skipErrors){
                    throw new RuntimeException($errorMsg, self::ERROR_NOT_SAVED);
                }
            }
        }
        return $this->getErrors()->count() > 0;
    }
public function send(MessageInterface $message, $skipErrors = true) {
        $this->clearErrors();

        $storePath = $this->getParam('store_path');
        if (empty($storePath)) {
            throw new ConfigurationException(__CLASS__ . ' is not configured properly. Please set "store_path" parameter.');
        }

        $pathChmod = $this->getParam('path_chmod');
        $dir = realpath($storePath);
        if (!is_dir($dir)) {
            if (!mkdir($storePath, $pathChmod, true)) {
                return false;
            }
        }

        $format = $this->getParam('format');
        foreach ($message->getRecipient() as $recipient) {
            $savePath = $storePath . DIRECTORY_SEPARATOR . $this->getFileName($recipient);
            $content = sprintf($format, $recipient, $message->getText());

            $return = file_put_contents($savePath, $content);
            if($return === false) {
                $errorMsg = sprintf("Error while saving file \"%s\" with SMS message.", $savePath);
                $this->addError(new SendingError($recipient, self::ERROR_NOT_SAVED, $errorMsg));
                if (!$skipErrors){
                    throw new RuntimeException($errorMsg, self::ERROR_NOT_SAVED);
                }
            }
        }
        return $this->getErrors()->count() > 0;
    }
public function send ( MessageInterface $ message , $ skipErrors = true ) { $ this -> clearErrors ( ) ; $ storePath = $ this -> getParam ( 'store_path' ) ; if ( empty ( $ storePath ) ) { throw new ConfigurationException ( __CLASS__ . ' is not configured properly. Please set "store_path" parameter.' ) ; } $ pathChmod = $ this -> getParam ( 'path_chmod' ) ; $ dir = realpath ( $ storePath ) ; if ( ! is_dir ( $ dir ) ) { if ( ! mkdir ( $ storePath , $ pathChmod , true ) ) { return false ; } } $ format = $ this -> getParam ( 'format' ) ; foreach ( $ message -> getRecipient ( ) as $ recipient ) { $ savePath = $ storePath . DIRECTORY_SEPARATOR . $ this -> getFileName ( $ recipient ) ; $ content = sprintf ( $ format , $ recipient , $ message -> getText ( ) ) ; $ return = file_put_contents ( $ savePath , $ content ) ; if ( $ return === false ) { $ errorMsg = sprintf ( "Error while saving file \"%s\" with SMS message." , $ savePath ) ; $ this -> addError ( new SendingError ( $ recipient , self :: ERROR_NOT_SAVED , $ errorMsg ) ) ; if ( ! $ skipErrors ) { throw new RuntimeException ( $ errorMsg , self :: ERROR_NOT_SAVED ) ; } } } return $ this -> getErrors ( ) -> count ( ) > 0 ; }
Save message in file
@param SmsMessageModel $message
@return bool
Save message in file