From 4c5ca43b773fecfac6d0918a6945158ff150184f Mon Sep 17 00:00:00 2001 From: Eugene Terentev Date: Wed, 8 Aug 2018 18:13:37 +0300 Subject: [PATCH] PSR-16 support --- composer.json | 3 ++- src/Cache/Cache.php | 20 ++++++++++--------- ...heInterface.php => CacheableInterface.php} | 4 ++-- .../{CacheObject.php => CacheableObject.php} | 10 +++++----- src/MapsPlace.php | 4 ++-- src/MapsTimezone.php | 4 ++-- 6 files changed, 24 insertions(+), 21 deletions(-) rename src/Cache/{CacheInterface.php => CacheableInterface.php} (81%) rename src/Cache/{CacheObject.php => CacheableObject.php} (74%) diff --git a/composer.json b/composer.json index ea8b33b..c7e2c2a 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "escapestudios/symfony2-coding-standard": "^3.0", "slevomat/coding-standard": "^4.0", "friendsofphp/php-cs-fixer": "^2.3", - "monolog/monolog": "^1.23" + "monolog/monolog": "^1.23", + "psr/simple-cache": "^1.0" }, "autoload": { "psr-4": { diff --git a/src/Cache/Cache.php b/src/Cache/Cache.php index 362008f..541fe0c 100644 --- a/src/Cache/Cache.php +++ b/src/Cache/Cache.php @@ -2,35 +2,37 @@ namespace Rentberry\MapsUtils\Cache; +use Psr\SimpleCache\CacheInterface; + /** * Cache service */ class Cache { /** - * @var \Memcached + * @var CacheInterface */ protected $cache; /** - * @param \Memcached $cache + * @param CacheInterface $cache */ - public function __construct(\Memcached $cache) + public function __construct(CacheInterface $cache) { $this->cache = $cache; } /** - * @param CacheInterface $object + * @param CacheableInterface $object * * @return false|mixed */ - public function getData(CacheInterface $object) + public function getData(CacheableInterface $object) { $cacheKey = $object->getCacheKey(); - $data = $this->cache->get($cacheKey); + $data = $this->cache->get($cacheKey, null); - if ($data !== false) { + if ($data !== null) { return $data; } @@ -46,11 +48,11 @@ public function getData(CacheInterface $object) /** * Force update data in cache * - * @param CacheInterface $object + * @param CacheableInterface $object * * @return false|mixed */ - public function updateData(CacheInterface $object) + public function updateData(CacheableInterface $object) { $cacheKey = $object->getCacheKey(); $data = $object->getData(); diff --git a/src/Cache/CacheInterface.php b/src/Cache/CacheableInterface.php similarity index 81% rename from src/Cache/CacheInterface.php rename to src/Cache/CacheableInterface.php index 5f8f905..9e1a48a 100644 --- a/src/Cache/CacheInterface.php +++ b/src/Cache/CacheableInterface.php @@ -3,9 +3,9 @@ namespace Rentberry\MapsUtils\Cache; /** - * Interface Cache + * Interface Cacheable */ -interface CacheInterface +interface CacheableInterface { /** * @return mixed diff --git a/src/Cache/CacheObject.php b/src/Cache/CacheableObject.php similarity index 74% rename from src/Cache/CacheObject.php rename to src/Cache/CacheableObject.php index c944930..4b32f23 100644 --- a/src/Cache/CacheObject.php +++ b/src/Cache/CacheableObject.php @@ -5,7 +5,7 @@ /** * Cache object */ -class CacheObject implements CacheInterface +class CacheableObject implements CacheableInterface { /** * @var string @@ -36,9 +36,9 @@ public function getData() /** * @param string $cacheKey * - * @return CacheObject + * @return CacheableObject */ - public function setCacheKey(string $cacheKey): CacheObject + public function setCacheKey(string $cacheKey): CacheableObject { $this->cacheKey = $cacheKey; @@ -48,9 +48,9 @@ public function setCacheKey(string $cacheKey): CacheObject /** * @param mixed $data * - * @return CacheObject + * @return CacheableObject */ - public function setData($data): CacheObject + public function setData($data): CacheableObject { $this->data = $data; diff --git a/src/MapsPlace.php b/src/MapsPlace.php index 65b35fd..d4c28b0 100644 --- a/src/MapsPlace.php +++ b/src/MapsPlace.php @@ -5,13 +5,13 @@ use GuzzleHttp\Client; use Psr\Log\LoggerInterface; use Rentberry\MapsUtils\Cache\Cache; -use Rentberry\MapsUtils\Cache\CacheInterface; +use Rentberry\MapsUtils\Cache\CacheableInterface; use Rentberry\MapsUtils\Objects\Place; /** * MapsPlace */ -class MapsPlace implements CacheInterface +class MapsPlace implements CacheableInterface { public const QUERY_TYPE_ADDRESS = 'address'; public const QUERY_TYPE_PLACE_ID = 'place_id'; diff --git a/src/MapsTimezone.php b/src/MapsTimezone.php index 51c7149..76e1e33 100644 --- a/src/MapsTimezone.php +++ b/src/MapsTimezone.php @@ -5,12 +5,12 @@ use GuzzleHttp\Client; use Psr\Log\LoggerInterface; use Rentberry\MapsUtils\Cache\Cache; -use Rentberry\MapsUtils\Cache\CacheInterface; +use Rentberry\MapsUtils\Cache\CacheableInterface; /** * MapsTimezone */ -class MapsTimezone implements CacheInterface +class MapsTimezone implements CacheableInterface { private const LOCATION_ROUND_LEVEL = 3; /**