-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathGenerator.php
76 lines (65 loc) · 2.04 KB
/
Generator.php
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\VisitorGenerator;
use Piwik\SettingsPiwik;
use Piwik\SettingsServer;
include_once __DIR__ . '/vendor/autoload.php';
class Generator
{
protected $faker;
protected $matomoUrl;
protected $trackNonProfilable = false;
/**
* @param null $matomoUrl
*/
public function __construct($matomoUrl = null)
{
$this->faker = \Faker\Factory::create('en_EN');
$this->faker->addProvider(new Faker\Request($this->faker));
$this->setMatomoUrl($matomoUrl);
}
protected function makeMatomoTracker($idSite)
{
if (SettingsServer::isMatomoForWordPress()) {
$trackerFile = plugin_dir_path(MATOMO_ANALYTICS_FILE) . "tests/phpunit/framework/test-local-tracker.php";
if (file_exists($trackerFile)) {
include_once $trackerFile;
return new \MatomoLocalTracker($idSite, $this->getMatomoUrl());
} else {
throw new \Exception('The visitor generator in Matomo for WordPress works only when the plugin is installed from Git and is only intended for development.');
}
}
return new \MatomoTracker($idSite, $this->getMatomoUrl());
}
/**
* @param $matomoUrl
*/
protected function setMatomoUrl($matomoUrl)
{
$this->matomoUrl = $matomoUrl;
}
/**
* @return string
*/
protected function getMatomoUrl()
{
if ($this->matomoUrl) {
$url = $this->matomoUrl;
} else {
$url = SettingsPiwik::getPiwikUrl();
}
// this is a workaround when force_ssl=1, and the HTTPS URL is not fetchable from CLI
$url = str_replace('https://localhost', 'http://localhost', $url);
return $url;
}
public function setTrackNonProfilable(bool $trackNonProfilable): void
{
$this->trackNonProfilable = $trackNonProfilable;
}
}