wp/wp-includes/pomo/streams.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     7  * @package pomo
     7  * @package pomo
     8  * @subpackage streams
     8  * @subpackage streams
     9  */
     9  */
    10 
    10 
    11 if ( ! class_exists( 'POMO_Reader', false ) ) :
    11 if ( ! class_exists( 'POMO_Reader', false ) ) :
       
    12 	#[AllowDynamicProperties]
    12 	class POMO_Reader {
    13 	class POMO_Reader {
    13 
    14 
    14 		public $endian = 'little';
    15 		public $endian = 'little';
    15 		public $_post  = '';
    16 		public $_pos;
       
    17 		public $is_overloaded;
    16 
    18 
    17 		/**
    19 		/**
    18 		 * PHP5 constructor.
    20 		 * PHP5 constructor.
    19 		 */
    21 		 */
    20 		public function __construct() {
    22 		public function __construct() {
    56 		 * @return mixed The integer, corresponding to the next 32 bits from
    58 		 * @return mixed The integer, corresponding to the next 32 bits from
    57 		 *  the stream of false if there are not enough bytes or on error
    59 		 *  the stream of false if there are not enough bytes or on error
    58 		 */
    60 		 */
    59 		public function readint32() {
    61 		public function readint32() {
    60 			$bytes = $this->read( 4 );
    62 			$bytes = $this->read( 4 );
    61 			if ( 4 != $this->strlen( $bytes ) ) {
    63 			if ( 4 !== $this->strlen( $bytes ) ) {
    62 				return false;
    64 				return false;
    63 			}
    65 			}
    64 			$endian_letter = ( 'big' === $this->endian ) ? 'N' : 'V';
    66 			$endian_letter = ( 'big' === $this->endian ) ? 'N' : 'V';
    65 			$int           = unpack( $endian_letter, $bytes );
    67 			$int           = unpack( $endian_letter, $bytes );
    66 			return reset( $int );
    68 			return reset( $int );
    73 		 * @return mixed Array of integers or false if there isn't
    75 		 * @return mixed Array of integers or false if there isn't
    74 		 *  enough data or on error
    76 		 *  enough data or on error
    75 		 */
    77 		 */
    76 		public function readint32array( $count ) {
    78 		public function readint32array( $count ) {
    77 			$bytes = $this->read( 4 * $count );
    79 			$bytes = $this->read( 4 * $count );
    78 			if ( 4 * $count != $this->strlen( $bytes ) ) {
    80 			if ( 4 * $count !== $this->strlen( $bytes ) ) {
    79 				return false;
    81 				return false;
    80 			}
    82 			}
    81 			$endian_letter = ( 'big' === $this->endian ) ? 'N' : 'V';
    83 			$endian_letter = ( 'big' === $this->endian ) ? 'N' : 'V';
    82 			return unpack( $endian_letter . $count, $bytes );
    84 			return unpack( $endian_letter . $count, $bytes );
    83 		}
    85 		}
    84 
    86 
    85 		/**
    87 		/**
    86 		 * @param string $string
    88 		 * @param string $input_string
    87 		 * @param int    $start
    89 		 * @param int    $start
    88 		 * @param int    $length
    90 		 * @param int    $length
    89 		 * @return string
    91 		 * @return string
    90 		 */
    92 		 */
    91 		public function substr( $string, $start, $length ) {
    93 		public function substr( $input_string, $start, $length ) {
    92 			if ( $this->is_overloaded ) {
    94 			if ( $this->is_overloaded ) {
    93 				return mb_substr( $string, $start, $length, 'ascii' );
    95 				return mb_substr( $input_string, $start, $length, 'ascii' );
    94 			} else {
    96 			} else {
    95 				return substr( $string, $start, $length );
    97 				return substr( $input_string, $start, $length );
    96 			}
    98 			}
    97 		}
    99 		}
    98 
   100 
    99 		/**
   101 		/**
   100 		 * @param string $string
   102 		 * @param string $input_string
   101 		 * @return int
   103 		 * @return int
   102 		 */
   104 		 */
   103 		public function strlen( $string ) {
   105 		public function strlen( $input_string ) {
   104 			if ( $this->is_overloaded ) {
   106 			if ( $this->is_overloaded ) {
   105 				return mb_strlen( $string, 'ascii' );
   107 				return mb_strlen( $input_string, 'ascii' );
   106 			} else {
   108 			} else {
   107 				return strlen( $string );
   109 				return strlen( $input_string );
   108 			}
   110 			}
   109 		}
   111 		}
   110 
   112 
   111 		/**
   113 		/**
   112 		 * @param string $string
   114 		 * @param string $input_string
   113 		 * @param int    $chunk_size
   115 		 * @param int    $chunk_size
   114 		 * @return array
   116 		 * @return array
   115 		 */
   117 		 */
   116 		public function str_split( $string, $chunk_size ) {
   118 		public function str_split( $input_string, $chunk_size ) {
   117 			if ( ! function_exists( 'str_split' ) ) {
   119 			if ( ! function_exists( 'str_split' ) ) {
   118 				$length = $this->strlen( $string );
   120 				$length = $this->strlen( $input_string );
   119 				$out    = array();
   121 				$out    = array();
   120 				for ( $i = 0; $i < $length; $i += $chunk_size ) {
   122 				for ( $i = 0; $i < $length; $i += $chunk_size ) {
   121 					$out[] = $this->substr( $string, $i, $chunk_size );
   123 					$out[] = $this->substr( $input_string, $i, $chunk_size );
   122 				}
   124 				}
   123 				return $out;
   125 				return $out;
   124 			} else {
   126 			} else {
   125 				return str_split( $string, $chunk_size );
   127 				return str_split( $input_string, $chunk_size );
   126 			}
   128 			}
   127 		}
   129 		}
   128 
   130 
   129 		/**
   131 		/**
   130 		 * @return int
   132 		 * @return int
   149 	}
   151 	}
   150 endif;
   152 endif;
   151 
   153 
   152 if ( ! class_exists( 'POMO_FileReader', false ) ) :
   154 if ( ! class_exists( 'POMO_FileReader', false ) ) :
   153 	class POMO_FileReader extends POMO_Reader {
   155 	class POMO_FileReader extends POMO_Reader {
       
   156 
       
   157 		/**
       
   158 		 * File pointer resource.
       
   159 		 *
       
   160 		 * @var resource|false
       
   161 		 */
       
   162 		public $_f;
   154 
   163 
   155 		/**
   164 		/**
   156 		 * @param string $filename
   165 		 * @param string $filename
   157 		 */
   166 		 */
   158 		public function __construct( $filename ) {
   167 		public function __construct( $filename ) {
   183 		/**
   192 		/**
   184 		 * @param int $pos
   193 		 * @param int $pos
   185 		 * @return bool
   194 		 * @return bool
   186 		 */
   195 		 */
   187 		public function seekto( $pos ) {
   196 		public function seekto( $pos ) {
   188 			if ( -1 == fseek( $this->_f, $pos, SEEK_SET ) ) {
   197 			if ( -1 === fseek( $this->_f, $pos, SEEK_SET ) ) {
   189 				return false;
   198 				return false;
   190 			}
   199 			}
   191 			$this->_pos = $pos;
   200 			$this->_pos = $pos;
   192 			return true;
   201 			return true;
   193 		}
   202 		}
   288 		 * @return string
   297 		 * @return string
   289 		 */
   298 		 */
   290 		public function read_all() {
   299 		public function read_all() {
   291 			return $this->substr( $this->_str, $this->_pos, $this->strlen( $this->_str ) );
   300 			return $this->substr( $this->_str, $this->_pos, $this->strlen( $this->_str ) );
   292 		}
   301 		}
   293 
       
   294 	}
   302 	}
   295 endif;
   303 endif;
   296 
   304 
   297 if ( ! class_exists( 'POMO_CachedFileReader', false ) ) :
   305 if ( ! class_exists( 'POMO_CachedFileReader', false ) ) :
   298 	/**
   306 	/**
   348 			_deprecated_constructor( self::class, '5.4.0', static::class );
   356 			_deprecated_constructor( self::class, '5.4.0', static::class );
   349 			self::__construct( $filename );
   357 			self::__construct( $filename );
   350 		}
   358 		}
   351 	}
   359 	}
   352 endif;
   360 endif;
   353