Skip to content

Commit

Permalink
イベントのオンオフを行う際にグローバルイベントマネージャーを指定した場合に例外を投げるように変更
Browse files Browse the repository at this point in the history
処理がループしてしまうため
  • Loading branch information
ryuring committed Nov 25, 2024
1 parent 2cfe521 commit 93c1a9d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions plugins/baser-core/src/Utility/BcUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace BaserCore\Utility;

use BaserCore\Error\BcException;
use BaserCore\Middleware\BcAdminMiddleware;
use BaserCore\Middleware\BcFrontMiddleware;
use BaserCore\Middleware\BcRequestFilterMiddleware;
Expand Down Expand Up @@ -1641,6 +1642,13 @@ public static function fgetcsvReg(&$handle, $length = null, $d = ',', $e = '"')
*/
public static function offEvent(EventManagerInterface $eventManager, string $eventKey)
{
$reflection = new ReflectionClass($eventManager);
$property = $reflection->getProperty('_isGlobal');
$property->setAccessible(true);
if($property->getValue($eventManager)) {
throw new BcException(__d('baser_core', 'グローバルイベントマネージャーからはイベントをオフにすることはできません。'));
}

$globalEventManager = $eventManager->instance();
$eventListeners = [
'local' => $eventManager->prioritisedListeners($eventKey),
Expand Down Expand Up @@ -1674,6 +1682,13 @@ public static function offEvent(EventManagerInterface $eventManager, string $eve
*/
public static function onEvent(EventManagerInterface $eventManager, string $eventKey, array $eventListeners)
{
$reflection = new ReflectionClass($eventManager);
$property = $reflection->getProperty('_isGlobal');
$property->setAccessible(true);
if($property->getValue($eventManager)) {
throw new BcException(__d('baser_core', 'グローバルイベントマネージャーからはイベントをオンにすることはできません。'));
}

$globalEventManager = $eventManager->instance();
if (!empty($eventListeners['local'])) {
foreach($eventListeners['local'] as $priority => $listeners) {
Expand Down

0 comments on commit 93c1a9d

Please sign in to comment.