-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from hpatoio/master
Fixing issue #87
- Loading branch information
Showing
7 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the badge-poser package. | ||
* | ||
* (c) PUGX <http://pugx.github.io/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace PUGX\StatsBundle\Service; | ||
|
||
/** | ||
* Class NullReader | ||
* | ||
* @author Simone Fumagalli <[email protected]> | ||
*/ | ||
class NullReader implements ReaderInterface | ||
{ | ||
public static $totalAccess = false; | ||
|
||
/** | ||
* Return the total accesses. | ||
* | ||
* @return Integer | ||
*/ | ||
public function totalAccess() | ||
{ | ||
return static::$totalAccess; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the badge-poser package. | ||
* | ||
* (c) PUGX <http://pugx.github.io/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace PUGX\StatsBundle\Service; | ||
|
||
/** | ||
* Class ReaderInterface | ||
* | ||
* @author Simone Fumagalli <[email protected]> | ||
*/ | ||
Interface ReaderInterface | ||
{ | ||
/** | ||
* Read total accesses. | ||
* | ||
* @return integer | ||
*/ | ||
public function totalAccess(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the badge-poser package. | ||
* | ||
* (c) PUGX <http://pugx.github.io/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace PUGX\StatsBundle\Service; | ||
|
||
/** | ||
* Class RedisStats | ||
* | ||
* @author Simone Fumagalli <[email protected]> | ||
*/ | ||
class RedisReader implements ReaderInterface | ||
{ | ||
const KEY_PREFIX = 'STAT'; | ||
const KEY_TOTAL = 'TOTAL'; | ||
|
||
private $redis; | ||
private $keyTotal; | ||
private $keyPrefix; | ||
|
||
public function __construct($redis, $keyTotal = self::KEY_TOTAL, $keyPrefix = self::KEY_PREFIX) | ||
{ | ||
$this->redis = $redis; | ||
$this->keyPrefix = $keyPrefix; | ||
$this->keyTotal = $this->concatenateKeys($keyPrefix, $keyTotal); | ||
} | ||
|
||
/** | ||
* Generate the Key with the default prefix. | ||
* | ||
* @param string $prefix | ||
* @param string $keyName | ||
* | ||
* @return string | ||
*/ | ||
private function concatenateKeys($prefix, $keyName) | ||
{ | ||
return sprintf("%s.%s", $prefix, $keyName); | ||
} | ||
|
||
/** | ||
* Read total accesses. | ||
* | ||
* @return integer | ||
*/ | ||
public function totalAccess() | ||
{ | ||
return $this->redis->get($this->keyTotal); | ||
} | ||
|
||
} |