Skip to content

Commit 35e178d

Browse files
committed
refactor: deprecate EVENT_PRIORITY_* and add class constants
1 parent c93b967 commit 35e178d

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

app/Config/Constants.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,18 @@
7777
defined('EXIT_DATABASE') || define('EXIT_DATABASE', 8); // database error
7878
defined('EXIT__AUTO_MIN') || define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code
7979
defined('EXIT__AUTO_MAX') || define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code
80+
81+
/**
82+
* @deprecated Use \CodeIgniter\Events\Events::PRIORITY_LOW instead.
83+
*/
84+
define('EVENT_PRIORITY_LOW', 200);
85+
86+
/**
87+
* @deprecated Use \CodeIgniter\Events\Events::PRIORITY_NORMAL instead.
88+
*/
89+
define('EVENT_PRIORITY_NORMAL', 100);
90+
91+
/**
92+
* @deprecated Use \CodeIgniter\Events\Events::PRIORITY_HIGH instead.
93+
*/
94+
define('EVENT_PRIORITY_HIGH', 10);

system/Events/Events.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
use Config\Modules;
1515
use Config\Services;
1616

17-
define('EVENT_PRIORITY_LOW', 200);
18-
define('EVENT_PRIORITY_NORMAL', 100);
19-
define('EVENT_PRIORITY_HIGH', 10);
20-
2117
/**
2218
* Events
2319
*/
2420
class Events
2521
{
22+
public const PRIORITY_LOW = 200;
23+
public const PRIORITY_NORMAL = 100;
24+
public const PRIORITY_HIGH = 10;
25+
2626
/**
2727
* The list of listeners.
2828
*

tests/system/Events/EventsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ public function testPriorityWithMultiple()
157157

158158
Events::on('foo', static function () use (&$result) {
159159
$result[] = 'a';
160-
}, EVENT_PRIORITY_NORMAL);
160+
}, Events::PRIORITY_NORMAL);
161161

162162
Events::on('foo', static function () use (&$result) {
163163
$result[] = 'b';
164-
}, EVENT_PRIORITY_LOW);
164+
}, Events::PRIORITY_LOW);
165165

166166
Events::on('foo', static function () use (&$result) {
167167
$result[] = 'c';
168-
}, EVENT_PRIORITY_HIGH);
168+
}, Events::PRIORITY_HIGH);
169169

170170
Events::on('foo', static function () use (&$result) {
171171
$result[] = 'd';

0 commit comments

Comments
 (0)