Skip to content

Commit

Permalink
Added Writer.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhorber committed Oct 21, 2018
1 parent 5fd47ae commit cab2793
Show file tree
Hide file tree
Showing 3 changed files with 424 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
## TODO

Features I will add:
* Add more writing variants and expand their docs.
* Support more versions (at least V2.3.0).
* Improve parsing of non-text frames.
* Return detailed info about frames (not only technical name).
Expand Down
22 changes: 11 additions & 11 deletions src/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,31 @@ class Reader
* @access private
* @var resource
*/
private $_fileHandle;
private $_fileHandle = null;

/**
* Major version of the source file (4).
*
* @access private
* @var integer
*/
private $_version;
private $_version = 0;

/**
* Total size of the tag (excluding header, including padding).
*
* @access private
* @var integer
*/
private $_tagSize;
private $_tagSize = 0;

/**
* Parsed frames of the tag.
*
* @access private
* @var array[]
*/
private $_frames;
private $_frames = [];


/**
Expand All @@ -79,7 +79,7 @@ public function __construct(string $filename)
// declare(encoding="UTF-8");

$this->_parseHeader();
$this->parseFrames();
$this->_parseFrames();

fclose($this->_fileHandle);
}
Expand All @@ -89,7 +89,7 @@ public function __construct(string $filename)
*
* Format:
* <code>
* [
* 'identifier' => [
* 'identifier' => 'Four character identifier of the frame',
* 'content' => 'Text frames only, parsed content',
* 'encoding' => 'Text frames only, text encoding of content',
Expand Down Expand Up @@ -172,7 +172,7 @@ private function _parseHeader()
* @author Raphael Horber
* @version 21.10.2018
*/
private function parseFrames()
private function _parseFrames()
{
$frames = fread($this->_fileHandle, $this->_tagSize);

Expand Down Expand Up @@ -225,7 +225,7 @@ private function parseFrames()
throw new \UnexpectedValueException("Invalid BOM, got: ".bin2hex($bom));
}

$content = substr($content, 2);
$content = substr($content, 2);
// $delimiter = "\x00\x00";
break;

Expand Down Expand Up @@ -257,9 +257,9 @@ private function parseFrames()

$this->_frames[$identifier] = [
'identifier' => $identifier,
'content' => $content,
'encoding' => $encoding,
'raw' => $rawContent,
'content' => $content,
'encoding' => $encoding,
'raw' => $rawContent,
];

// Frame header + frame size.
Expand Down
Loading

0 comments on commit cab2793

Please sign in to comment.