protected final function initializeBase($data, $params = array()) { if (is_null($this->headers)) { $this->headers = new Header(); } if (is_array($data)) { $this->path = $data; } elseif ($data) { // do nothing // content : default is file if (isset($params['is_file']) && $params['is_file'] === false) { $file = Adapter::getTempFilename(); file_put_contents($file, $data); $this->path = $file; // filename if (isset($params['filename'])) { $this->filename = $params['filename']; } } else { $this->path = $data; // filename $this->filename = isset($params['filename']) ? $params['filename'] : basename($this->path); } // mimetype handle $this->mimetype = isset($params['mimetype']) ? $params['mimetype'] : Adapter::detectMimeType($this->path); } // partners if (isset($params['partner_from']) && $params['partner_from']) { $this->setPartnerFrom($params['partner_from']); } else { throw new AS2Exception('No AS2 From Partner specified.'); } if (isset($params['partner_to']) && $params['partner_to']) { $this->setPartnerTo($params['partner_to']); } else { throw new AS2Exception('NO AS2 To Partner specified.'); } $this->adapter = $this->getAdapterFactory()->build($this->getPartnerFrom(), $this->getPartnerTo()); }
/** * Add file to the message * * @param string $data The content or the file * @param string $mimetype The mimetype of the message * @param boolean $is_file If file * @param string $encoding The encoding to use for transfert * * @return boolean */ public function addFile($data, $mimetype = '', $filename = '', $is_file = true, $encoding = 'base64') { if (!$is_file) { $file = Adapter::getTempFilename(); file_put_contents($file, $data); $data = $file; $is_file = true; } else { if (!$filename) { $filename = basename($data); } } if (!$mimetype) { $mimetype = Adapter::detectMimeType($data); } $this->files[] = array('path' => $data, 'mimetype' => $mimetype, 'filename' => $filename, 'encoding' => $encoding); return true; }