Skip to content

Commit d790d4c

Browse files
committed
Merge pull request #2 from helpfulrobot/convert-to-psr-2
Converted to PSR-2
2 parents 4430286 + 8b7d154 commit d790d4c

2 files changed

+33
-30
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
22

3-
class WhitespaceSuppressorControllerExtension extends Extension {
3+
class WhitespaceSuppressorControllerExtension extends Extension
4+
{
45

5-
public function onAfterInit() {
6-
Injector::inst()->get('RequestProcessor')->setFilters(
7-
array(new WhitespaceSuppressorRequestProcessor())
8-
);
9-
}
10-
11-
}
6+
public function onAfterInit()
7+
{
8+
Injector::inst()->get('RequestProcessor')->setFilters(
9+
array(new WhitespaceSuppressorRequestProcessor())
10+
);
11+
}
12+
}
+24-22
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
<?php
22

3-
class WhitespaceSuppressorRequestProcessor extends RequestProcessor {
3+
class WhitespaceSuppressorRequestProcessor extends RequestProcessor
4+
{
45

5-
// false or 'none' - disable processing
6-
// 'always' - enable processing in all environments
7-
// 'live-only' - enable processing only on live environment
8-
private static $suppress = 'live-only'; // set to false or 'none' to disable processing
6+
// false or 'none' - disable processing
7+
// 'always' - enable processing in all environments
8+
// 'live-only' - enable processing only on live environment
9+
private static $suppress = 'live-only'; // set to false or 'none' to disable processing
910

1011

11-
public function postRequest(SS_HTTPRequest $request, SS_HTTPResponse $response, DataModel $model) {
12-
if (preg_match('/text\/html/', $response->getHeader('Content-Type'))) {
13-
$response->setBody(
14-
$this->SuppressWhitespace($response->getBody())
15-
);
16-
}
17-
}
12+
public function postRequest(SS_HTTPRequest $request, SS_HTTPResponse $response, DataModel $model)
13+
{
14+
if (preg_match('/text\/html/', $response->getHeader('Content-Type'))) {
15+
$response->setBody(
16+
$this->SuppressWhitespace($response->getBody())
17+
);
18+
}
19+
}
1820

19-
public function SuppressWhitespace($html) {
20-
if ($this->config()->suppress == 'always' || ($this->config()->suppress == 'live-only' && Director::isLive())) {
21-
$html = preg_replace("/\s+/", ' ', trim($html));
22-
$html = str_replace(array('<!-- -->', ' //<![CDATA[', '//]]> '), '', $html);
23-
// TODO: remove all comments?
24-
}
25-
return $html;
26-
}
27-
28-
}
21+
public function SuppressWhitespace($html)
22+
{
23+
if ($this->config()->suppress == 'always' || ($this->config()->suppress == 'live-only' && Director::isLive())) {
24+
$html = preg_replace("/\s+/", ' ', trim($html));
25+
$html = str_replace(array('<!-- -->', ' //<![CDATA[', '//]]> '), '', $html);
26+
// TODO: remove all comments?
27+
}
28+
return $html;
29+
}
30+
}

0 commit comments

Comments
 (0)