Skip to content

Commit

Permalink
Allow overriding
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioribeiro committed Nov 23, 2015
1 parent 20361f6 commit e70ad31
Showing 1 changed file with 28 additions and 37 deletions.
65 changes: 28 additions & 37 deletions src/Tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@

class Tracker
{
private $config;
protected $config;

/**
* @var \Illuminate\Routing\Router
*/
private $route;
protected $route;

private $logger;
protected $logger;
/**
* @var \Illuminate\Foundation\Application
*/
private $laravel;
protected $laravel;

private $enabled = true;
protected $enabled = true;

private $sessionData;
protected $sessionData;

public function __construct(
Config $config,
Expand Down Expand Up @@ -72,7 +72,7 @@ public function track()
/**
* @return array
*/
private function getSessionData()
protected function getSessionData()
{
$sessionData = array(
'user_id' => $this->getUserId(),
Expand All @@ -96,7 +96,7 @@ private function getSessionData()
/**
* @return array
*/
private function getLogData()
protected function getLogData()
{
return array(
'session_id' => $this->getSessionId(true),
Expand Down Expand Up @@ -171,23 +171,20 @@ public function getQueryId()
public function routerMatched($log)
{
if ($this->dataRepositoryManager->routeIsTrackable($this->route))
{
if ($log)
{ if ($log)
{
$this->dataRepositoryManager->updateRoute(
$this->getRoutePathId()
);
);
}
}

// Router was matched but this route is not trackable
// Let's just delete the stored data, because There's not a
// really clean way of doing this because if a route is not
// realy clean way of doing this because if a route is not
// matched, and this happens ages after the app is booted,
// we still need to store data from the request.
// we till need to store data from the request.
else
{
$this->turnOff();
{ $this->turnOff();

$this->deleteCurrentLog();
}
Expand All @@ -198,7 +195,7 @@ public function trackVisit($route, $request)
$this->dataRepositoryManager->trackRoute($route, $request);
}

private function getRefererId()
protected function getRefererId()
{
return $this->config->get('log_referers')
? $this->dataRepositoryManager->getRefererId(
Expand All @@ -212,7 +209,7 @@ public function getDomainId($domain)
return $this->dataRepositoryManager->getDomainId($domain);
}

private function getRoutePathId()
protected function getRoutePathId()
{
return $this->dataRepositoryManager->getRoutePathId($this->route, $this->request);
}
Expand All @@ -231,8 +228,7 @@ public function allSessions()
}

public function parserIsAvailable()
{
if ( ! $this->dataRepositoryManager->parserIsAvailable() )
{ if ( ! $this->dataRepositoryManager->parserIsAvailable() )
{
$this->logger->error('Tracker: uaparser regex file not available. "Execute php artisan tracker:updateparser" to generate it.');

Expand All @@ -242,21 +238,20 @@ public function parserIsAvailable()
return true;
}

private function isTrackableIp()
protected function isTrackableIp()
{
return ! ipv4_in_range(
$this->request->getClientIp(),
$this->config->get('do_not_track_ips')
);
}

private function isTrackableEnvironment()
protected function isTrackableEnvironment()
{
return ! in_array(
$this->laravel->environment(),
$this->config->get('do_not_track_environments')
);
}
); }

public function logSqlQuery($query, $bindings, $time, $name)
{
Expand All @@ -271,15 +266,15 @@ public function logSqlQuery($query, $bindings, $time, $name)
}
}

private function isSqlQueriesLoggableConnection($name)
protected function isSqlQueriesLoggableConnection($name)
{
return ! in_array(
$name,
$this->config->get('do_not_log_sql_queries_connections')
);
}

private function isTrackable()
protected function isTrackable()
{
return $this->config->get('enabled') &&
$this->logIsEnabled() &&
Expand Down Expand Up @@ -351,27 +346,25 @@ public function isRobot()
return $this->dataRepositoryManager->isRobot();
}

private function notRobotOrTrackable()
protected function notRobotOrTrackable()
{
return
! $this->isRobot() ||
! $this->config->get('do_not_track_robots');
}

private function getGeoIpId()
protected function getGeoIpId()
{
return $this->config->get('log_geoip')
? $this->dataRepositoryManager->getGeoIpId($this->request->getClientIp())
: null;
}

private function getAgentId()
protected function getAgentId()
{
return $this->config->get('log_user_agents')
? $this->dataRepositoryManager->getAgentId()
: null;
}

public function logByRouteName($name, $minutes = null)
{
if ($minutes)
Expand All @@ -387,12 +380,12 @@ public function getConfig($key)
return $this->config->get($key);
}

private function deleteCurrentLog()
protected function deleteCurrentLog()
{
$this->dataRepositoryManager->logRepository->delete();
}

private function logIsEnabled()
protected function logIsEnabled()
{
return
$this->config->get('log_enabled') ||
Expand All @@ -401,21 +394,20 @@ private function logIsEnabled()
$this->config->get('log_events') ||
$this->config->get('log_geoip') ||
$this->config->get('log_user_agents') ||
$this->config->get('log_users') ||
$tis->config->get('log_users') ||
$this->config->get('log_devices') ||
$this->config->get('log_referers') ||
$this->config->get('log_paths') ||
$this->config->get('log_queries') ||
$this->config->get('log_routes') ||
$this->config->get('log_exceptions');
}

public function isEnabled()
{
return $this->enabled;
}

private function turnOff()
protected function turnOff()
{
$this->enabled = false;
}
Expand All @@ -429,5 +421,4 @@ public function checkCurrentUser()

return false;
}

}

0 comments on commit e70ad31

Please sign in to comment.