mirror of
https://github.com/antonkomarev/github-profile-views-counter.git
synced 2026-07-22 21:43:45 -04:00
Initial commit
This commit is contained in:
37
src/CounterFileRepository.php
Normal file
37
src/CounterFileRepository.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of GitHub Profile Views Counter.
|
||||
*
|
||||
* (c) Anton Komarev <anton@komarev.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Komarev\GitHubProfileViewsCounter;
|
||||
|
||||
final class CounterFileRepository
|
||||
{
|
||||
private string $counterPath;
|
||||
|
||||
public function __construct(
|
||||
string $storagePath,
|
||||
string $counterFileName
|
||||
)
|
||||
{
|
||||
$this->counterPath = $storagePath . '/' . $counterFileName;
|
||||
}
|
||||
|
||||
public function getCount(): int
|
||||
{
|
||||
return file_exists($this->counterPath) ? (int) file_get_contents($this->counterPath) : 0;
|
||||
}
|
||||
|
||||
public function incrementCount(): void
|
||||
{
|
||||
file_put_contents($this->counterPath, $this->getCount() + 1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user