blob: ac17fe4d6ab58450adc6a403ff68c143b26c5413 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
<?php
namespace SSRS\Object;
use SSRS\Report;
use SSRS\Report\CachedStreamResource;
class ReportOutput extends ObjectAbstract {
public function preCacheStreams(Report $report, $localCachePath, $format = 'HTML4.0') {
$this->verifyCachePath($localCachePath);
$rootPath = rtrim($localCachePath, '/');
foreach ($this->StreamIds->string as $streamId) {
$path = $rootPath . '/' . $streamId;
$stream = $report->renderStream($format, $streamId);
$cachedResource = new CachedStreamResource($streamId, $path);
$cachedResource->store($stream);
}
return $this;
}
public function download($filename) {
header("Cache-control: max-age=3600, must-revalidate");
header("Pragma: public");
header("Expires: -1");
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="' . $filename . '"');
header("Content-Type: " . $this->MimeType);
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . strlen($this->Result));
echo($this->Result);
exit(0);
}
public function __toString() {
return (string) $this->Result;
}
protected function verifyCachePath($path) {
if (false === file_exists($path) || false === is_dir($path)) {
throw new \RuntimeException('Stream cache path does not exist');
}
if (false === is_writable($path)) {
throw new \RuntimeException('Stream cache path is not writeable');
}
return $this;
}
}
|