Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
SubversionProxy | |
0.00% |
0 / 34 |
|
0.00% |
0 / 7 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
canConnect | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getFile | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDiff | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
getLog | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
getDirList | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
_proxy | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\CodeReview\Backend; |
4 | |
5 | use Exception; |
6 | use MediaWiki\MediaWikiServices; |
7 | |
8 | /** |
9 | * Using a remote JSON proxy |
10 | */ |
11 | class SubversionProxy extends SubversionAdaptor { |
12 | |
13 | private string $mProxy; |
14 | |
15 | private int $mTimeout; |
16 | |
17 | /** |
18 | * @param CodeRepository|string $repo |
19 | * @param string $proxy |
20 | * @param int $timeout |
21 | */ |
22 | public function __construct( $repo, $proxy, $timeout = 30 ) { |
23 | parent::__construct( $repo ); |
24 | $this->mProxy = $proxy; |
25 | $this->mTimeout = $timeout; |
26 | } |
27 | |
28 | public function canConnect() { |
29 | // TODO! |
30 | return true; |
31 | } |
32 | |
33 | /** |
34 | * @param string $path |
35 | * @param null $rev |
36 | * |
37 | * @return never |
38 | * @throws Exception |
39 | */ |
40 | public function getFile( $path, $rev = null ) { |
41 | throw new Exception( 'NYI' ); |
42 | } |
43 | |
44 | /** @inheritDoc */ |
45 | public function getDiff( $path, $rev1, $rev2 ) { |
46 | return $this->_proxy( [ |
47 | 'action' => 'diff', |
48 | 'base' => $this->mRepoPath, |
49 | 'path' => $path, |
50 | 'rev1' => $rev1, |
51 | 'rev2' => $rev2 |
52 | ] ); |
53 | } |
54 | |
55 | /** @inheritDoc */ |
56 | public function getLog( $path, $startRev = null, $endRev = null ) { |
57 | return $this->_proxy( [ |
58 | 'action' => 'log', |
59 | 'base' => $this->mRepoPath, |
60 | 'path' => $path, |
61 | 'start' => $startRev, |
62 | 'end' => $endRev |
63 | ] ); |
64 | } |
65 | |
66 | /** @inheritDoc */ |
67 | public function getDirList( $path, $rev = null ) { |
68 | return $this->_proxy( [ |
69 | 'action' => 'list', |
70 | 'base' => $this->mRepoPath, |
71 | 'path' => $path, |
72 | 'rev' => $rev |
73 | ] ); |
74 | } |
75 | |
76 | /** |
77 | * @param array $params |
78 | * @return mixed |
79 | */ |
80 | protected function _proxy( $params ) { |
81 | foreach ( $params as $key => $val ) { |
82 | if ( $val === null ) { |
83 | // Don't pass nulls to remote |
84 | unset( $params[$key] ); |
85 | } |
86 | } |
87 | $target = $this->mProxy . '?' . wfArrayToCgi( $params ); |
88 | $blob = MediaWikiServices::getInstance()->getHttpRequestFactory() |
89 | ->get( $target, [ 'timeout' => $this->mTimeout ], __METHOD__ ); |
90 | if ( $blob === null ) { |
91 | throw new Exception( 'SVN proxy error' ); |
92 | } |
93 | return unserialize( $blob ); |
94 | } |
95 | } |