diff --git a/.gitattributes b/.gitattributes index 773a14a..7ccb1f3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8,5 +8,5 @@ .gitignore export-ignore .scrutinizer.yml export-ignore .travis.yml export-ignore -phpunit.xml export-ignore +phpunit.xml.dist export-ignore CONTRIBUTING.md export-ignore diff --git a/composer.json b/composer.json index 26b5e23..2902b2c 100644 --- a/composer.json +++ b/composer.json @@ -40,13 +40,6 @@ } }, "scripts": { - "testbench": "composer require --dev \"orchestra/testbench-browser-kit=~3.0\" \"orchestra/database=~3.0\"" - }, - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "minimum-stability": "dev", - "prefer-stable" : true + "testbench": "composer require --dev \"orchestra/testbench-browser-kit=~3.4.0\" \"orchestra/database=~3.4.0\"" + } } diff --git a/config/laravel-tracker.php b/config/laravel-tracker.php index 3ace5d0..87174b9 100644 --- a/config/laravel-tracker.php +++ b/config/laravel-tracker.php @@ -4,26 +4,30 @@ use Arcanedev\LaravelTracker\Support\BindingManager; return [ - /* ------------------------------------------------------------------------------------------------ + + /* ----------------------------------------------------------------- | Enabled - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + 'enabled' => false, - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Database - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + 'database' => [ 'connection' => null, 'prefix' => 'tracker_', ], - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Models - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + 'models' => [ BindingManager::MODEL_AGENT => Models\Agent::class, BindingManager::MODEL_COOKIE => Models\Cookie::class, @@ -44,11 +48,13 @@ BindingManager::MODEL_VISITOR_ACTIVITY => Models\VisitorActivity::class, ], - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Tracking - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + 'tracking' => [ + 'console' => false, 'cookies' => true, 'devices' => true, 'errors' => true, @@ -61,10 +67,11 @@ 'user-agents' => true, ], - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Auth - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + 'auth' => [ 'bindings' => ['auth'], @@ -79,10 +86,11 @@ ], ], - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Cookie - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + 'cookie' => [ /** * A cookie may be created on your visitor device, so you can have @@ -91,18 +99,20 @@ 'name' => null ], - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Session - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + 'session' => [ 'name' => 'tracker_session' ], - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Routes - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + 'routes' => [ 'ignore' => [ 'names' => [ @@ -115,4 +125,5 @@ 'model-columns' => ['id'], ], + ]; diff --git a/phpunit.xml b/phpunit.xml.dist similarity index 100% rename from phpunit.xml rename to phpunit.xml.dist diff --git a/src/Bases/Migration.php b/src/Bases/Migration.php index 17fc0dd..18cccf0 100644 --- a/src/Bases/Migration.php +++ b/src/Bases/Migration.php @@ -10,10 +10,11 @@ */ abstract class Migration extends BaseMigration { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Constructor - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Migration constructor. */ diff --git a/src/Console/PublishCommand.php b/src/Console/PublishCommand.php index eac6970..e35a773 100644 --- a/src/Console/PublishCommand.php +++ b/src/Console/PublishCommand.php @@ -10,10 +10,11 @@ */ class PublishCommand extends Command { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The name and signature of the console command. * @@ -28,10 +29,11 @@ class PublishCommand extends Command */ protected $description = 'Publish the Laravel Tracker config, migrations...'; - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Execute the console command. */ diff --git a/src/Contracts/Detectors/CrawlerDetector.php b/src/Contracts/Detectors/CrawlerDetector.php index d2ecaf7..4b6a431 100644 --- a/src/Contracts/Detectors/CrawlerDetector.php +++ b/src/Contracts/Detectors/CrawlerDetector.php @@ -8,10 +8,11 @@ */ interface CrawlerDetector { - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Check if current request is from a bot. * diff --git a/src/Contracts/Detectors/DeviceDetector.php b/src/Contracts/Detectors/DeviceDetector.php index 4c98d50..46f9bdc 100644 --- a/src/Contracts/Detectors/DeviceDetector.php +++ b/src/Contracts/Detectors/DeviceDetector.php @@ -8,10 +8,11 @@ */ interface DeviceDetector { - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Detect kind, model and mobility. * diff --git a/src/Contracts/Detectors/GeoIpDetector.php b/src/Contracts/Detectors/GeoIpDetector.php index f6dc974..a9af902 100644 --- a/src/Contracts/Detectors/GeoIpDetector.php +++ b/src/Contracts/Detectors/GeoIpDetector.php @@ -8,10 +8,11 @@ */ interface GeoIpDetector { - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Get the geoip data. * diff --git a/src/Contracts/Detectors/LanguageDetector.php b/src/Contracts/Detectors/LanguageDetector.php index 8cca805..6476e52 100644 --- a/src/Contracts/Detectors/LanguageDetector.php +++ b/src/Contracts/Detectors/LanguageDetector.php @@ -8,10 +8,11 @@ */ interface LanguageDetector { - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Detect preference and language-range. * diff --git a/src/Contracts/Models/Device.php b/src/Contracts/Models/Device.php index 901b3c9..f62359b 100644 --- a/src/Contracts/Models/Device.php +++ b/src/Contracts/Models/Device.php @@ -8,19 +8,21 @@ */ interface Device { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Constants - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + const KIND_COMPUTER = 'computer'; const KIND_PHONE = 'phone'; const KIND_TABLET = 'tablet'; const KIND_UNAVAILABLE = 'unavailable'; - /* ------------------------------------------------------------------------------------------------ - | Check Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Check Methods + | ----------------------------------------------------------------- */ + /** * Is this a computer? * diff --git a/src/Contracts/Models/Domain.php b/src/Contracts/Models/Domain.php index a7282a8..39e9689 100644 --- a/src/Contracts/Models/Domain.php +++ b/src/Contracts/Models/Domain.php @@ -10,10 +10,11 @@ */ interface Domain { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Relationships - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Referer relationship. * diff --git a/src/Contracts/Models/Referer.php b/src/Contracts/Models/Referer.php index 41be99c..f58f841 100644 --- a/src/Contracts/Models/Referer.php +++ b/src/Contracts/Models/Referer.php @@ -11,10 +11,11 @@ */ interface Referer { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Relationships - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Domain relationship. * diff --git a/src/Contracts/Models/Route.php b/src/Contracts/Models/Route.php index 7c0117c..2b28599 100644 --- a/src/Contracts/Models/Route.php +++ b/src/Contracts/Models/Route.php @@ -10,10 +10,11 @@ */ interface Route { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Relationships - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Paths relationship. * diff --git a/src/Contracts/Models/RoutePath.php b/src/Contracts/Models/RoutePath.php index ff89637..220d9fd 100644 --- a/src/Contracts/Models/RoutePath.php +++ b/src/Contracts/Models/RoutePath.php @@ -11,10 +11,11 @@ */ interface RoutePath { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Relationships - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Route relationship. * diff --git a/src/Contracts/Models/Visitor.php b/src/Contracts/Models/Visitor.php index d6eae2a..b079589 100644 --- a/src/Contracts/Models/Visitor.php +++ b/src/Contracts/Models/Visitor.php @@ -16,10 +16,11 @@ */ interface Visitor { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Relationships - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * User relationship. * @@ -76,10 +77,11 @@ public function language(); */ public function activities(); - /* ------------------------------------------------------------------------------------------------ - | Check Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Check Methods + | ----------------------------------------------------------------- */ + /** * Check if the user exists. * diff --git a/src/Contracts/Models/VisitorActivity.php b/src/Contracts/Models/VisitorActivity.php index 6b0abf0..52678c7 100644 --- a/src/Contracts/Models/VisitorActivity.php +++ b/src/Contracts/Models/VisitorActivity.php @@ -14,10 +14,11 @@ */ interface VisitorActivity { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Relationships - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Visitor relationship. * @@ -53,10 +54,11 @@ public function referrer(); */ public function error(); - /* ------------------------------------------------------------------------------------------------ - | Check Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Check Methods + | ----------------------------------------------------------------- */ + /** * Check if the referer exists. * diff --git a/src/Contracts/Parsers/RefererParser.php b/src/Contracts/Parsers/RefererParser.php index de39eb3..99b01a1 100644 --- a/src/Contracts/Parsers/RefererParser.php +++ b/src/Contracts/Parsers/RefererParser.php @@ -8,10 +8,11 @@ */ interface RefererParser { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Getters & Setters - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Set the referer. * @@ -49,10 +50,11 @@ public function getSearchTerm(); */ public function isKnown(); - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Parse a referer. * diff --git a/src/Contracts/Parsers/UserAgentParser.php b/src/Contracts/Parsers/UserAgentParser.php index 1c712f4..de59b52 100644 --- a/src/Contracts/Parsers/UserAgentParser.php +++ b/src/Contracts/Parsers/UserAgentParser.php @@ -8,10 +8,11 @@ */ interface UserAgentParser { - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Get the OS version. * diff --git a/src/Contracts/Tracker.php b/src/Contracts/Tracker.php index f1b5262..4f6b7a9 100644 --- a/src/Contracts/Tracker.php +++ b/src/Contracts/Tracker.php @@ -12,10 +12,11 @@ */ interface Tracker { - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Start the tracking. * @@ -48,19 +49,15 @@ public function enable(); */ public function disable(); - /* ------------------------------------------------------------------------------------------------ - | Check Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Check Methods + | ----------------------------------------------------------------- */ + /** * Check if the tracking is enabled. * * @return bool */ public function isEnabled(); - - /* ------------------------------------------------------------------------------------------------ - | Other Functions - | ------------------------------------------------------------------------------------------------ - */ } diff --git a/src/Contracts/Trackers/CookieTracker.php b/src/Contracts/Trackers/CookieTracker.php index 3b00612..a567e7f 100644 --- a/src/Contracts/Trackers/CookieTracker.php +++ b/src/Contracts/Trackers/CookieTracker.php @@ -8,10 +8,11 @@ */ interface CookieTracker { - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Track the cookie. * diff --git a/src/Contracts/Trackers/DeviceTracker.php b/src/Contracts/Trackers/DeviceTracker.php index 60f03c6..c6400c5 100644 --- a/src/Contracts/Trackers/DeviceTracker.php +++ b/src/Contracts/Trackers/DeviceTracker.php @@ -8,10 +8,11 @@ */ interface DeviceTracker { - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Track the device. * diff --git a/src/Contracts/Trackers/ErrorTracker.php b/src/Contracts/Trackers/ErrorTracker.php index b8d5696..d802af9 100644 --- a/src/Contracts/Trackers/ErrorTracker.php +++ b/src/Contracts/Trackers/ErrorTracker.php @@ -1,5 +1,7 @@ detector = $detector; } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Check if current request is from a bot. * diff --git a/src/Detectors/DeviceDetector.php b/src/Detectors/DeviceDetector.php index bfaca3d..bb4f879 100644 --- a/src/Detectors/DeviceDetector.php +++ b/src/Detectors/DeviceDetector.php @@ -12,17 +12,19 @@ */ class DeviceDetector implements DeviceDetectorContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** @var \Arcanedev\Agent\Contracts\Agent */ protected $agent; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Constructor - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * DeviceDetector constructor. * @@ -33,10 +35,11 @@ public function __construct(Agent $agent) $this->agent = $agent; } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Detect kind, model and mobility. * @@ -57,9 +60,14 @@ public function detect() */ public function getDeviceKind() { - if ($this->isTablet()) return Device::KIND_TABLET; - if ($this->isPhone()) return Device::KIND_PHONE; - if ($this->isComputer()) return Device::KIND_COMPUTER; + if ($this->isTablet()) + return Device::KIND_TABLET; + + if ($this->isPhone()) + return Device::KIND_PHONE; + + if ($this->isComputer()) + return Device::KIND_COMPUTER; return Device::KIND_UNAVAILABLE; } diff --git a/src/Detectors/GeoIpDetector.php b/src/Detectors/GeoIpDetector.php index e026479..1261852 100644 --- a/src/Detectors/GeoIpDetector.php +++ b/src/Detectors/GeoIpDetector.php @@ -11,28 +11,36 @@ */ class GeoIpDetector implements GeoIpDetectorContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * @var \Arcanedev\GeoIP\Contracts\GeoIP */ - private $geoip; + private $geoIp; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Constructor - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ - public function __construct(GeoIP $geoip) + + /** + * GeoIpDetector constructor. + * + * @param \Arcanedev\GeoIP\Contracts\GeoIP $geoIp + */ + public function __construct(GeoIP $geoIp) { - $this->geoip = $geoip; + $this->geoIp = $geoIp; } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Get the geoip data. * @@ -43,8 +51,8 @@ public function __construct(GeoIP $geoip) public function search($ipAddress) { try { - if ($location = $this->geoip->location($ipAddress)) { - return $this->renderData($location); + if ($location = $this->geoIp->location($ipAddress)) { + return $this->transform($location); } } catch (\Exception $e) { @@ -54,10 +62,11 @@ public function search($ipAddress) return null; } - /* ------------------------------------------------------------------------------------------------ - | Other Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Other Methods + | ----------------------------------------------------------------- */ + /** * Render the data. * @@ -65,7 +74,7 @@ public function search($ipAddress) * * @return array */ - private function renderData($location) + private function transform($location) { return [ 'iso_code' => $location->iso_code, diff --git a/src/Detectors/LanguageDetector.php b/src/Detectors/LanguageDetector.php index 3c2713e..7ed29b4 100644 --- a/src/Detectors/LanguageDetector.php +++ b/src/Detectors/LanguageDetector.php @@ -11,17 +11,19 @@ */ class LanguageDetector implements LanguageDetectorContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** @var \Arcanedev\Agent\Contracts\Agent */ protected $agent; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Constructor - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * LanguageDetector constructor. * @@ -32,10 +34,11 @@ public function __construct(Agent $agent) $this->agent = $agent; } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Detect preference and language-range. * diff --git a/src/EventListeners/RouteEventSubscriber.php b/src/EventListeners/RouteEventSubscriber.php index 03c9f0f..bc8d154 100644 --- a/src/EventListeners/RouteEventSubscriber.php +++ b/src/EventListeners/RouteEventSubscriber.php @@ -12,17 +12,19 @@ */ class RouteEventSubscriber { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** @var \Arcanedev\LaravelTracker\Contracts\Tracker */ private $tracker; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Constructor - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * RouteEventSubscriber constructor. * @@ -33,10 +35,11 @@ public function __construct(Tracker $manager) $this->tracker = $manager; } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Register the listeners for the subscriber. * @@ -46,8 +49,7 @@ public function subscribe($events) { $class = self::class; - $events->listen('Illuminate\Routing\Events\RouteMatched', "$class@handle"); - $events->listen('router.matched', "$class@handleOldEvent"); + $events->listen(RouteMatched::class, "$class@handle"); } /** @@ -59,14 +61,4 @@ public function handle(RouteMatched $event) { $this->tracker->trackMatchedRoute($event->route, $event->request); } - - /** - * Track the matched route (old event on Laravel 5.1). - * - * @param \Illuminate\Routing\Route $route - */ - public function handleOldEvent(Route $route) - { - $this->tracker->trackMatchedRoute($route, request()); - } } diff --git a/src/Exceptions/ExceptionFactory.php b/src/Exceptions/ExceptionFactory.php index 6cc0e89..9042f2d 100644 --- a/src/Exceptions/ExceptionFactory.php +++ b/src/Exceptions/ExceptionFactory.php @@ -10,10 +10,11 @@ */ class ExceptionFactory { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Supported exceptions. * @@ -37,10 +38,11 @@ class ExceptionFactory E_USER_DEPRECATED => Errors\UserDeprecated::class, ]; - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Make exception. * diff --git a/src/Exceptions/Handler.php b/src/Exceptions/Handler.php index ed7525a..afd5580 100644 --- a/src/Exceptions/Handler.php +++ b/src/Exceptions/Handler.php @@ -12,10 +12,11 @@ */ class Handler implements ExceptionHandlerContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** @var \Arcanedev\LaravelTracker\Contracts\Tracker */ private $manager; @@ -26,10 +27,11 @@ class Handler implements ExceptionHandlerContract private $originalErrorHandler; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Constructor - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Handler constructor. * @@ -44,10 +46,11 @@ public function __construct(Tracker $tracker, ExceptionHandlerContract $illumina $this->originalErrorHandler = set_error_handler([$this, 'handleError']); } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Report or log an exception. * diff --git a/src/LaravelTrackerServiceProvider.php b/src/LaravelTrackerServiceProvider.php index 29be893..38a0fa0 100644 --- a/src/LaravelTrackerServiceProvider.php +++ b/src/LaravelTrackerServiceProvider.php @@ -16,6 +16,7 @@ class LaravelTrackerServiceProvider extends PackageServiceProvider | Properties | ----------------------------------------------------------------- */ + /** * Package name. * @@ -27,11 +28,14 @@ class LaravelTrackerServiceProvider extends PackageServiceProvider | Main Methods | ----------------------------------------------------------------- */ + /** * Register the service provider. */ public function register() { + parent::register(); + $this->registerConfig(); $this->registerProviders([ Providers\PackagesServiceProvider::class, @@ -95,12 +99,13 @@ private function registerDetectors() $this->singleton(Contracts\Detectors\CrawlerDetector::class, function (AppContract $app) { /** @var \Illuminate\Http\Request $request */ $request = $app['request']; - $crawler = new \Jaybizzle\CrawlerDetect\CrawlerDetect( - $request->headers->all(), - $request->server('HTTP_USER_AGENT') - ); - return new Detectors\CrawlerDetector($crawler); + return new Detectors\CrawlerDetector( + new \Jaybizzle\CrawlerDetect\CrawlerDetect( + $request->headers->all(), + $request->server('HTTP_USER_AGENT') + ) + ); }); $this->singleton(Contracts\Detectors\DeviceDetector::class, Detectors\DeviceDetector::class); diff --git a/src/Middleware/Tracking.php b/src/Middleware/Tracking.php index 82c9b34..fcc47d2 100644 --- a/src/Middleware/Tracking.php +++ b/src/Middleware/Tracking.php @@ -11,10 +11,11 @@ */ class Tracking { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The tracker instance. * @@ -22,10 +23,11 @@ class Tracking */ protected $tracker; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Constructor - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Tracking constructor. * @@ -36,10 +38,11 @@ public function __construct(Tracker $tracker) $this->tracker = $tracker; } - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Main Functions - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Handle the incoming request. * diff --git a/src/Models/AbstractModel.php b/src/Models/AbstractModel.php index 77c18fb..3d4a12e 100644 --- a/src/Models/AbstractModel.php +++ b/src/Models/AbstractModel.php @@ -9,15 +9,14 @@ * @author ARCANEDEV * * @property int id - * - * @method static \Arcanedev\LaravelTracker\Models\AbstractModel firstOrCreate(array $attributes, array $values = []) */ abstract class AbstractModel extends Model { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Constructor - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Create a new Eloquent model instance. * diff --git a/src/Models/Agent.php b/src/Models/Agent.php index 1651532..7d4b86d 100644 --- a/src/Models/Agent.php +++ b/src/Models/Agent.php @@ -17,10 +17,11 @@ */ class Agent extends AbstractModel implements AgentContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The table associated with the model. * @@ -38,9 +39,4 @@ class Agent extends AbstractModel implements AgentContract 'browser', 'browser_version', ]; - - /* ------------------------------------------------------------------------------------------------ - | Relationships - | ------------------------------------------------------------------------------------------------ - */ } diff --git a/src/Models/Cookie.php b/src/Models/Cookie.php index 780e3df..c981a76 100644 --- a/src/Models/Cookie.php +++ b/src/Models/Cookie.php @@ -15,10 +15,11 @@ */ class Cookie extends AbstractModel implements CookieContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The table associated with the model. * @@ -32,9 +33,4 @@ class Cookie extends AbstractModel implements CookieContract * @var array */ protected $fillable = ['uuid']; - - /* ------------------------------------------------------------------------------------------------ - | Relationships - | ------------------------------------------------------------------------------------------------ - */ } diff --git a/src/Models/Device.php b/src/Models/Device.php index 557ab45..6fbeff8 100644 --- a/src/Models/Device.php +++ b/src/Models/Device.php @@ -18,10 +18,11 @@ */ class Device extends AbstractModel implements DeviceContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The table associated with the model. * @@ -50,15 +51,11 @@ class Device extends AbstractModel implements DeviceContract 'id' => 'integer', ]; - /* ------------------------------------------------------------------------------------------------ - | Relationships - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Check Methods + | ----------------------------------------------------------------- */ - /* ------------------------------------------------------------------------------------------------ - | Check Functions - | ------------------------------------------------------------------------------------------------ - */ /** * Is this a computer? * diff --git a/src/Models/Domain.php b/src/Models/Domain.php index 16815f0..bf1facf 100644 --- a/src/Models/Domain.php +++ b/src/Models/Domain.php @@ -18,10 +18,11 @@ */ class Domain extends AbstractModel implements DomainContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The table associated with the model. * @@ -45,10 +46,11 @@ class Domain extends AbstractModel implements DomainContract 'id' => 'integer', ]; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Relationships - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Referer relationship. * diff --git a/src/Models/Error.php b/src/Models/Error.php index a7110da..b4d6e7e 100644 --- a/src/Models/Error.php +++ b/src/Models/Error.php @@ -16,10 +16,11 @@ */ class Error extends AbstractModel implements ErrorContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The table associated with the model. * diff --git a/src/Models/GeoIp.php b/src/Models/GeoIp.php index 4f022c1..6aed66f 100644 --- a/src/Models/GeoIp.php +++ b/src/Models/GeoIp.php @@ -25,10 +25,11 @@ */ class GeoIp extends AbstractModel implements GeoIpContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The table associated with the model. * @@ -68,9 +69,4 @@ class GeoIp extends AbstractModel implements GeoIpContract 'dma_code' => 'float', 'metro_code' => 'float', ]; - - /* ------------------------------------------------------------------------------------------------ - | Relationships - | ------------------------------------------------------------------------------------------------ - */ } diff --git a/src/Models/Language.php b/src/Models/Language.php index 68004af..a707d92 100644 --- a/src/Models/Language.php +++ b/src/Models/Language.php @@ -16,10 +16,11 @@ */ class Language extends AbstractModel implements LanguageContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The table associated with the model. * @@ -36,9 +37,4 @@ class Language extends AbstractModel implements LanguageContract 'preference', 'language_range', ]; - - /* ------------------------------------------------------------------------------------------------ - | Relationships - | ------------------------------------------------------------------------------------------------ - */ } diff --git a/src/Models/Path.php b/src/Models/Path.php index 68f661e..4d28eff 100644 --- a/src/Models/Path.php +++ b/src/Models/Path.php @@ -15,10 +15,11 @@ */ class Path extends AbstractModel implements PathContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The table associated with the model. * diff --git a/src/Models/Presenters/VisitorPresenter.php b/src/Models/Presenters/VisitorPresenter.php index 70a6364..1afab36 100644 --- a/src/Models/Presenters/VisitorPresenter.php +++ b/src/Models/Presenters/VisitorPresenter.php @@ -12,10 +12,11 @@ */ trait VisitorPresenter { - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Get the `location_name` attribute. * diff --git a/src/Models/Query.php b/src/Models/Query.php index 84155eb..774ebf2 100644 --- a/src/Models/Query.php +++ b/src/Models/Query.php @@ -16,10 +16,11 @@ */ class Query extends AbstractModel implements QueryContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The table associated with the model. * @@ -43,9 +44,4 @@ class Query extends AbstractModel implements QueryContract 'id' => 'int', 'arguments' => 'array', ]; - - /* ------------------------------------------------------------------------------------------------ - | Relationships - | ------------------------------------------------------------------------------------------------ - */ } diff --git a/src/Models/Referer.php b/src/Models/Referer.php index f1d3889..ca37da3 100644 --- a/src/Models/Referer.php +++ b/src/Models/Referer.php @@ -24,10 +24,11 @@ */ class Referer extends AbstractModel implements RefererContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The table associated with the model. * @@ -59,10 +60,11 @@ class Referer extends AbstractModel implements RefererContract 'domain_id' => 'integer', ]; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Relationships - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Domain relationship. * diff --git a/src/Models/RefererSearchTerm.php b/src/Models/RefererSearchTerm.php index 17eed3f..cc33850 100644 --- a/src/Models/RefererSearchTerm.php +++ b/src/Models/RefererSearchTerm.php @@ -10,10 +10,11 @@ */ class RefererSearchTerm extends AbstractModel implements RefererSearchTermContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The table associated with the model. * diff --git a/src/Models/Route.php b/src/Models/Route.php index 4a2734f..bd04298 100644 --- a/src/Models/Route.php +++ b/src/Models/Route.php @@ -19,10 +19,11 @@ */ class Route extends AbstractModel implements RouteContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The table associated with the model. * @@ -37,10 +38,11 @@ class Route extends AbstractModel implements RouteContract */ protected $fillable = ['name', 'action']; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Relationships - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Paths relationship. * diff --git a/src/Models/RoutePath.php b/src/Models/RoutePath.php index b7769bb..77ebe5f 100644 --- a/src/Models/RoutePath.php +++ b/src/Models/RoutePath.php @@ -20,10 +20,11 @@ */ class RoutePath extends AbstractModel implements RoutePathContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The table associated with the model. * @@ -47,10 +48,11 @@ class RoutePath extends AbstractModel implements RoutePathContract 'route_id' => 'integer', ]; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Relationships - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Route relationship. * diff --git a/src/Models/RoutePathParameter.php b/src/Models/RoutePathParameter.php index d4d61d4..52844ee 100644 --- a/src/Models/RoutePathParameter.php +++ b/src/Models/RoutePathParameter.php @@ -17,10 +17,11 @@ */ class RoutePathParameter extends AbstractModel implements RoutePathParameterContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The table associated with the model. * diff --git a/src/Models/User.php b/src/Models/User.php index 94eb371..a47b58e 100644 --- a/src/Models/User.php +++ b/src/Models/User.php @@ -10,10 +10,11 @@ */ class User extends AbstractModel implements UserContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The table associated with the model. * diff --git a/src/Models/Visitor.php b/src/Models/Visitor.php index 76380f9..1264af1 100644 --- a/src/Models/Visitor.php +++ b/src/Models/Visitor.php @@ -33,16 +33,18 @@ */ class Visitor extends AbstractModel implements SessionContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Traits - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + use Presenters\VisitorPresenter; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The table associated with the model. * @@ -84,10 +86,11 @@ class Visitor extends AbstractModel implements SessionContract 'is_robot' => 'boolean', ]; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Relationships - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * User relationship. * @@ -184,10 +187,11 @@ public function activities() ); } - /* ------------------------------------------------------------------------------------------------ - | Check Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Check Methods + | ----------------------------------------------------------------- */ + /** * Check if the user exists. * diff --git a/src/Models/VisitorActivity.php b/src/Models/VisitorActivity.php index 07b9383..4745396 100644 --- a/src/Models/VisitorActivity.php +++ b/src/Models/VisitorActivity.php @@ -32,10 +32,11 @@ */ class VisitorActivity extends AbstractModel implements VisitorActivityContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The table associated with the model. * @@ -81,10 +82,11 @@ class VisitorActivity extends AbstractModel implements VisitorActivityContract 'error_id' => 'integer', ]; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Relationships - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Visitor relationship. * @@ -145,10 +147,11 @@ public function error() ); } - /* ------------------------------------------------------------------------------------------------ - | Check Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Check Methods + | ----------------------------------------------------------------- */ + /** * Check if the referer exists. * diff --git a/src/Parsers/RefererParser.php b/src/Parsers/RefererParser.php index 602f508..1ad3b74 100644 --- a/src/Parsers/RefererParser.php +++ b/src/Parsers/RefererParser.php @@ -10,10 +10,11 @@ */ class RefererParser implements RefererParserContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Referer parser instance. * @@ -28,10 +29,11 @@ class RefererParser implements RefererParserContract */ private $referer; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Constructor - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * RefererParser constructor. * @@ -42,10 +44,11 @@ public function __construct($parser) $this->parser = $parser; } - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Getters & Setters - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Set the referer. * @@ -100,10 +103,11 @@ public function isKnown() return $this->referer->isKnown(); } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Parse a referer. * diff --git a/src/Parsers/UserAgentParser.php b/src/Parsers/UserAgentParser.php index bdf3212..1fbcb66 100644 --- a/src/Parsers/UserAgentParser.php +++ b/src/Parsers/UserAgentParser.php @@ -10,20 +10,22 @@ */ class UserAgentParser implements UserAgentParserContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** @var \UAParser\Parser */ protected $parser; /** @var string */ public $basePath; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Constructor - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * UserAgentParser constructor. * @@ -41,10 +43,11 @@ public function __construct($parser, $basePath, $userAgent = null) $this->basePath = $basePath; } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Get the OS version. * @@ -134,10 +137,11 @@ public function getDevice() return $this->parser->device; } - /* ------------------------------------------------------------------------------------------------ - | Other Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Other Methods + | ----------------------------------------------------------------- */ + /** * Prepare the version. * diff --git a/src/Providers/CommandServiceProvider.php b/src/Providers/CommandServiceProvider.php index 3865701..1b1cdf3 100644 --- a/src/Providers/CommandServiceProvider.php +++ b/src/Providers/CommandServiceProvider.php @@ -11,10 +11,11 @@ */ class CommandServiceProvider extends ServiceProvider { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The commands to be registered. * diff --git a/src/Providers/EventServiceProvider.php b/src/Providers/EventServiceProvider.php index 7148afa..a2a2296 100644 --- a/src/Providers/EventServiceProvider.php +++ b/src/Providers/EventServiceProvider.php @@ -10,10 +10,11 @@ */ class EventServiceProvider extends ServiceProvider { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * The event listener mappings for the application. * @@ -32,10 +33,11 @@ class EventServiceProvider extends ServiceProvider \Arcanedev\LaravelTracker\EventListeners\RouteEventSubscriber::class, ]; - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Register the application's event listeners. */ diff --git a/src/Providers/PackagesServiceProvider.php b/src/Providers/PackagesServiceProvider.php index c6d3d91..049b1af 100644 --- a/src/Providers/PackagesServiceProvider.php +++ b/src/Providers/PackagesServiceProvider.php @@ -10,15 +10,18 @@ */ class PackagesServiceProvider extends ServiceProvider { - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Register the dependencies. */ public function register() { + parent::register(); + $this->registerProviders([ \Arcanedev\GeoIP\GeoIPServiceProvider::class, \Arcanedev\Agent\AgentServiceProvider::class, diff --git a/src/Support/BindingManager.php b/src/Support/BindingManager.php index 6860719..52b6585 100644 --- a/src/Support/BindingManager.php +++ b/src/Support/BindingManager.php @@ -12,10 +12,11 @@ */ class BindingManager { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Constants - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + const MODEL_AGENT = 'agent'; const MODEL_COOKIE = 'cookie'; const MODEL_DEVICE = 'device'; @@ -34,10 +35,11 @@ class BindingManager const MODEL_VISITOR = 'visitor'; const MODEL_VISITOR_ACTIVITY = 'visitor-activity'; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Models bindings. * @@ -84,10 +86,11 @@ class BindingManager TrackerContracts\VisitorActivityTracker::class => Trackers\VisitorActivityTracker::class, ]; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Getters & Setters - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Get the models bindings. * diff --git a/src/Tracker.php b/src/Tracker.php index 23358c7..ac4128f 100644 --- a/src/Tracker.php +++ b/src/Tracker.php @@ -18,12 +18,14 @@ class Tracker implements TrackerContract | Traits | ----------------------------------------------------------------- */ + use Traits\TrackersMaker; /* ----------------------------------------------------------------- | Properties | ----------------------------------------------------------------- */ + /** * The application container. * @@ -93,6 +95,7 @@ class Tracker implements TrackerContract | Constructor | ----------------------------------------------------------------- */ + /** * Tracker constructor. * @@ -108,6 +111,7 @@ public function __construct(Application $app) | Getters & Setters | ----------------------------------------------------------------- */ + /** * Get the application instance. * @@ -167,6 +171,7 @@ private function setRequest(Request $request) | Main Methods | ----------------------------------------------------------------- */ + /** * Start the tracking. * @@ -243,6 +248,7 @@ public function disable() | Check Methods | ----------------------------------------------------------------- */ + /** * Check if the tracker is enabled. * @@ -273,6 +279,7 @@ private function trackIfEnabled($key, \Closure $callback, $default = null) | Other Methods | ----------------------------------------------------------------- */ + /** * Merge visitor data. * diff --git a/src/Trackers/AbstractTracker.php b/src/Trackers/AbstractTracker.php index 806e083..fc7a439 100644 --- a/src/Trackers/AbstractTracker.php +++ b/src/Trackers/AbstractTracker.php @@ -10,29 +10,34 @@ */ abstract class AbstractTracker { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** @var \Illuminate\Contracts\Foundation\Application */ private $app; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Constructor - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * AbstractTracker constructor. + * + * @param \Illuminate\Contracts\Foundation\Application $app */ public function __construct(Application $app) { $this->app = $app; } - /* ------------------------------------------------------------------------------------------------ - | Common Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Common Methods + | ----------------------------------------------------------------- */ + /** * Get the config instance. * @@ -71,7 +76,7 @@ protected function getConfig($key, $default = null) * * @param string $name * - * @return mixed + * @return \Illuminate\Database\Eloquent\Model|mixed */ protected function makeModel($name) { diff --git a/src/Trackers/CookieTracker.php b/src/Trackers/CookieTracker.php index d356ab8..6e3557f 100644 --- a/src/Trackers/CookieTracker.php +++ b/src/Trackers/CookieTracker.php @@ -2,6 +2,7 @@ use Arcanedev\LaravelTracker\Contracts\Trackers\CookieTracker as CookieTrackerContract; use Arcanedev\LaravelTracker\Support\BindingManager; +use Illuminate\Contracts\Cookie\QueueingFactory; use Ramsey\Uuid\Uuid; /** @@ -12,10 +13,11 @@ */ class CookieTracker extends AbstractTracker implements CookieTrackerContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Getters and Setters - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Get the model. * @@ -26,10 +28,11 @@ protected function getModel() return $this->makeModel(BindingManager::MODEL_COOKIE); } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Track the cookie. * @@ -46,13 +49,16 @@ public function track($cookie) } return $this->getModel() - ->firstOrCreate(['uuid' => $cookie])->id; + ->newQuery() + ->firstOrCreate(['uuid' => $cookie]) + ->getKey(); } - /* ------------------------------------------------------------------------------------------------ - | Other Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Other Methods + | ----------------------------------------------------------------- */ + /** * Get the cookie instance. * @@ -60,6 +66,6 @@ public function track($cookie) */ private function cookie() { - return $this->make(\Illuminate\Contracts\Cookie\QueueingFactory::class); + return $this->make(QueueingFactory::class); } } diff --git a/src/Trackers/DeviceTracker.php b/src/Trackers/DeviceTracker.php index 9c49d9b..e0114df 100644 --- a/src/Trackers/DeviceTracker.php +++ b/src/Trackers/DeviceTracker.php @@ -13,10 +13,11 @@ */ class DeviceTracker extends AbstractTracker implements DeviceTrackerContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Getters & Setters - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Get the model. * @@ -43,10 +44,11 @@ private function getUserAgentParser() return $this->make(UserAgentParser::class); } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Track the device. * @@ -55,13 +57,16 @@ private function getUserAgentParser() public function track() { return $this->getModel() - ->firstOrCreate($this->getCurrentDeviceProperties())->id; + ->newQuery() + ->firstOrCreate($this->getCurrentDeviceProperties()) + ->getKey(); } - /* ------------------------------------------------------------------------------------------------ - | Other Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Other Methods + | ----------------------------------------------------------------- */ + /** * Get the current device properties. * diff --git a/src/Trackers/ErrorTracker.php b/src/Trackers/ErrorTracker.php index 8fd5dba..e514407 100644 --- a/src/Trackers/ErrorTracker.php +++ b/src/Trackers/ErrorTracker.php @@ -12,10 +12,11 @@ */ class ErrorTracker extends AbstractTracker implements ErrorTrackerContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Getters and Setters - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Get the model. * @@ -26,10 +27,11 @@ protected function getModel() return $this->makeModel(BindingManager::MODEL_ERROR); } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Track the exception error. * @@ -39,17 +41,17 @@ protected function getModel() */ public function track(Exception $exception) { - return $this->getModel() - ->firstOrCreate([ - 'code' => $this->getCode($exception), - 'message' => $exception->getMessage(), - ])->id; + return $this->getModel()->newQuery()->firstOrCreate([ + 'code' => $this->getCode($exception), + 'message' => $exception->getMessage(), + ])->getKey(); } - /* ------------------------------------------------------------------------------------------------ - | Other Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Other Methods + | ----------------------------------------------------------------- */ + /** * Get the code from the exception. * diff --git a/src/Trackers/GeoIpTracker.php b/src/Trackers/GeoIpTracker.php index 03d7ca3..96e1a12 100644 --- a/src/Trackers/GeoIpTracker.php +++ b/src/Trackers/GeoIpTracker.php @@ -13,10 +13,11 @@ */ class GeoIpTracker extends AbstractTracker implements GeoIpTrackerContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Getters and Setters - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Get the model. * @@ -35,10 +36,11 @@ private function getGeoIpDetector() return $this->make(GeoIpDetector::class); } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Track the ip address. * @@ -50,7 +52,9 @@ public function track($ipAddress) { if ($data = $this->getGeoIpDetector()->search($ipAddress)) { return $this->getModel() - ->firstOrCreate(Arr::only($data, ['latitude', 'longitude']), $data)->id; + ->newQuery() + ->firstOrCreate(Arr::only($data, ['latitude', 'longitude']), $data) + ->getKey(); } return null; diff --git a/src/Trackers/LanguageTracker.php b/src/Trackers/LanguageTracker.php index eefe80a..364ba22 100644 --- a/src/Trackers/LanguageTracker.php +++ b/src/Trackers/LanguageTracker.php @@ -12,10 +12,11 @@ */ class LanguageTracker extends AbstractTracker implements LanguageTrackerContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Getters and Setters - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Get the model. * @@ -34,10 +35,11 @@ private function getLanguageDetector() return $this->make(LanguageDetector::class); } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Track the language. * @@ -46,8 +48,9 @@ private function getLanguageDetector() public function track() { return $this->getModel() + ->newQuery() ->firstOrCreate( $this->getLanguageDetector()->detect() - )->id; + )->getKey(); } } diff --git a/src/Trackers/PathTracker.php b/src/Trackers/PathTracker.php index d124a06..bc3e1db 100644 --- a/src/Trackers/PathTracker.php +++ b/src/Trackers/PathTracker.php @@ -11,10 +11,11 @@ */ class PathTracker extends AbstractTracker implements PathTrackerContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Getters and Setters - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Get the model. * @@ -25,10 +26,11 @@ protected function getModel() return $this->makeModel(BindingManager::MODEL_PATH); } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Track the path. * @@ -39,6 +41,8 @@ protected function getModel() public function track($path) { return $this->getModel() - ->firstOrCreate(compact('path'))->id; + ->newQuery() + ->firstOrCreate(compact('path')) + ->getKey(); } } diff --git a/src/Trackers/QueryTracker.php b/src/Trackers/QueryTracker.php index edbf370..67364d8 100644 --- a/src/Trackers/QueryTracker.php +++ b/src/Trackers/QueryTracker.php @@ -12,10 +12,11 @@ */ class QueryTracker extends AbstractTracker implements QueryTrackerContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Getters and Setters - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Get the model. * @@ -26,10 +27,11 @@ protected function getModel() return $this->makeModel(BindingManager::MODEL_QUERY); } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Track the query. * @@ -48,13 +50,16 @@ public function track(array $queries) ]; return $this->getModel() - ->firstOrCreate(Arr::only($data, ['query']), $data)->id; + ->newQuery() + ->firstOrCreate(Arr::only($data, ['query']), $data) + ->getKey(); } - /* ------------------------------------------------------------------------------------------------ - | Other Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Other Methods + | ----------------------------------------------------------------- */ + /** * Prepare the query. * diff --git a/src/Trackers/RefererTracker.php b/src/Trackers/RefererTracker.php index 39186b3..07937df 100644 --- a/src/Trackers/RefererTracker.php +++ b/src/Trackers/RefererTracker.php @@ -13,10 +13,11 @@ */ class RefererTracker extends AbstractTracker implements RefererTrackerContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Getters and Setters - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Get the model. * @@ -35,10 +36,11 @@ private function getRefererParser() return $this->make(RefererParser::class); } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Track the referer and return the id. * @@ -52,11 +54,10 @@ public function track($refererUrl, $pageUrl) $firstParsed = $this->getRefererParser()->parseUrl($refererUrl); if ($firstParsed) { - $domainId = $this->trackDomain($firstParsed['domain']); $attributes = [ 'url' => $firstParsed['url'], 'host' => $firstParsed['host'], - 'domain_id' => $domainId, + 'domain_id' => $this->trackDomain($firstParsed['domain']), 'medium' => null, 'source' => null, 'search_terms_hash' => null, @@ -71,7 +72,7 @@ public function track($refererUrl, $pageUrl) } /** @var \Arcanedev\LaravelTracker\Models\Referer $referer */ - $referer = $this->getModel()->firstOrCreate( + $referer = $this->getModel()->newQuery()->firstOrCreate( Arr::only($attributes, ['url', 'search_terms_hash']), $attributes ); @@ -96,7 +97,9 @@ public function track($refererUrl, $pageUrl) private function trackDomain($name) { return $this->makeModel(BindingManager::MODEL_DOMAIN) - ->firstOrCreate(compact('name'))->id; + ->newQuery() + ->firstOrCreate(compact('name')) + ->getKey(); } /** diff --git a/src/Trackers/RouteTracker.php b/src/Trackers/RouteTracker.php index ee8598a..6ca8f25 100644 --- a/src/Trackers/RouteTracker.php +++ b/src/Trackers/RouteTracker.php @@ -16,10 +16,11 @@ */ class RouteTracker extends AbstractTracker implements RouteTrackerContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Getters and Setters - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Get the model. * @@ -30,10 +31,11 @@ protected function getModel() return $this->makeModel(BindingManager::MODEL_ROUTE); } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Check if the route is trackable. * @@ -62,10 +64,11 @@ public function track(Route $route, Request $request) ); } - /* ------------------------------------------------------------------------------------------------ - | Other Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Other Methods + | ----------------------------------------------------------------- */ + /** * Track the current route. * @@ -75,11 +78,10 @@ public function track(Route $route, Request $request) */ private function trackRoute(Route $route) { - return $this->getModel() - ->firstOrCreate([ - 'name' => $this->getRouteName($route), - 'action' => $route->getActionName(), - ])->id; + return $this->getModel()->newQuery()->firstOrCreate([ + 'name' => $this->getRouteName($route), + 'action' => $route->getActionName(), + ])->getKey(); } /** @@ -159,7 +161,7 @@ private function trackRoutePath(Route $route, Request $request, $routeId) if ($model->wasRecentlyCreated) $this->trackRoutePathParameters($route, $model); - return $model->id; + return $model->getKey(); } /** diff --git a/src/Trackers/UserAgentTracker.php b/src/Trackers/UserAgentTracker.php index 73add5b..4846ab7 100644 --- a/src/Trackers/UserAgentTracker.php +++ b/src/Trackers/UserAgentTracker.php @@ -12,10 +12,11 @@ */ class UserAgentTracker extends AbstractTracker implements UserAgentTrackerContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Getters and Setters - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Get the model. * @@ -36,10 +37,11 @@ public function getUserAgentParser() return $this->make(UserAgentParser::class); } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Track the user agent. * @@ -48,13 +50,16 @@ public function getUserAgentParser() public function track() { return $this->getModel() - ->firstOrCreate($data = $this->prepareData())->id; + ->newQuery() + ->firstOrCreate($this->prepareData()) + ->getKey(); } - /* ------------------------------------------------------------------------------------------------ - | Other Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Other Methods + | ----------------------------------------------------------------- */ + /** * Prepare the data. * diff --git a/src/Trackers/UserTracker.php b/src/Trackers/UserTracker.php index bb69d25..703280c 100644 --- a/src/Trackers/UserTracker.php +++ b/src/Trackers/UserTracker.php @@ -12,17 +12,19 @@ */ class UserTracker extends AbstractTracker implements UserTrackerContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** @var array */ private $auths = []; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Constructor - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * UserTracker constructor. * @@ -45,10 +47,11 @@ private function instantiateAuthentication() } } - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Getters and Setters - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Get the model. * @@ -59,10 +62,11 @@ protected function getModel() return $this->makeModel(BindingManager::MODEL_USER); } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Track the current authenticated user id. * @@ -75,10 +79,11 @@ public function track() : null; } - /* ------------------------------------------------------------------------------------------------ - | Other Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Other Methods + | ----------------------------------------------------------------- */ + /** * Check if the user is authenticated. * diff --git a/src/Trackers/VisitorActivityTracker.php b/src/Trackers/VisitorActivityTracker.php index 3ac0d34..20514c0 100644 --- a/src/Trackers/VisitorActivityTracker.php +++ b/src/Trackers/VisitorActivityTracker.php @@ -11,10 +11,11 @@ */ class VisitorActivityTracker extends AbstractTracker implements VisitorActivityTrackerContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Getters and Setters - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Get the model. * @@ -25,10 +26,11 @@ protected function getModel() return $this->makeModel(BindingManager::MODEL_VISITOR_ACTIVITY); } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Track the visitor activity. * @@ -41,6 +43,6 @@ public function track(array $data) $model = $this->getModel()->fill($data); $model->save(); - return $model->id; + return $model->getKey(); } } diff --git a/src/Trackers/VisitorTracker.php b/src/Trackers/VisitorTracker.php index d414eae..6363851 100644 --- a/src/Trackers/VisitorTracker.php +++ b/src/Trackers/VisitorTracker.php @@ -14,17 +14,19 @@ */ class VisitorTracker extends AbstractTracker implements VisitorTrackerContract { - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Properties - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** @var array */ private $visitorInfo = []; - /* ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- | Getters and Setters - | ------------------------------------------------------------------------------------------------ + | ----------------------------------------------------------------- */ + /** * Get the model. * @@ -79,10 +81,11 @@ private function setVisitorId($id) $this->visitorInfo['id'] = $id; } - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Track the visitor. * @@ -112,10 +115,11 @@ public function checkData(array $currentData, array $newData) : $newData; } - /* ------------------------------------------------------------------------------------------------ - | Other Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Other Methods + | ----------------------------------------------------------------- */ + /** * Update the visitor data. * @@ -151,7 +155,7 @@ private function getVisitorData($column = null) */ private function checkIfUserChanged(array $data) { - $model = $this->getModel()->find($this->getVisitorData('id')); + $model = $this->getModel()->newQuery()->find($this->getVisitorData('id')); if ( ! is_null($model) && @@ -247,7 +251,7 @@ private function createVisitorIfIsUnknown() /** @var \Arcanedev\LaravelTracker\Models\Visitor $visitor */ if ($this->isVisitorKnown()) { - $visitor = $model->find($id = $this->getVisitorData('id')); + $visitor = $model->newQuery()->find($id = $this->getVisitorData($model->getKeyName())); $visitor->updated_at = Carbon::now(); $visitor->save(); @@ -256,8 +260,10 @@ private function createVisitorIfIsUnknown() return true; } - $visitor = $model->firstOrCreate(Arr::only($this->visitorInfo, ['uuid']), $this->visitorInfo); - $this->setVisitorId($visitor->id); + $visitor = $model->newQuery() + ->firstOrCreate(Arr::only($this->visitorInfo, ['uuid']), $this->visitorInfo); + + $this->setVisitorId($visitor->getKey()); $this->putSessionData($this->visitorInfo); return false; diff --git a/src/Traits/TrackersMaker.php b/src/Traits/TrackersMaker.php index 3ea4525..63ae80d 100644 --- a/src/Traits/TrackersMaker.php +++ b/src/Traits/TrackersMaker.php @@ -10,10 +10,11 @@ */ trait TrackersMaker { - /* ------------------------------------------------------------------------------------------------ - | Main Functions - | ------------------------------------------------------------------------------------------------ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- */ + /** * Get the cookie tracker. *