1414
1515class Client
1616{
17- private $ url ;
1817 private $ brower ;
1918
20- public function __construct ($ url , Browser $ browser , Parser $ parser = null , Loader $ loader = null )
19+ public function __construct (Browser $ browser , Parser $ parser = null , Loader $ loader = null )
2120 {
2221 if ($ parser === null ) {
2322 $ parser = new Parser ();
@@ -31,7 +30,6 @@ public function __construct($url, Browser $browser, Parser $parser = null, Loade
3130// 'follow_redirects' => false
3231// ));
3332
34- $ this ->url = rtrim ($ url , '/ ' ) . '/ ' ;
3533 $ this ->browser = $ browser ;
3634 $ this ->parser = $ parser ;
3735 $ this ->loader = $ loader ;
@@ -43,17 +41,20 @@ public function fetchFile($path, $revision = null)
4341 return Promise \reject (new InvalidArgumentException ('File path MUST NOT end with trailing slash ' ));
4442 }
4543
46- $ url = $ path . '?view=co ' ;
47- if ($ revision !== null ) {
48- $ url .= '&pathrev= ' . $ revision ;
49- }
50-
5144 // TODO: fetching a directory redirects to path with trailing slash
5245 // TODO: status returns 200 OK, but displays an error message anyways..
5346 // TODO: see not-a-file.html
5447 // TODO: reject all paths with trailing slashes
5548
56- return $ this ->fetch ($ url );
49+ return $ this ->fetch (
50+ $ this ->browser ->resolve (
51+ '/{+path}?view=co{&pathrev} ' ,
52+ array (
53+ 'path ' => ltrim ($ path , '/ ' ),
54+ 'pathrev ' => $ revision
55+ )
56+ )
57+ );
5758 }
5859
5960 public function fetchDirectory ($ path , $ revision = null , $ showAttic = false )
@@ -62,21 +63,19 @@ public function fetchDirectory($path, $revision = null, $showAttic = false)
6263 return Promise \reject (new InvalidArgumentException ('Directory path MUST end with trailing slash ' ));
6364 }
6465
65- $ url = $ path ;
66-
67- if ($ revision !== null ) {
68- $ url .= '?pathrev= ' . $ revision ;
69- }
70-
71- if ($ showAttic ) {
72- $ url .= (strpos ($ url , '? ' ) === false ) ? '? ' : '& ' ;
73- $ url .= 'hideattic=0 ' ;
74- }
75-
7666 // TODO: path MUST end with trailing slash
7767 // TODO: accessing files will redirect to file with relative location URL (not supported by clue/buzz-react)
7868
79- return $ this ->fetchXml ($ url )->then (function (SimpleXMLElement $ xml ) {
69+ return $ this ->fetchXml (
70+ $ this ->browser ->resolve (
71+ '/{+path}{?pathrev,hideattic} ' ,
72+ array (
73+ 'path ' => ltrim ($ path , '/ ' ),
74+ 'pathrev ' => $ revision ,
75+ 'hideattic ' => $ showAttic ? '0 ' : null
76+ )
77+ )
78+ )->then (function (SimpleXMLElement $ xml ) {
8079 // TODO: reject if this is a file, instead of directory => contains "Log of" instead of "Index of"
8180 // TODO: see is-a-file.html
8281
@@ -86,23 +85,31 @@ public function fetchDirectory($path, $revision = null, $showAttic = false)
8685
8786 public function fetchPatch ($ path , $ r1 , $ r2 )
8887 {
89- $ url = $ path . '?view=patch&r1= ' . $ r1 . '&r2= ' . $ r2 ;
90-
91- return $ this ->fetch ($ url );
88+ return $ this ->fetch (
89+ $ this ->browser ->resolve (
90+ '/{+path}?view=patch{&r1,r2} ' ,
91+ array (
92+ 'path ' => ltrim ($ path , '/ ' ),
93+ 'r1 ' => $ r1 ,
94+ 'r2 ' => $ r2
95+ )
96+ )
97+ );
9298 }
9399
94100 public function fetchLog ($ path , $ revision = null )
95101 {
96- $ url = $ path . '?view=log ' ;
97-
98102 // TODO: invalid revision shows error page, but HTTP 200 OK
99103
100- if ($ revision !== null ) {
101- $ url .= (strpos ($ url , '? ' ) === false ) ? '? ' : '& ' ;
102- $ url .= 'pathrev= ' . $ revision ;
103- }
104-
105- return $ this ->fetchXml ($ url )->then (array ($ this ->parser , 'parseLogEntries ' ));
104+ return $ this ->fetchXml (
105+ $ this ->browser ->resolve (
106+ '/{+path}?view=log{&pathrev} ' ,
107+ array (
108+ 'path ' => ltrim ($ path , '/ ' ),
109+ 'pathrev ' => $ revision
110+ )
111+ )
112+ )->then (array ($ this ->parser , 'parseLogEntries ' ));
106113 }
107114
108115 public function fetchRevisionPrevious ($ path , $ revision )
@@ -123,9 +130,14 @@ public function fetchAllPreviousRevisions($path)
123130
124131 private function fetchLogXml ($ path )
125132 {
126- $ url = $ path . '?view=log ' ;
127-
128- return $ this ->fetchXml ($ url );
133+ return $ this ->fetchXml (
134+ $ this ->browser ->resolve (
135+ '/{+path}?view=log ' ,
136+ array (
137+ 'path ' => ltrim ($ path , '/ ' )
138+ )
139+ )
140+ );
129141 }
130142
131143 private function fetchXml ($ url )
@@ -135,7 +147,7 @@ private function fetchXml($url)
135147
136148 private function fetch ($ url )
137149 {
138- return $ this ->browser ->get ($ this -> url . ltrim ( $ url , ' / ' ) )->then (
150+ return $ this ->browser ->get ($ url )->then (
139151 function (Response $ response ) {
140152 return (string )$ response ->getBody ();
141153 },
0 commit comments