@@ -13,22 +13,37 @@ class BehindProxy implements Filter {
1313 private $ remote , $ replace ;
1414
1515 /**
16- * Creates a new instance given a map of the front-facing URL to the local path
16+ * Creates a new instance given a map of the front-facing URL to the local path:
1717 *
18- * @param [:string] $mapping e.g. `["http://remote.url/" => "/local.path"]`
18+ * ```php
19+ * // Using a map
20+ * new BehindProxy(['http://remote.url/' => '/local.path']);
21+ *
22+ * // Specifying remote URL and local path as separate arguments
23+ * new BehindProxy('http://remote.url/', '/local.path');
24+ * ```
25+ *
26+ * @param [:string]|string $mapping
27+ * @param ?string $target
1928 * @throws lang.IllegalArgumentException
2029 */
21- public function __construct ($ mapping ) {
22- if (1 !== sizeof ($ mapping )) {
23- throw new IllegalArgumentException ('Expected a map in the form ["http://remote.url/" => "/local.path"] ' );
30+ public function __construct ($ mapping , $ target = null ) {
31+ if (is_array ($ mapping )) {
32+ if (1 !== sizeof ($ mapping )) {
33+ throw new IllegalArgumentException ('Expected a map in the form ["http://remote.url/" => "/local.path"] ' );
34+ }
35+
36+ $ this ->remote = new URI (key ($ mapping ));
37+ $ target = current ($ mapping );
38+ } else {
39+ $ this ->remote = new URI ($ mapping );
2440 }
2541
26- $ this ->remote = new URI (key ($ mapping ));
2742 if ($ this ->remote ->isRelative ()) {
2843 throw new IllegalArgumentException ('Remote URL must be absolute ' );
2944 }
3045
31- $ this ->replace = '#^ ' .rtrim (preg_quote (current ( $ mapping ) , '# ' ), '/ ' ).'/# ' ;
46+ $ this ->replace = '#^ ' .rtrim (preg_quote ($ target , '# ' ), '/ ' ).'/# ' ;
3247 }
3348
3449 /**
0 commit comments