/** * @since 1.0 * @uses getState() * @uses parseFileHeader() * @uses getRawFileHeader() * @uses Chunk::getData() * @uses TrackParser::parse() * @uses TrackParser::getState() * * @throws {@link ParseException} * @return Chunk */ public function parse() { $chunk = null; $state = $this->getState(); switch ($state) { case ParseState::FILE_HEADER: $chunk = $this->parseFileHeader($this->getRawFileHeader()); list(, $numTracks, ) = $chunk->getData(); $this->tracksExpected = $numTracks; $this->setState(ParseState::TRACK_HEADER); break; case ParseState::TRACK_HEADER: case ParseState::EVENT: case ParseState::DELTA: $chunk = $this->trackParser->parse(); $newState = $this->trackParser->getState(); if ($newState === ParseState::TRACK_HEADER) { $this->tracksParsed++; if ($this->getTracksParsed() >= $this->getTracksExpected()) { $newState = ParseState::EOF; } } $this->setState($newState); break; case ParseState::EOF: //the pointer is not beyond the buffer length at this point //one more should push it over the edge $this->file->fgetc(); if (!$this->file->eof()) { throw new ParseException('Expected EOF'); } break; default: throw new StateException('Unknown parse state: ' . $state); } return $chunk; }
public function testDefaultState() { $this->assertEquals(ParseState::TRACK_HEADER, $this->obj->getState()); }