File indexing completed on 2024-06-16 05:30:17

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Pdf
0017  * @subpackage FileParser
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /** Zend_Pdf_FileParserDataSource */
0024 // require_once 'Zend/Pdf/FileParserDataSource.php';
0025 
0026 /**
0027  * Concrete subclass of {@link Zend_Pdf_FileParserDataSource} that provides an
0028  * interface to binary strings.
0029  *
0030  * @package    Zend_Pdf
0031  * @subpackage FileParser
0032  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0033  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0034  */
0035 class Zend_Pdf_FileParserDataSource_String extends Zend_Pdf_FileParserDataSource
0036 {
0037   /**** Instance Variables ****/
0038 
0039 
0040     /**
0041      * The string to parse.
0042      * @var string
0043      */
0044     protected $_string = '';
0045 
0046 
0047 
0048   /**** Public Interface ****/
0049 
0050 
0051   /* Concrete Class Implementation */
0052 
0053     /**
0054      * Object constructor.
0055      *
0056      * Verifies that the string is not empty.
0057      *
0058      * @param string $string String to parse.
0059      */
0060     public function __construct($string)
0061     {
0062         if (empty($string)) {
0063             // require_once 'Zend/Pdf/Exception.php';
0064             throw new Zend_Pdf_Exception('String is empty',
0065                                          Zend_Pdf_Exception::PARAMETER_VALUE_OUT_OF_RANGE);
0066         }
0067         $this->_size = strlen($string);
0068         $this->_string = $string;
0069     }
0070 
0071     /**
0072      * Object destructor.
0073      */
0074     public function __destruct()
0075     {
0076         $this->_string = '';
0077     }
0078 
0079     /**
0080      * Returns the specified number of raw bytes from the string at the byte
0081      * offset of the current read position.
0082      *
0083      * Advances the read position by the number of bytes read.
0084      *
0085      * Throws an exception if there is insufficient data to completely fulfill
0086      * the request.
0087      *
0088      * @param integer $byteCount Number of bytes to read.
0089      * @return string
0090      * @throws Zend_Pdf_Exception
0091      */
0092     public function readBytes($byteCount)
0093     {
0094         if (($this->_offset + $byteCount) > $this->_size) {
0095             // require_once 'Zend/Pdf/Exception.php';
0096             throw new Zend_Pdf_Exception("Insufficient data to read $byteCount bytes",
0097                                          Zend_Pdf_Exception::INSUFFICIENT_DATA);
0098         }
0099         $bytes = substr($this->_string, $this->_offset, $byteCount);
0100         $this->_offset += $byteCount;
0101         return $bytes;
0102     }
0103 
0104     /**
0105      * Returns the entire string.
0106      *
0107      * Preserves the current read position.
0108      *
0109      * @return string
0110      */
0111     public function readAllBytes()
0112     {
0113         return $this->_string;
0114     }
0115 
0116 
0117   /* Object Magic Methods */
0118 
0119     /**
0120      * Returns a string containing the parsed string's length.
0121      *
0122      * @return string
0123      */
0124     public function __toString()
0125     {
0126         return "String ($this->_size bytes)";
0127     }
0128 }