Add Zend_Io package proposal
git-svn-id: http://php-reader.googlecode.com/svn/branches/zend@151 51a70ab9-7547-0410-9469-37e369ee0574
This commit is contained in:
67
src/Zend/Io/StringWriter.php
Normal file
67
src/Zend/Io/StringWriter.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Io
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**#@+ @ignore */
|
||||
require_once 'Zend/Io/Writer.php';
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* The Zend_Io_StringWriter represents a character stream whose source is
|
||||
* a string.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Io
|
||||
* @author Sven Vollbehr <sven@vollbehr.eu>
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
class Zend_Io_StringWriter extends Zend_Io_Writer
|
||||
{
|
||||
/**
|
||||
* Constructs the Zend_Io_StringWriter class with given source string.
|
||||
*
|
||||
* @param string $data The string to use as the source.
|
||||
* @throws Zend_Io_Exception if an I/O error occurs
|
||||
*/
|
||||
public function __construct($data = null)
|
||||
{
|
||||
if (($this->_fd = fopen('php://memory', 'w+b')) === false) {
|
||||
require_once('Zend/Io/Exception.php');
|
||||
throw new Zend_Io_Exception('Unable to open php://memory stream');
|
||||
}
|
||||
if ($data !== null && is_string($data)) {
|
||||
if (($this->_size = fwrite($this->_fd, $data, $tagSize)) === false) {
|
||||
require_once('Zend/Io/Exception.php');
|
||||
throw new Zend_Io_Exception('Unable to write data to php://memory stream');
|
||||
}
|
||||
fseek($this->_fd, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the file descriptor.
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$this->close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user