9
9
namespace StaticDeploy ;
10
10
11
11
class SimpleRewriter {
12
-
13
- /**
14
- * @var string
15
- */
16
- private $ destination_url ;
17
-
18
- /**
19
- * @var array
20
- */
21
- private $ hosts_to_rewrite ;
22
-
23
- /**
24
- * @var string
25
- */
26
- private $ site_url ;
27
-
28
- /**
29
- * @var boolean
30
- */
31
- private $ skip_url_rewrite ;
32
-
33
- public function __construct () {
34
- $ this ->destination_url = apply_filters (
35
- Controller::getHookName ( 'set_destination_url ' ),
36
- Options::getValue ( 'deploymentURL ' )
37
- );
38
- $ this ->hosts_to_rewrite = Options::getLineDelimitedBlobValue ( 'hostsToRewrite ' );
39
- $ this ->site_url = apply_filters (
40
- Controller::getHookName ( 'set_wordpress_site_url ' ),
41
- untrailingslashit ( SiteInfo::getUrl ( 'site ' ) )
42
- );
43
- $ url_rewrite = (int ) Options::getValue ( 'skipURLRewrite ' );
44
- $ this ->skip_url_rewrite = $ url_rewrite === 1 ? true : false ;
45
- }
46
-
47
12
/**
48
13
* Rewrite URLs in a string to destination_url
49
14
*
50
15
* @param string $file_contents
51
16
* @return string
52
17
*/
53
- public function rewriteFileContents ( string $ file_contents ): string
54
- {
18
+ public function rewriteFileContents (
19
+ PostProcessConfig $ config ,
20
+ string $ file_contents ,
21
+ ): string {
55
22
// TODO: allow empty file saving here? Exception for style.css
56
23
if ( ! $ file_contents ) {
57
24
return '' ;
58
25
}
59
26
60
- if ( $ this ->skip_url_rewrite ) {
61
- return $ file_contents ;
62
- }
63
-
64
- $ wordpress_site_url = untrailingslashit ( $ this ->site_url );
65
- $ destination_url = untrailingslashit ( $ this ->destination_url );
27
+ $ wordpress_site_url = untrailingslashit ( $ config ->site_url );
28
+ $ destination_url = untrailingslashit ( $ config ->destination_url );
66
29
$ destination_url_c = addcslashes ( $ destination_url , '/ ' );
67
30
$ destination_url_rel = URLHelper::getProtocolRelativeURL ( $ destination_url );
68
31
$ destination_url_rel_c = addcslashes ( $ destination_url_rel , '/ ' );
@@ -75,7 +38,7 @@ public function rewriteFileContents( string $file_contents ): string
75
38
addcslashes ( URLHelper::getProtocolRelativeURL ( $ destination_url ), '/ ' ),
76
39
];
77
40
78
- foreach ( $ this ->hosts_to_rewrite as $ host ) {
41
+ foreach ( $ config ->hosts_to_rewrite as $ host ) {
79
42
if ( $ host ) {
80
43
$ host_rel = URLHelper::getProtocolRelativeURL ( 'http:// ' . $ host );
81
44
$ host_rel_c = addcslashes ( $ host_rel , '/ ' );
0 commit comments