/** * Constructor. * * @param array $opts Additional configuration options: * <pre> * - string: (string) [REQUIRED] The PHP string. * </pre> * * @throws InvalidArgumentException */ public function __construct(array $opts = array()) { if (!isset($opts['string']) || !is_string($opts['string'])) { throw new InvalidArgumentException('Need a PHP string.'); } $this->stream = Horde_Stream_Wrapper_String::getStream($opts['string']); unset($opts['string']); parent::__construct($opts); }
public function testMemoryUsage() { $bytes = 1024 * 1024; $string = str_repeat('*', $bytes); $memoryUsage = memory_get_usage(); $stream = Horde_Stream_Wrapper_String::getStream($string); $memoryUsage2 = memory_get_usage(); $this->assertLessThan($memoryUsage + $bytes, $memoryUsage2); while (!feof($stream)) { fread($stream, 1024); } $memoryUsage3 = memory_get_usage(); $this->assertLessThan($memoryUsage + $bytes, $memoryUsage3); }
/** * Retrieves a bodypart for the given message ID and mime part ID. * * @param string $folder The folder to fetch the messages from. * @param array $uid The message UID. * @param array $id The mime part ID. * * @return resource The body part, as a stream resource. */ public function fetchBodypart($folder, $uid, $id) { $this->select($folder); return Horde_Stream_Wrapper_String::getStream(Horde_Kolab_Storage_Exception_Pear::catchError($this->getBackend()->getBodyPart($uid, $id, true))); }
/** * Stores an object in the Kolab message store. * * TODO * * @return string The object id, possibly updated. * @throws Turba_Exception */ protected function _store($attributes, $object_id = null) { if (isset($attributes['__type']) && $attributes['__type'] == 'Group') { $this->_convertMembers($attributes); $data = $this->_getListData(); } else { if (isset($attributes['photo']) && isset($attributes['phototype'])) { $filename = 'photo.' . Horde_Mime_Magic::mimeToExt($attributes['phototype']); $attributes['_attachments'][$filename] = array('type' => $attributes['phototype'], 'content' => Horde_Stream_Wrapper_String::getStream($attributes['photo'])); $attributes['picture'] = $filename; unset($attributes['photo'], $attributes['phototype']); } // EAS sets the date fields to '' instead of null -> fix it up $fix_date_fields = array('birthday', 'anniversary'); foreach ($fix_date_fields as $fix_date) { if (empty($attributes[$fix_date])) { unset($attributes[$fix_date]); } } $data = $this->_getData(); } if ($object_id === null) { $object_id = $data->create($attributes); } else { $data->modify($attributes); } /* Invalidate cache. */ $this->_connected = false; return Horde_Url::uriB64Encode($object_id); }
/** * Retrieve an attachment. * * @param string $data_id ID of the data set. * @param string $obid Object backend id. * @param string $attachment_id Attachment ID. * * @return resource A stream opened to the attachment data. */ public function loadAttachment($data_id, $obid, $attachment_id) { $data = $this->horde_cache->get($this->_getAttachmentId($data_id, $obid, $attachment_id), 0); return $data === false ? $data : Horde_Stream_Wrapper_String::getStream($data); }
/** * Retrieves a bodypart for the given message ID and mime part ID. * * @param string $folder The folder to fetch the messages from. * @param array $uid The message UID. * @param array $id The mime part ID. * * @return resource The body part, as a stream resource. */ public function fetchBodypart($folder, $uid, $id) { $this->select($folder); $result = @imap_fetchbody($this->getBackend(), $uid, $id, FT_UID); if (!$result) { throw new Horde_Kolab_Storage_Exception(sprintf(Horde_Kolab_Storage_Translation::t("Failed fetching body part %s for message %s in folder %s.") . ' ' . Horde_Kolab_Storage_Translation::t("Error: %s"), $id, $uid, $this->_getBaseMbox() . $folder, imap_last_error())); } return Horde_Stream_Wrapper_String::getStream($result); }
private function _getSyncedCacheWithAttachment($data) { $resource = Horde_Stream_Wrapper_String::getStream($data); $cache = $this->getMockDataCache(); $cache->store(array('100' => array('uid' => 'test', '_attachments' => array('1' => array('name' => 'test.txt', 'type' => 'application/x-vnd.kolab.event', 'content' => $resource), '2' => array('type' => 'application/x-vnd.kolab.event', 'content' => $resource), '3' => array('name' => 'test.txt', 'type' => 'application/x-vnd.kolab.event', 'content' => $resource), '4' => array('content' => $resource)))), new Horde_Kolab_Storage_Folder_Stamp_Uids('c', 'd'), '2'); return $cache; }