1 | <?php |
||
3 | class CDNRewriteRequestFilter implements RequestFilter |
||
|
|||
4 | { |
||
5 | |||
6 | /** |
||
7 | * Enable rewriting of asset urls |
||
8 | * @var bool |
||
9 | */ |
||
10 | private static $cdn_rewrite = false; |
||
11 | |||
12 | /** |
||
13 | * The cdn domain incl. protocol |
||
14 | * @var string |
||
15 | */ |
||
16 | private static $cdn_domain = 'http://cdn.mysite.com'; |
||
17 | |||
18 | /** |
||
19 | * Enable rewrite in admin area |
||
20 | * @var bool |
||
21 | */ |
||
22 | private static $enable_in_backend = false; |
||
23 | |||
24 | /** |
||
25 | * Enable rewrite in dev mode |
||
26 | * @var bool |
||
27 | */ |
||
28 | private static $enable_in_dev = false; |
||
29 | |||
30 | |||
31 | /** |
||
32 | * should assets be rewritten? |
||
33 | * @var bool |
||
34 | */ |
||
35 | private static $rewrite_assets = true; |
||
36 | |||
37 | /** |
||
38 | * should themes also be rewritten? |
||
39 | * @var bool |
||
40 | */ |
||
41 | private static $rewrite_themes = false; |
||
42 | |||
43 | /** |
||
44 | * Filter executed before a request processes |
||
45 | * |
||
46 | * @param SS_HTTPRequest $request Request container object |
||
47 | * @param Session $session Request session |
||
48 | * @param DataModel $model Current DataModel |
||
49 | * @return boolean Whether to continue processing other filters. Null or true will continue processing (optional) |
||
50 | */ |
||
51 | public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model) |
||
55 | |||
56 | /** |
||
57 | * Filter executed AFTER a request |
||
58 | * |
||
59 | * @param SS_HTTPRequest $request Request container object |
||
60 | * @param SS_HTTPResponse $response Response output object |
||
61 | * @param DataModel $model Current DataModel |
||
62 | * @return boolean Whether to continue processing other filters. Null or true will continue processing (optional) |
||
63 | */ |
||
64 | public function postRequest(SS_HTTPRequest $request, SS_HTTPResponse $response, DataModel $model) |
||
75 | |||
76 | /** |
||
77 | * Checks if cdn rewrite is enabled |
||
78 | * @return bool |
||
79 | */ |
||
80 | public static function isEnabled() |
||
88 | |||
89 | /** |
||
90 | * Helper method to check if we're in backend (LeftAndMain) or frontend |
||
91 | * Controller::curr() doesn't return anything, so i cannot check it... |
||
92 | * @return bool |
||
93 | */ |
||
94 | public static function isBackend() |
||
99 | |||
100 | /** |
||
101 | * replaces links to assets in src and href attributes to point to a given cdn domain |
||
102 | * |
||
103 | * @param $body |
||
104 | * @return mixed|void |
||
105 | */ |
||
106 | public static function replaceCDN($body) |
||
129 | } |
||
130 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.