Skip to content

Commit 4c5ca43

Browse files
author
Eugene Terentev
committed
PSR-16 support
1 parent b1fc433 commit 4c5ca43

6 files changed

+24
-21
lines changed

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"escapestudios/symfony2-coding-standard": "^3.0",
2727
"slevomat/coding-standard": "^4.0",
2828
"friendsofphp/php-cs-fixer": "^2.3",
29-
"monolog/monolog": "^1.23"
29+
"monolog/monolog": "^1.23",
30+
"psr/simple-cache": "^1.0"
3031
},
3132
"autoload": {
3233
"psr-4": {

src/Cache/Cache.php

+11-9
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,37 @@
22

33
namespace Rentberry\MapsUtils\Cache;
44

5+
use Psr\SimpleCache\CacheInterface;
6+
57
/**
68
* Cache service
79
*/
810
class Cache
911
{
1012
/**
11-
* @var \Memcached
13+
* @var CacheInterface
1214
*/
1315
protected $cache;
1416

1517
/**
16-
* @param \Memcached $cache
18+
* @param CacheInterface $cache
1719
*/
18-
public function __construct(\Memcached $cache)
20+
public function __construct(CacheInterface $cache)
1921
{
2022
$this->cache = $cache;
2123
}
2224

2325
/**
24-
* @param CacheInterface $object
26+
* @param CacheableInterface $object
2527
*
2628
* @return false|mixed
2729
*/
28-
public function getData(CacheInterface $object)
30+
public function getData(CacheableInterface $object)
2931
{
3032
$cacheKey = $object->getCacheKey();
31-
$data = $this->cache->get($cacheKey);
33+
$data = $this->cache->get($cacheKey, null);
3234

33-
if ($data !== false) {
35+
if ($data !== null) {
3436
return $data;
3537
}
3638

@@ -46,11 +48,11 @@ public function getData(CacheInterface $object)
4648
/**
4749
* Force update data in cache
4850
*
49-
* @param CacheInterface $object
51+
* @param CacheableInterface $object
5052
*
5153
* @return false|mixed
5254
*/
53-
public function updateData(CacheInterface $object)
55+
public function updateData(CacheableInterface $object)
5456
{
5557
$cacheKey = $object->getCacheKey();
5658
$data = $object->getData();

src/Cache/CacheInterface.php src/Cache/CacheableInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace Rentberry\MapsUtils\Cache;
44

55
/**
6-
* Interface Cache
6+
* Interface Cacheable
77
*/
8-
interface CacheInterface
8+
interface CacheableInterface
99
{
1010
/**
1111
* @return mixed

src/Cache/CacheObject.php src/Cache/CacheableObject.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Cache object
77
*/
8-
class CacheObject implements CacheInterface
8+
class CacheableObject implements CacheableInterface
99
{
1010
/**
1111
* @var string
@@ -36,9 +36,9 @@ public function getData()
3636
/**
3737
* @param string $cacheKey
3838
*
39-
* @return CacheObject
39+
* @return CacheableObject
4040
*/
41-
public function setCacheKey(string $cacheKey): CacheObject
41+
public function setCacheKey(string $cacheKey): CacheableObject
4242
{
4343
$this->cacheKey = $cacheKey;
4444

@@ -48,9 +48,9 @@ public function setCacheKey(string $cacheKey): CacheObject
4848
/**
4949
* @param mixed $data
5050
*
51-
* @return CacheObject
51+
* @return CacheableObject
5252
*/
53-
public function setData($data): CacheObject
53+
public function setData($data): CacheableObject
5454
{
5555
$this->data = $data;
5656

src/MapsPlace.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
use GuzzleHttp\Client;
66
use Psr\Log\LoggerInterface;
77
use Rentberry\MapsUtils\Cache\Cache;
8-
use Rentberry\MapsUtils\Cache\CacheInterface;
8+
use Rentberry\MapsUtils\Cache\CacheableInterface;
99
use Rentberry\MapsUtils\Objects\Place;
1010

1111
/**
1212
* MapsPlace
1313
*/
14-
class MapsPlace implements CacheInterface
14+
class MapsPlace implements CacheableInterface
1515
{
1616
public const QUERY_TYPE_ADDRESS = 'address';
1717
public const QUERY_TYPE_PLACE_ID = 'place_id';

src/MapsTimezone.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
use GuzzleHttp\Client;
66
use Psr\Log\LoggerInterface;
77
use Rentberry\MapsUtils\Cache\Cache;
8-
use Rentberry\MapsUtils\Cache\CacheInterface;
8+
use Rentberry\MapsUtils\Cache\CacheableInterface;
99

1010
/**
1111
* MapsTimezone
1212
*/
13-
class MapsTimezone implements CacheInterface
13+
class MapsTimezone implements CacheableInterface
1414
{
1515
private const LOCATION_ROUND_LEVEL = 3;
1616
/**

0 commit comments

Comments
 (0)