Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
error #4 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
weboAp committed Jun 7, 2015
0 parents commit e33cdbf
Show file tree
Hide file tree
Showing 21 changed files with 1,021 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor
composer.phar
composer.lock
.DS_Store
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: php

php:
- 5.3
- 5.4
- 5.5

before_script:
- curl -s http://getcomposer.org/installer | php
- php composer.phar install --dev

script: phpunit
122 changes: 122 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#Visitor
==============

Register your visitors, Page hists, and count for Laravel 5

for laravel 4 use ver v1.0.0

### Installation


The recommended way to install Winput is through composer.

## Step 1

Just add to `composer.json` file:

``` json
{
"require": {
"weboap/visitor": "dev-master"
}
}
```

then run
``` php
php composer.phar update
```

## Step 2

Add
``` php
'Weboap\Visitor\VisitorServiceProvider'
```

to the list of service providers in app/config/app.php

## Step 3

Migrate the Visitor Table
Run

``` php
php artisan vendor:publish
```
then

``` php
php artisan migrate
```
to migrate visitor table

the config.php will be copied to /config at the same time

``` php
/config/visitor.php
```

costumize it accordinly



## Step 5 (Optional)

Visit
http://dev.maxmind.com/geoip/geoip2/geolite2/

download GeoLite2-City.mmdb

place it in (create the geo directory)

``` php
storage/geo/
```
or where ever you want just adjust the package config to reflect the new location,
it's used to geo locate visitors




### Usage



``` php


Visitor::log(); //log in db visitor ip, geo location, hit counter


Visitor::get();
Visitor::get( $ip ); //fetch ip record



Visitor::forget( $ip ); //delete ip from log


Visitor::has( $ip ); // checkk if visitor ip exist in log


Visitor::count() // return count of all site registred unique visitors


Visitor::all(); // all records


Visitor::clicks(); //total of all clicks


Visitor::range($date_start, $date_end); // visitors count in a date range;


```
###Credits
This product Uses GeoLite2 data created by MaxMind, whenever available.

Enjoy!



27 changes: 27 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "weboap/visitor",
"description": "log your visitors in db, page hits, and generate visit counter for Laravel 5",
"keywords": ["framework", "laravel","visitors", "counter", "log", "hits", "clicks"],
"license": "MIT",
"authors": [
{
"name": "WeboAp",
"email": "weboap@gmail.com"
}
],
"require": {
"php": ">=5.4.0",
"illuminate/support": "~5.0",
"jalle19/php-whitelist-check": "1.0.4",
"geoip2/geoip2": "2.1.1"
},
"autoload": {
"psr-4": {
"Weboap\\Visitor\\": "src"
}
},
"minimum-stability": "dev",
"require-dev": {
"phpspec/phpspec": "~2.1"
}
}
18 changes: 18 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
14 changes: 14 additions & 0 deletions src/Facades/VisitorFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php namespace Weboap\Visitor\Facades;

use Illuminate\Support\Facades\Facade;

class VisitorFacade extends Facade {

/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor() { return 'visitor'; }

}
53 changes: 53 additions & 0 deletions src/Ip.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php namespace Weboap\Visitor;



use Illuminate\Http\Request as Request;


class Ip {

protected $ip = null;

protected $request;


public function __construct(Request $request, array $validators = array())
{
$this->request = $request;
$this->validators = $validators;

}

public function get()
{
$ip = $this->request->getClientIp();

if($ip == '::1') {
$ip = '127.0.0.1';
}

return $ip;

}

public function isValid( $ip = null )
{
if( ! isset( $ip ) )
{
return false;
}

foreach ($this->validators as $validator)
{
if( ! $validator->validate( $ip ) ) return false;
}

return true;
}





}
45 changes: 45 additions & 0 deletions src/Services/Cache/CacheClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php namespace Weboap\Visitor\Services\Cache;



use Illuminate\Cache\CacheManager as Cache;


class CacheClass implements CacheInterface {

protected $cache;

public function __construct(Cache $cache)
{
$this->cache = $cache;

}




public function destroy( $key )
{
$this->cache->forget( $key );
}


public function rememberForever( $key, $data )
{

return $this->cache->rememberForever( $key, function() use ( $data )
{
return $data;
});
}










}
11 changes: 11 additions & 0 deletions src/Services/Cache/CacheInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php namespace Weboap\Visitor\Services\Cache;



interface CacheInterface {

public function destroy( $key );



}
9 changes: 9 additions & 0 deletions src/Services/Geo/GeoInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php namespace Weboap\Visitor\Services\Geo;



interface GeoInterface {

public function locate();

}
66 changes: 66 additions & 0 deletions src/Services/Geo/MaxMind.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php namespace Weboap\Visitor\Services\Geo;

use GeoIp2\Database\Reader;
use GeoIp2\Exception\AddressNotFoundException;
use Illuminate\Config\Repository as Config;
use Illuminate\Http\Request as Request;
use Weboap\Visitor\Ip;


class MaxMind implements GeoInterface{


protected $reader;

protected $config;

protected $ip;

public function __construct( Config $config, Ip $ip )
{
$this->config = $config;
$this->ip = $ip;
}



public function locate()
{
//
$ip = $this->ip->get();
$db = $this->config->get('visitor.maxmind_db_path');

if( !is_string($db) || ! file_exists( $db )|| ! $this->ip->isValid( $ip ) ) return [];


$this->reader = new Reader( $db );

try{

$record = $this->reader->city( $ip );

return [
'country_code' => $record->country->isoCode,
'country_name' => $record->country->name,
'state_code' => $record->mostSpecificSubdivision->isoCode,
'state' => $record->mostSpecificSubdivision->name,
'city' => $record->city->name,
'postale_code' => $record->postal->code

];

}
catch (AddressNotFoundException $e) {

return [];
};

}






}

Loading

0 comments on commit e33cdbf

Please sign in to comment.