/framework/vendor/zend/Zend/Pdf/FileParserDataSource/String.php
PHP | 128 lines | 39 code | 16 blank | 73 comment | 2 complexity | fdd78e14ab43cb42d737b6b0cbb634e9 MD5 | raw file
1<?php 2/** 3 * Zend Framework 4 * 5 * LICENSE 6 * 7 * This source file is subject to the new BSD license that is bundled 8 * with this package in the file LICENSE.txt. 9 * It is also available through the world-wide-web at this URL: 10 * http://framework.zend.com/license/new-bsd 11 * If you did not receive a copy of the license and are unable to 12 * obtain it through the world-wide-web, please send an email 13 * to license@zend.com so we can send you a copy immediately. 14 * 15 * @category Zend 16 * @package Zend_Pdf 17 * @subpackage FileParser 18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 19 * @license http://framework.zend.com/license/new-bsd New BSD License 20 * @version $Id: String.php 20096 2010-01-06 02:05:09Z bkarwin $ 21 */ 22 23/** Zend_Pdf_FileParserDataSource */ 24require_once 'Zend/Pdf/FileParserDataSource.php'; 25 26/** 27 * Concrete subclass of {@link Zend_Pdf_FileParserDataSource} that provides an 28 * interface to binary strings. 29 * 30 * @package Zend_Pdf 31 * @subpackage FileParser 32 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 33 * @license http://framework.zend.com/license/new-bsd New BSD License 34 */ 35class Zend_Pdf_FileParserDataSource_String extends Zend_Pdf_FileParserDataSource 36{ 37 /**** Instance Variables ****/ 38 39 40 /** 41 * The string to parse. 42 * @var string 43 */ 44 protected $_string = ''; 45 46 47 48 /**** Public Interface ****/ 49 50 51 /* Concrete Class Implementation */ 52 53 /** 54 * Object constructor. 55 * 56 * Verifies that the string is not empty. 57 * 58 * @param string $string String to parse. 59 */ 60 public function __construct($string) 61 { 62 if (empty($string)) { 63 require_once 'Zend/Pdf/Exception.php'; 64 throw new Zend_Pdf_Exception('String is empty', 65 Zend_Pdf_Exception::PARAMETER_VALUE_OUT_OF_RANGE); 66 } 67 $this->_size = strlen($string); 68 $this->_string = $string; 69 } 70 71 /** 72 * Object destructor. 73 */ 74 public function __destruct() 75 { 76 $this->_string = ''; 77 } 78 79 /** 80 * Returns the specified number of raw bytes from the string at the byte 81 * offset of the current read position. 82 * 83 * Advances the read position by the number of bytes read. 84 * 85 * Throws an exception if there is insufficient data to completely fulfill 86 * the request. 87 * 88 * @param integer $byteCount Number of bytes to read. 89 * @return string 90 * @throws Zend_Pdf_Exception 91 */ 92 public function readBytes($byteCount) 93 { 94 if (($this->_offset + $byteCount) > $this->_size) { 95 require_once 'Zend/Pdf/Exception.php'; 96 throw new Zend_Pdf_Exception("Insufficient data to read $byteCount bytes", 97 Zend_Pdf_Exception::INSUFFICIENT_DATA); 98 } 99 $bytes = substr($this->_string, $this->_offset, $byteCount); 100 $this->_offset += $byteCount; 101 return $bytes; 102 } 103 104 /** 105 * Returns the entire string. 106 * 107 * Preserves the current read position. 108 * 109 * @return string 110 */ 111 public function readAllBytes() 112 { 113 return $this->_string; 114 } 115 116 117 /* Object Magic Methods */ 118 119 /** 120 * Returns a string containing the parsed string's length. 121 * 122 * @return string 123 */ 124 public function __toString() 125 { 126 return "String ($this->_size bytes)"; 127 } 128}