From 267ed3632d3fd258170da872ed8c670e96583af5 Mon Sep 17 00:00:00 2001 From: svollbehr Date: Mon, 8 Mar 2010 09:24:50 +0000 Subject: [PATCH] Fix missing methods/method signatures git-svn-id: http://php-reader.googlecode.com/svn/branches/zend@175 51a70ab9-7547-0410-9469-37e369ee0574 --- src/Zend/Io/Reader.php | 56 ++++++++++++++++++++++++++++++++++++++++- src/Zend/Mime/Magic.php | 34 +++++++++++++++++++++---- 2 files changed, 84 insertions(+), 6 deletions(-) diff --git a/src/Zend/Io/Reader.php b/src/Zend/Io/Reader.php index 444b98b..d2187dd 100644 --- a/src/Zend/Io/Reader.php +++ b/src/Zend/Io/Reader.php @@ -28,7 +28,7 @@ * @author Sven Vollbehr * @author Ryan Butterfield * @author Marc Bennewitz - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @version $Id$ */ @@ -273,6 +273,18 @@ class Zend_Io_Reader } } + /** + * Reads 2 bytes from the stream and returns machine ordered binary data + * as signed 16-bit integer. + * + * @return integer + * @throws Zend_Io_Exception if an I/O error occurs + */ + public final function readInt16() + { + return $this->_fromInt16($this->read(2)); + } + /** * Returns machine endian ordered binary data as unsigned 16-bit integer. * @@ -313,6 +325,18 @@ class Zend_Io_Reader return $this->_fromUInt16($this->read(2), self::BIG_ENDIAN_ORDER); } + /** + * Reads 2 bytes from the stream and returns machine ordered binary data + * as unsigned 16-bit integer. + * + * @return integer + * @throws Zend_Io_Exception if an I/O error occurs + */ + public final function readUInt16() + { + return $this->_fromUInt16($this->read(2), self::MACHINE_ENDIAN_ORDER); + } + /** * Returns machine-endian ordered binary data as signed 32-bit integer. * @@ -355,6 +379,18 @@ class Zend_Io_Reader return $this->_fromInt32($this->read(4)); } + /** + * Reads 4 bytes from the stream and returns machine ordered binary data + * as signed 32-bit integer. + * + * @return integer + * @throws Zend_Io_Exception if an I/O error occurs + */ + public final function readInt32() + { + return $this->_fromInt32($this->read(4)); + } + /** * Reads 4 bytes from the stream and returns little-endian ordered binary * data as unsigned 32-bit integer. @@ -391,6 +427,24 @@ class Zend_Io_Reader } } + /** + * Reads 4 bytes from the stream and returns machine ordered binary data + * as unsigned 32-bit integer. + * + * @return integer + * @throws Zend_Io_Exception if an I/O error occurs + */ + public final function readUInt32() + { + if (PHP_INT_SIZE < 8) { + list(, $hi, $lo) = unpack('L*', $this->read(4)); + return $hi * (0xffff+1) + $lo; // eq $hi << 16 | $lo + } else { + list(, $int) = unpack('L*', $this->read(4)); + return $int; + } + } + /** * Reads 8 bytes from the stream and returns little-endian ordered binary * data as 64-bit float. diff --git a/src/Zend/Mime/Magic.php b/src/Zend/Mime/Magic.php index 82fb2e8..e09788e 100644 --- a/src/Zend/Mime/Magic.php +++ b/src/Zend/Mime/Magic.php @@ -57,7 +57,7 @@ require_once 'Zend/Io/FileReader.php'; * @category Zend * @package Zend_Mime * @author Sven Vollbehr - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @version $Id$ */ @@ -89,7 +89,7 @@ final class Zend_Mime_Magic * @param string $default The default value. * @return string|false */ - public function getType($filename, $default = null) + public function getMimeType($filename, $default = null) { $reader = new Zend_Io_FileReader($filename); @@ -98,8 +98,8 @@ final class Zend_Mime_Magic $chunks = array(); if (!preg_match("/^(?P>?)(?P\d+)\s+(?P\S+)\s+(?P\S+)(?:\s+(?P[a-" . - "z]+\/[a-z-0-9]+)?(?:\s+(?P.+))?)?$/", - $line, $chunks)) { + "z]+\/[a-z-0-9]+)?(?:\s+(?P.?+))?)?$/", + $line, $chunks)) { continue; } @@ -161,10 +161,34 @@ final class Zend_Mime_Magic return $chunks['MIMEType']; } if (!empty($chunks['Description'])) { - return $chunks['Description']; + return rtrim($chunks['Description'], "\n"); } } } return $default; } + + /** + * Returns the results of the mime type check either as a boolean or an + * array of boolean values. + * + * @param string|Array $filename The file path whose type to test. + * @param string|Array $mimeType The mime type to test against. + * @return boolean|Array + */ + public function isMimeType($filename, $mimeType) + { + if (is_array($filename)) { + $result = array(); + foreach ($filename as $key => $value) { + $result[] = + ($this->getMimeType($value) == + (is_array($mimeType) ? $mimeType[$key] : $mimeType)) ? + true : false; + } + return $result; + } else { + return $this->getMimeType($filename) == $mimeType ? true : false; + } + } }