Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose some informative methods #28

Merged
merged 2 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: php
php:
- 7.0
- 7.1
- 7.2
- 7.3
before_script:
- composer self-update
- composer install --prefer-source --no-interaction
Expand Down
2 changes: 1 addition & 1 deletion src/Keys.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function visitsTotal()
public function ip($ip)
{
return $this->visits . '_' .
snake_case("recorded_ips:" . ($this->instanceOfModel ? "{$this->id}:" : '') . $ip);
Str::snake("recorded_ips:" . ($this->instanceOfModel ? "{$this->id}:" : '') . $ip);
}


Expand Down
3 changes: 2 additions & 1 deletion src/Traits/Periods.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace awssat\Visits\Traits;

use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Exception;

trait Periods
Expand Down Expand Up @@ -42,7 +43,7 @@ protected function noExpiration($periodKey)
protected function newExpiration($period)
{
try {
$periodCarbon = $this->xHoursPeriod($period) ?? Carbon::now()->{'endOf' . studly_case($period)}();
$periodCarbon = $this->xHoursPeriod($period) ?? Carbon::now()->{'endOf' . Str::studly($period)}();
} catch (Exception $e) {
throw new Exception("Wrong period: `{$period}`! please update config/visits.php file.");
}
Expand Down
19 changes: 15 additions & 4 deletions src/Traits/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ protected function recordCountry($inc)
*/
protected function recordRefer($inc)
{
$referer = app(Referer::class)->get();
$this->redis->zincrby($this->keys->visits."_referers:{$this->keys->id}", $inc, $referer);
$this->redis->zincrby($this->keys->visits."_referers:{$this->keys->id}", $inc, $this->getVisitorReferer());
}

/**
Expand Down Expand Up @@ -56,7 +55,7 @@ protected function recordPeriods($inc)
* Gets visitor country code
* @return mixed|string
*/
protected function getVisitorCountry()
public function getVisitorCountry()
{
return strtolower(geoip()->getLocation()->iso_code);
}
Expand Down Expand Up @@ -94,7 +93,19 @@ public function getVisitorOperatingSystem()
*/
public function getVisitorLanguage()
{
$language = request()->getPreferredLanguage();
if (false !== $position = strpos($language, '_')) {
$language = substr($language, 0, $position);
}
return $language;
}

return request()->getPreferredLanguage();
/**
* Gets visitor referer
* @return mixed|string
*/
public function getVisitorReferer()
{
return app(Referer::class)->get();
}
}
3 changes: 2 additions & 1 deletion src/Visits.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Support\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Redis;
use Jaybizzle\CrawlerDetect\CrawlerDetect;

Expand Down Expand Up @@ -192,7 +193,7 @@ public function increment($inc = 1, $force = false, $ignore = [])
//NOTE: $$method is parameter also .. ($periods,$country,$refer)
foreach (['country', 'refer', 'periods', 'operatingSystem', 'language'] as $method) {
if(! in_array($method, $ignore)) {
$this->{'record'.studly_case($method)}($inc);
$this->{'record'.Str::studly($method)}($inc);
}
}
}
Expand Down