blob: 98f5843f7d86ca85fba625d07f4fd5cb39dc88d6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tests\Framework\Mock;
use Piwik\Archiver\Request;
use Piwik\CliMulti;
class FakeCliMulti extends CliMulti
{
public static $specifiedResults = null;
public function request(array $piwikUrls)
{
if (empty(FakeCliMulti::$specifiedResults)) {
return parent::request($piwikUrls);
}
$results = array();
foreach ($piwikUrls as $url) {
if ($url instanceof Request) {
$url->start();
$url = (string)$url;
}
$results[] = $this->getSpecifiedResult($url);
}
return $results;
}
private function getSpecifiedResult($url)
{
foreach (FakeCliMulti::$specifiedResults as $pattern => $result) {
if (substr($pattern, 0, 1) == '/'
&& substr($pattern, strlen($pattern) - 1, 1) == '/'
) {
$isMatch = preg_match($pattern, $url);
} else {
$isMatch = $pattern == $url;
}
if (!$isMatch) {
continue;
}
if (is_callable($result)) {
return $result($url);
} else {
return $result;
}
}
return null;
}
}
|