Skip to content

Commit e9c3272

Browse files
committed
- Updated EventManager now MUST implement Phpfastcache\Event\EventInterface
- Upgraded API version from 2.0.2 to 2.0.3
1 parent c62002d commit e9c3272

File tree

9 files changed

+69
-22
lines changed

9 files changed

+69
-22
lines changed

CHANGELOG_API.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.3
2+
- Updated ExtendedCacheItemPoolInterface::setEventManager() first argument that now MUSt implement `\Phpfastcache\Event\EventInterface`
3+
- Updated ExtendedCacheItemInterface::setEventManager() first argument that now MUSt implement `\Phpfastcache\Event\EventInterface`
4+
15
## 2.0.2
26
- Added ExtendedCacheItemPoolInterface::isUsableInAutoContext() to check if the driver is allowed to be used in 'Auto' context.
37

lib/Phpfastcache/Api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
class Api
2626
{
27-
protected static $version = '2.0.2';
27+
protected static $version = '2.0.3';
2828

2929
/**
3030
* Api constructor.

lib/Phpfastcache/Core/Item/ExtendedCacheItemInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
namespace Phpfastcache\Core\Item;
1717

1818
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
19-
use Phpfastcache\EventManager;
19+
use Phpfastcache\Event\EventInterface;
2020
use Phpfastcache\Exceptions\{
2121
PhpfastcacheInvalidArgumentException, PhpfastcacheLogicException
2222
};
@@ -214,8 +214,8 @@ public function getDataAsJsonString($option = 0, $depth = 512): string;
214214
/**
215215
* Set the EventManager instance
216216
*
217-
* @param EventManager $em
217+
* @param EventInterface $em
218218
* @return self
219219
*/
220-
public function setEventManager(EventManager $em): self;
220+
public function setEventManager(EventInterface $em): self;
221221
}

lib/Phpfastcache/Core/Item/ItemExtendedTrait.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
namespace Phpfastcache\Core\Item;
1717

1818
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
19-
use Phpfastcache\EventManager;
19+
use Phpfastcache\Event\EventInterface;
2020
use Phpfastcache\Exceptions\{
2121
PhpfastcacheInvalidArgumentException, PhpfastcacheInvalidArgumentTypeException, PhpfastcacheLogicException
2222
};
@@ -42,7 +42,7 @@ trait ItemExtendedTrait
4242
*******************/
4343

4444
/**
45-
* @var EventManager
45+
* @var EventInterface
4646
*/
4747
protected $eventManager;
4848

