Fix issue with case-sensitive file systems

git-svn-id: http://php-reader.googlecode.com/svn/branches/zend@161 51a70ab9-7547-0410-9469-37e369ee0574
This commit is contained in:
svollbehr
2010-02-19 14:29:10 +00:00
parent 915200d4c1
commit 2151daf867
2 changed files with 34 additions and 22 deletions

View File

@@ -132,7 +132,8 @@ abstract class Zend_Media_Id3_Frame extends Zend_Media_Id3_Object
if ($reader === null) { if ($reader === null) {
$this->_identifier = strtoupper(substr(get_class($this), -4)); $this->_identifier = strtoupper(substr(get_class($this), -4));
} else { } else {
$this->_identifier = $this->_reader->readString8(4, " "); $this->_identifier =
strtoupper($this->_reader->readString8(4, " "));
/* ID3v2.3.0 size and flags; convert flags to 2.4.0 format */ /* ID3v2.3.0 size and flags; convert flags to 2.4.0 format */
if ($this->getOption('version', 4) < 4) { if ($this->getOption('version', 4) < 4) {
@@ -191,7 +192,7 @@ abstract class Zend_Media_Id3_Frame extends Zend_Media_Id3_Object
*/ */
public final function getIdentifier() public final function getIdentifier()
{ {
return $this->_identifier; return $this->_identifier;
} }
/** /**
@@ -213,7 +214,7 @@ abstract class Zend_Media_Id3_Frame extends Zend_Media_Id3_Object
*/ */
public final function getSize() public final function getSize()
{ {
return $this->_size; return $this->_size;
} }
/** /**
@@ -235,7 +236,7 @@ abstract class Zend_Media_Id3_Frame extends Zend_Media_Id3_Object
*/ */
public final function getFlags($flags) public final function getFlags($flags)
{ {
return $this->_flags; return $this->_flags;
} }
/** /**
@@ -245,7 +246,7 @@ abstract class Zend_Media_Id3_Frame extends Zend_Media_Id3_Object
*/ */
public final function setFlags($flags) public final function setFlags($flags)
{ {
$this->_flags = $flags; $this->_flags = $flags;
} }
/** /**

View File

@@ -21,7 +21,6 @@
*/ */
/**#@+ @ignore */ /**#@+ @ignore */
require_once 'Zend/Io/StringWriter.php';
require_once 'Zend/Media/Id3/Object.php'; require_once 'Zend/Media/Id3/Object.php';
require_once 'Zend/Media/Id3/Header.php'; require_once 'Zend/Media/Id3/Header.php';
/**#@-*/ /**#@-*/
@@ -111,7 +110,7 @@ final class Zend_Media_Id3v2 extends Zend_Media_Id3_Object
if ($filename instanceof Zend_Io_Reader) { if ($filename instanceof Zend_Io_Reader) {
$this->_reader = &$filename; $this->_reader = &$filename;
} else { } else {
require_once('Zend/Io/FileReader.php'); require_once 'Zend/Io/FileReader.php';
try { try {
$this->_reader = new Zend_Io_FileReader($filename); $this->_reader = new Zend_Io_FileReader($filename);
} catch (Zend_Io_Exception $e) { } catch (Zend_Io_Exception $e) {
@@ -140,11 +139,13 @@ final class Zend_Media_Id3v2 extends Zend_Media_Id3_Object
$this->_header->getVersion() > 4) { $this->_header->getVersion() > 4) {
require_once 'Zend/Media/Id3/Exception.php'; require_once 'Zend/Media/Id3/Exception.php';
throw new Zend_Media_Id3_Exception throw new Zend_Media_Id3_Exception
('File does not contain ID3v2 tag of supported version'); ('File does not contain ID3v2 tag of supported version: v2.' .
$this->_header->getVersion());
} }
if ($this->_header->getVersion() < 4 && if ($this->_header->getVersion() < 4 &&
$this->_header->hasFlag(Zend_Media_Id3_Header::UNSYNCHRONISATION)) { $this->_header->hasFlag(Zend_Media_Id3_Header::UNSYNCHRONISATION)) {
$data = $this->_reader->read($this->_header->getSize()); $data = $this->_reader->read($this->_header->getSize());
require_once 'Zend/Io/StringReader.php';
$this->_reader = new Zend_Io_StringReader $this->_reader = new Zend_Io_StringReader
($this->_decodeUnsynchronisation($data)); ($this->_decodeUnsynchronisation($data));
$tagSize = $this->_reader->getSize(); $tagSize = $this->_reader->getSize();
@@ -188,12 +189,14 @@ final class Zend_Media_Id3v2 extends Zend_Media_Id3_Object
} }
$this->_reader->setOffset($offset); $this->_reader->setOffset($offset);
if (@fopen($filename = 'Zend/Media/Id3/Frame/' . if (@fopen($file = 'Zend/Media/Id3/Frame/' .
strtoupper($identifier) . '.php', 'r', true) !== false) { ucfirst(strtolower($identifier)) . '.php', 'r',
require_once($filename); true) !== false) {
require_once($file);
} }
if (class_exists if (class_exists
($classname = 'Zend_Media_Id3_Frame_' . $identifier)) { ($classname = 'Zend_Media_Id3_Frame_' .
ucfirst(strtolower($identifier)))) {
$frame = new $classname($this->_reader, $options); $frame = new $classname($this->_reader, $options);
} else { } else {
require_once 'Zend/Media/Id3/Frame/Unknown.php'; require_once 'Zend/Media/Id3/Frame/Unknown.php';
@@ -215,7 +218,7 @@ final class Zend_Media_Id3v2 extends Zend_Media_Id3_Object
*/ */
public function getHeader() public function getHeader()
{ {
return $this->_header; return $this->_header;
} }
/** /**
@@ -286,7 +289,7 @@ final class Zend_Media_Id3v2 extends Zend_Media_Id3_Object
*/ */
public function getFrames() public function getFrames()
{ {
return $this->_frames; return $this->_frames;
} }
/** /**
@@ -431,7 +434,8 @@ final class Zend_Media_Id3v2 extends Zend_Media_Id3_Object
* If write is called without setting any frames to the tag, the tag is * If write is called without setting any frames to the tag, the tag is
* removed from the file. * removed from the file.
* *
* @param string $filename The optional path to the file. * @param string|Zend_Io_Writer $filename The optional path to the file, use
* null to save to the same file.
*/ */
public function write($filename) public function write($filename)
{ {
@@ -439,6 +443,10 @@ final class Zend_Media_Id3v2 extends Zend_Media_Id3_Object
require_once 'Zend/Media/Id3/Exception.php'; require_once 'Zend/Media/Id3/Exception.php';
throw new Zend_Media_Id3_Exception throw new Zend_Media_Id3_Exception
('No file given to write the tag to'); ('No file given to write the tag to');
} else if ($filename !== null && $filename instanceof Zend_Io_Writer) {
require_once 'Zend/Io/Writer.php';
$this->_writeData($filename);
return;
} else if ($filename !== null && $this->_filename !== null && } else if ($filename !== null && $this->_filename !== null &&
realpath($filename) != realpath($this->_filename) && realpath($filename) != realpath($this->_filename) &&
!copy($this->_filename, $filename)) { !copy($this->_filename, $filename)) {
@@ -466,8 +474,9 @@ final class Zend_Media_Id3v2 extends Zend_Media_Id3_Object
$oldTagSize = 0; $oldTagSize = 0;
} }
} }
require_once 'Zend/Io/StringWriter.php';
$tag = new Zend_Io_StringWriter(); $tag = new Zend_Io_StringWriter();
$this->_writeTag($tag); $this->_writeData($tag);
$tagSize = empty($this->_frames) ? 0 : $tag->getSize(); $tagSize = empty($this->_frames) ? 0 : $tag->getSize();
if ($tagSize > $oldTagSize || $tagSize == 0) { if ($tagSize > $oldTagSize || $tagSize == 0) {
@@ -510,7 +519,7 @@ final class Zend_Media_Id3v2 extends Zend_Media_Id3_Object
* @param Zend_Io_Writer $writer The writer object. * @param Zend_Io_Writer $writer The writer object.
* @return void * @return void
*/ */
private function _writeTag($writer) private function _writeData($writer)
{ {
$this->clearOption('unsyncronisation'); $this->clearOption('unsyncronisation');
@@ -616,19 +625,21 @@ final class Zend_Media_Id3v2 extends Zend_Media_Id3_Object
* @param string $name The frame or field name. * @param string $name The frame or field name.
* @return mixed * @return mixed
*/ */
public function __get($name) { public function __get($name)
{
if (isset($this->_frames[strtoupper($name)])) { if (isset($this->_frames[strtoupper($name)])) {
return $this->_frames[strtoupper($name)][0]; return $this->_frames[strtoupper($name)][0];
} }
if (method_exists($this, 'get' . ucfirst($name))) { if (method_exists($this, 'get' . ucfirst($name))) {
return call_user_func(array($this, 'get' . ucfirst($name))); return call_user_func
(array($this, 'get' . ucfirst($name)));
} }
if (@fopen($filename = 'Zend/Media/Id3/Frame/' . strtoupper($name) . if (@fopen($filename = 'Zend/Media/Id3/Frame/' . ucfirst($name) .
'.php', 'r', true) !== false) { '.php', 'r', true) !== false) {
require_once $filename; require_once $filename;
} }
if (class_exists if (class_exists
($classname = 'Zend_Media_Id3_Frame_' . strtoupper($name))) { ($classname = 'Zend_Media_Id3_Frame_' . ucfirst($name))) {
return $this->addFrame(new $classname()); return $this->addFrame(new $classname());
} }
require_once 'Zend/Media/Id3/Exception.php'; require_once 'Zend/Media/Id3/Exception.php';
@@ -655,6 +666,6 @@ final class Zend_Media_Id3v2 extends Zend_Media_Id3_Object
*/ */
public function __unset($name) public function __unset($name)
{ {
unset($this->_frames[strtoupper($name)]); unset($this->_frames[strtoupper($name)]);
} }
} }