summaryrefslogtreecommitdiffstats
path: root/library/SSRS/Object
diff options
context:
space:
mode:
authorArron Woods <aw@chartblocks.com>2015-04-23 16:52:50 +0100
committerArron Woods <aw@chartblocks.com>2015-04-23 16:52:58 +0100
commita12d873a6a8230dd2ef1255fedd5753068ce86ee (patch)
tree8b8cedba08b540689009861225b1108fc5b3460f /library/SSRS/Object
parent320d49f6af9fd66ab1ba72da22fd9fa37fcad0e4 (diff)
downloadphp-ssrs-a12d873a6a8230dd2ef1255fedd5753068ce86ee.zip
php-ssrs-a12d873a6a8230dd2ef1255fedd5753068ce86ee.tar.gz
php-ssrs-a12d873a6a8230dd2ef1255fedd5753068ce86ee.tar.bz2
Cache streams from report output
Diffstat (limited to 'library/SSRS/Object')
-rwxr-xr-xlibrary/SSRS/Object/RenderStream.php8
-rwxr-xr-xlibrary/SSRS/Object/ReportOutput.php30
2 files changed, 35 insertions, 3 deletions
diff --git a/library/SSRS/Object/RenderStream.php b/library/SSRS/Object/RenderStream.php
index 58482b6..02cbb33 100755
--- a/library/SSRS/Object/RenderStream.php
+++ b/library/SSRS/Object/RenderStream.php
@@ -7,9 +7,11 @@ class RenderStream extends ObjectAbstract {
public $Result;
public $MimeType;
- public function __construct(\stdClass $stream) {
- $this->Result = $stream->Result;
- $this->MimeType = $stream->MimeType;
+ public function __construct(\stdClass $stream = null) {
+ if ($stream) {
+ $this->Result = $stream->Result;
+ $this->MimeType = $stream->MimeType;
+ }
}
public function __toString() {
diff --git a/library/SSRS/Object/ReportOutput.php b/library/SSRS/Object/ReportOutput.php
index 0500525..ac17fe4 100755
--- a/library/SSRS/Object/ReportOutput.php
+++ b/library/SSRS/Object/ReportOutput.php
@@ -2,8 +2,26 @@
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");
@@ -22,4 +40,16 @@ class ReportOutput extends ObjectAbstract {
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;
+ }
+
}