1 : <?php
2 :
3 : /**
4 : * \Midi\Reporting\MultiFilePrinter
5 : *
6 : * @package Midi
7 : * @subpackage Reporting
8 : * @copyright © 2009 Tommy Montgomery <http://phpmidiparser.com/>
9 : * @since 1.0
10 : */
11 :
12 : namespace Midi\Reporting;
13 :
14 : use \Midi\Delta;
15 : use \Midi\TrackHeader;
16 : use \Midi\FileHeader;
17 : use \Midi\Event;
18 : use \Midi\Parsing\Parser;
19 :
20 : /**
21 : * Printer that outputs to multiple files
22 : *
23 : * @package Midi
24 : * @subpackage Reporting
25 : * @since 1.0
26 : */
27 1 : class MultiFilePrinter extends FilePrinter {
28 :
29 : /**
30 : * @since 1.0
31 : *
32 : * @param Formatter $formatter
33 : * @param Parser $parser
34 : * @param string $directory The directory to write the report to
35 : */
36 : public function __construct(Formatter $formatter, Parser $parser, $directory = null) {
37 2 : parent::__construct($formatter, $parser);
38 2 : $this->params['target'] = $directory;
39 2 : $this->params['items'] = 1;
40 2 : $this->params['multi_file'] = true;
41 2 : $this->params['max_file_size'] = 1024 * 50;
42 2 : }
43 :
44 : /**
45 : * @since 1.0
46 : * @uses createIndex()
47 : * @uses createFileObject()
48 : * @uses Printer::printNext()
49 : *
50 : * @return bool true if there is more to parse, false if EOF has been reached
51 : */
52 : public function printNext() {
53 1 : if ($this->file === null) {
54 1 : $this->createIndex();
55 1 : $this->file = $this->createFileObject($this->params['target'] . DIRECTORY_SEPARATOR . 'data' . $this->params['items'] . '.html');
56 1 : } else if ($this->bytesWritten >= $this->params['max_file_size']) {
57 1 : $this->parseTime = 0;
58 1 : $this->totalTime = 0;
59 1 : $this->bytesWritten = 0;
60 :
61 1 : $this->params['items']++;
62 1 : $this->file = $this->createFileObject($this->params['target'] . DIRECTORY_SEPARATOR . 'data' . $this->params['items'] . '.html');
63 1 : }
64 :
65 1 : return parent::printNext();
66 : }
67 :
68 : /**
69 : * Creates the index page
70 : *
71 : * @since 1.0
72 : * @uses createFileObject()
73 : * @uses printData()
74 : * @uses Formatter::beforeFile()
75 : * @uses Formatter::afterFile()
76 : */
77 : protected function createIndex() {
78 1 : $this->file = $this->createFileObject($this->params['target'] . DIRECTORY_SEPARATOR . 'index.html');
79 1 : $this->printData($this->formatter->beforeFile());
80 1 : $this->printData($this->formatter->afterFile(0, 0));
81 1 : }
82 :
83 : /**
84 : * @since 1.0
85 : * @uses Formatter::beforeFile()
86 : * @uses Formatter::beforeFileHeader()
87 : * @uses Formatter::beforeChunk()
88 : * @uses Formatter::formatFileHeader()
89 : * @uses Formatter::afterChunk()
90 : * @uses Formatter::afterFileHeader()
91 : * @uses printData()
92 : *
93 : * @param FileHeader $fileHeader
94 : */
95 : protected function printFileHeader(FileHeader $fileHeader) {
96 1 : $this->printData($this->formatter->beforeFileHeader($fileHeader));
97 1 : $this->printData($this->formatter->beforeChunk($fileHeader));
98 1 : $this->printData($this->formatter->formatFileHeader($fileHeader));
99 1 : $this->printData($this->formatter->afterChunk($fileHeader));
100 1 : $this->printData($this->formatter->afterFileHeader($fileHeader));
101 1 : }
102 :
103 : /**
104 : * @since 1.0
105 : */
106 : protected function printEof() {
107 1 : $this->isParsingTrack = false;
108 1 : }
109 :
110 : }
111 :
|