Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Filters for output

givanzbb9be6cf3749
diff --git a/system/core/response.php b/system/core/response.php
old mode 100755
new mode 100644
index c163f14..a04bf56
--- a/system/core/response.php
+++ b/system/core/response.php
@@ -27,6 +27,10 @@ class Response {
private $done = false;
+ public $output = true;
+
+ public $filters = [];
+
private $type = ''; //html, json, xml
private $status = 200;
@@ -49,6 +53,10 @@ class Response {
$this->addHeader('X-Powered-By', 'Vvveb ' . V_VERSION);
}
+ function addFilter($filter) {
+ $this->filters[] = $filter;
+ }
+
function getStatus() {
return $this->status;
}
@@ -109,8 +117,10 @@ class Response {
}
}
+ $this->done = true;
+
if ($this->type == 'text' && $data !== null) {
- echo $data;
+ $output = $data;
} else {
if (($this->type == 'json' || $this->type == 'jsonp' || $this->type == 'ldjson' || $this->type == 'activityjson' || $this->type == 'jrdjson') && $data !== null && (! defined('CLI'))) {
if (is_array($data) || is_object($data)) {
@@ -121,7 +131,7 @@ class Response {
}
}
- echo $data;
+ $output = $data;
} else {
$view = View :: getInstance();
@@ -129,10 +139,20 @@ class Response {
$view->setType($this->type);
}
- $view->render();
+ $output = $view->render(true, $this->output && ! $this->filters);
}
}
- $this->done = true;
+ if ($this->filters) {
+ foreach ($this->filters as $filter) {
+ $output = $filter($output);
+ }
+ }
+
+ if ($this->output) {
+ echo $output;
+ }
+
+ return $output;
}
}