Modifications to keep compatibility with PHP 5.0.0
git-svn-id: http://php-reader.googlecode.com/svn/trunk@135 51a70ab9-7547-0410-9469-37e369ee0574
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
/**
|
||||
* PHP Reader Library
|
||||
*
|
||||
* Copyright (c) 2008 The PHP Reader Project Workgroup. All rights reserved.
|
||||
* Copyright (c) 2008-2009 The PHP Reader Project Workgroup. All rights
|
||||
* reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -30,7 +31,7 @@
|
||||
*
|
||||
* @package php-reader
|
||||
* @subpackage ID3
|
||||
* @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
|
||||
* @copyright Copyright (c) 2008-2009 The PHP Reader Project Workgroup
|
||||
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
@@ -64,7 +65,7 @@ require_once("ID3/Frame.php");
|
||||
* @subpackage ID3
|
||||
* @author Sven Vollbehr <svollbehr@gmail.com>
|
||||
* @author Ryan Butterfield <buttza@gmail.com>
|
||||
* @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
|
||||
* @copyright Copyright (c) 2008-2009 The PHP Reader Project Workgroup
|
||||
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
|
||||
* @version $Rev$
|
||||
*/
|
||||
@@ -372,7 +373,7 @@ final class ID3v2
|
||||
throw new ID3_Exception("Unable to open file for writing: " . $filename);
|
||||
|
||||
$oldTagSize = $this->_header->getSize();
|
||||
$tag = "" . $this;
|
||||
$tag = $this->__toString();
|
||||
$tagSize = empty($this->_frames) ? 0 : strlen($tag);
|
||||
|
||||
if ($this->_reader === null ||
|
||||
@@ -451,7 +452,7 @@ final class ID3v2
|
||||
$data = "";
|
||||
foreach ($this->_frames as $frames)
|
||||
foreach ($frames as $frame)
|
||||
$data .= $frame;
|
||||
$data .= $frame->__toString();
|
||||
|
||||
$datalen = strlen($data);
|
||||
$padlen = 0;
|
||||
@@ -464,14 +465,12 @@ final class ID3v2
|
||||
/* The tag padding is calculated as follows. If the tag can be written in
|
||||
the space of the previous tag, the remaining space is used for padding.
|
||||
If there is no previous tag or the new tag is bigger than the space taken
|
||||
by the previous tag, the padding is calculated using the following
|
||||
logaritmic equation: log(0.2(x + 10)), ranging from some 300 bytes to
|
||||
almost 5000 bytes given the tag length of 0..256M. */
|
||||
by the previous tag, the padding is a constant 4096 bytes. */
|
||||
if ($this->hasFooter() === false) {
|
||||
if ($this->_reader !== null && $datalen < $this->_header->getSize())
|
||||
$padlen = $this->_header->getSize() - $datalen;
|
||||
else
|
||||
$padlen = ceil(log(0.2 * ($datalen / 1024 + 10), 10) * 1024);
|
||||
$padlen = 4096;
|
||||
}
|
||||
|
||||
/* ID3v2.4.0 CRC calculated w/ padding */
|
||||
@@ -486,7 +485,7 @@ final class ID3v2
|
||||
$crc = -(($crc ^ 0xffffffff) + 1);
|
||||
$this->_extendedHeader->setCrc($crc);
|
||||
}
|
||||
$data = $this->getExtendedHeader() . $data;
|
||||
$data = $this->getExtendedHeader()->__toString() . $data;
|
||||
}
|
||||
|
||||
/* ID3v2.3.0 CRC calculated w/o padding */
|
||||
@@ -495,7 +494,7 @@ final class ID3v2
|
||||
|
||||
$this->_header->setSize(strlen($data));
|
||||
|
||||
return "ID3" . $this->_header . $data .
|
||||
($this->hasFooter() ? "3DI" . $this->getFooter() : "");
|
||||
return "ID3" . $this->_header->__toString() . $data .
|
||||
($this->hasFooter() ? "3DI" . $this->getFooter()->__toString() : "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* PHP Reader Library
|
||||
*
|
||||
* Copyright (c) 2006-2008 The PHP Reader Project Workgroup. All rights
|
||||
* Copyright (c) 2006-2009 The PHP Reader Project Workgroup. All rights
|
||||
* reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -30,7 +30,7 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package php-reader
|
||||
* @copyright Copyright (c) 2006-2008 The PHP Reader Project Workgroup
|
||||
* @copyright Copyright (c) 2006-2009 The PHP Reader Project Workgroup
|
||||
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
@@ -48,7 +48,7 @@ require_once("Transform.php");
|
||||
* @package php-reader
|
||||
* @author Sven Vollbehr <svollbehr@gmail.com>
|
||||
* @author Ryan Butterfield <buttza@gmail.com>
|
||||
* @copyright Copyright (c) 2006-2008 The PHP Reader Project Workgroup
|
||||
* @copyright Copyright (c) 2006-2009 The PHP Reader Project Workgroup
|
||||
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
|
||||
* @version $Rev$
|
||||
*/
|
||||
@@ -168,7 +168,8 @@ class Reader
|
||||
* @param string $name The field name.
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($name) {
|
||||
public function __get($name)
|
||||
{
|
||||
if (method_exists($this, "get" . ucfirst(strtolower($name))))
|
||||
return call_user_func(array($this, "get" . ucfirst(strtolower($name))));
|
||||
else throw new Reader_Exception("Unknown field: " . $name);
|
||||
@@ -181,7 +182,8 @@ class Reader
|
||||
* @param string $value The field value.
|
||||
* @return mixed
|
||||
*/
|
||||
public function __set($name, $value) {
|
||||
public function __set($name, $value)
|
||||
{
|
||||
if (method_exists($this, "set" . ucfirst(strtolower($name))))
|
||||
call_user_func
|
||||
(array($this, "set" . ucfirst(strtolower($name))), $value);
|
||||
@@ -201,16 +203,32 @@ class Reader
|
||||
* @return mixed
|
||||
* @throws Reader_Exception if no such transformer is implemented
|
||||
*/
|
||||
public function __call($method, $params) {
|
||||
public function __call($method, $params)
|
||||
{
|
||||
$chunks = array();
|
||||
|
||||
// To keep compatibility with PHP 5.0.0 we use a static array instead of
|
||||
// method_exists to check if a method of the Transform class can be called.
|
||||
static $methods = array(
|
||||
"isLittleEndian", "isBigEndian", "toInt64LE", "fromInt64LE", "toInt64BE",
|
||||
"fromInt64BE", "toInt32", "fromInt32", "toInt32LE", "fromInt32LE",
|
||||
"toInt32BE", "fromInt32BE", "toUInt32LE", "fromUInt32LE", "toUInt32BE",
|
||||
"fromUInt32BE", "toInt16", "fromInt16", "toInt16LE", "fromInt16LE",
|
||||
"toInt16BE", "fromInt16BE", "toUInt16LE", "fromUInt16LE", "toUInt16BE",
|
||||
"fromUInt16BE", "toInt8", "fromInt8", "toUInt8", "fromUInt8", "toFloat",
|
||||
"fromFloat", "toFloatLE", "fromFloatLE", "toFloatBE", "fromFloatBE",
|
||||
"toString8", "fromString8", "toString16", "fromString16", "toString16LE",
|
||||
"fromString16LE", "toString16BE", "fromString16BE", "toHHex", "fromHHex",
|
||||
"toLHex", "fromLHex", "toGUID", "fromGUID"
|
||||
);
|
||||
if (preg_match
|
||||
("/read([a-z]{3,6})?(\d{1,2})?(?:LE|BE)?/i", $method, $chunks) &&
|
||||
method_exists("Transform", preg_replace("/^read/", "from", $method))) {
|
||||
in_array(preg_replace("/^read/", "from", $method), $methods))
|
||||
return call_user_func
|
||||
(array("Transform", preg_replace("/^read/", "from", $method)),
|
||||
$this->read(preg_match("/String|(?:H|L)Hex/", $chunks[1]) ?
|
||||
(isset($params[0]) ? $params[0] : 1) :
|
||||
($chunks[1] == "GUID" ? 16 : $chunks[2] / 8)));
|
||||
} else throw new Reader_Exception("Unknown method: " . $method);
|
||||
else throw new Reader_Exception("Unknown method: " . $method);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user