@@ -441,10 +441,10 @@ public function jsonSerialize()
441441
/**
442442
* Set the EventManager instance
443443
*
444-
* @param EventManager $em
444+
* @param EventInterface $em
445445
* @return ExtendedCacheItemInterface
446446
*/
447-
public function setEventManager(EventManager $em): ExtendedCacheItemInterface
447+
public function setEventManager(EventInterface $em): ExtendedCacheItemInterface
448448
{
449449
$this->eventManager = $em;
450450

lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolInterface.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919
use Phpfastcache\Config\ConfigurationOption;
2020
use Phpfastcache\Core\Item\ExtendedCacheItemInterface;
2121
use Phpfastcache\Entities\DriverStatistic;
22-
use Phpfastcache\EventManager;
22+
use Phpfastcache\Event\EventInterface;
2323
use Phpfastcache\Exceptions\{
2424
PhpfastcacheInvalidArgumentException, PhpfastcacheLogicException
2525
};
26-
use Phpfastcache\Util\ArrayObject;
2726
use Psr\Cache\{CacheItemInterface, CacheItemPoolInterface};
2827

2928

@@ -516,10 +515,10 @@ public function isAttached(CacheItemInterface $item);
516515
/**
517516
* Set the EventManager instance
518517
*
519-
* @param EventManager $em
518+
* @param EventInterface $em
520519
* @return self
521520
*/
522-
public function setEventManager(EventManager $em): self;
521+
public function setEventManager(EventInterface $em): self;
523522

524523
/**
525524
* Save multiple items, possible uses:

lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
namespace Phpfastcache\Core\Pool;
1717

1818
use Phpfastcache\Core\Item\ExtendedCacheItemInterface;
19-
use Phpfastcache\EventManager;
19+
use Phpfastcache\Event\EventInterface;
2020
use Phpfastcache\Exceptions\{
2121
PhpfastcacheInvalidArgumentException, PhpfastcacheLogicException
2222
};
@@ -458,10 +458,10 @@ public function isAttached(CacheItemInterface $item)
458458
/**
459459
* Set the EventManager instance
460460
*
461-
* @param EventManager $em
461+
* @param EventInterface $em
462462
* @return ExtendedCacheItemPoolInterface
463463
*/
464-
public function setEventManager(EventManager $em): ExtendedCacheItemPoolInterface
464+
public function setEventManager(EventInterface $em): ExtendedCacheItemPoolInterface
465465
{
466466
$this->eventManager = $em;
467467

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Geolim4
5+
* Date: 29/04/2018
6+
* Time: 23:28
7+
*/
8+
9+
namespace Phpfastcache\Event;
10+
11+
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
12+
13+
interface EventInterface
14+
{
15+
/**
16+
* @return self
17+
*/
18+
public static function getInstance(): self;
19+
20+
/**
21+
* @param string $eventName
22+
* @param array ...$args
23+
*/
24+
public function dispatch(string $eventName, ...$args);
25+
26+
/**
27+
* @param string $name
28+
* @param array $arguments
29+
* @throws PhpfastcacheInvalidArgumentException
30+
* @throws \BadMethodCallException
31+
*/
32+
public function __call(string $name, array $arguments);
33+
34+
/**
35+
* @param string $eventName
36+
* @param string $callbackName
37+
* @return bool
38+
*/
39+
public function unbindEventCallback(string $eventName, string $callbackName): bool;
40+
}

lib/Phpfastcache/EventManager.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
namespace Phpfastcache;
1717

18+
use Phpfastcache\Event\EventInterface;
1819
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
1920

2021
/**
@@ -38,7 +39,7 @@
3839
*
3940
*
4041
*/
41-
class EventManager
42+
class EventManager implements EventInterface
4243
{
4344
/**
4445
* @var $this
@@ -51,18 +52,19 @@ class EventManager
5152
protected $events = [];
5253

5354
/**
54-
* @return \Phpfastcache\EventManager
55+
* @return EventInterface
5556
*/
56-
public static function getInstance(): self
57+
public static function getInstance(): EventInterface
5758
{
5859
return (self::$instance ?: self::$instance = new self);
5960
}
6061

6162
/**
6263
* EventManager constructor.
6364
*/
64-
protected function __construct()
65+
final protected function __construct()
6566
{
67+
// The constructor should not be instantiated externally
6668
}
6769

6870
/**

lib/Phpfastcache/Helper/ActOnAll.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
namespace Phpfastcache\Helper;
1717

18-
use Phpfastcache\{CacheManager, EventManager};
18+
use Phpfastcache\{
19+
CacheManager, Event\EventInterface, EventManager
20+
};
1921
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
2022
use Phpfastcache\Entities\DriverStatistic;
2123
use Psr\Cache\CacheItemInterface;
@@ -466,10 +468,10 @@ public function isAttached(CacheItemInterface $item): array
466468
}
467469

468470
/**
469-
* @param \Phpfastcache\EventManager $em
471+
* @param EventInterface $em
470472
* @return array
471473
*/
472-
public function setEventManager(EventManager $em): array
474+
public function setEventManager(EventInterface $em): array
473475
{
474476
$callback = $this->getGenericCallback();
475477
return $callback(__FUNCTION__, func_get_args());

0 commit comments

Comments
 (0)