Skip to content

Commit 2511452

Browse files
committed
Use Phalcon events contracts
1 parent f52d960 commit 2511452

15 files changed

Lines changed: 61 additions & 52 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ release notes.
134134
- Normalized mailer driver and SMTP encryption config case-insensitively,
135135
validated mailer option shapes, and failed fast on unsupported values before
136136
send-time network behavior.
137+
- Replaced internal references to deprecated Phalcon events interfaces with
138+
their `Phalcon\Contracts\Events` equivalents.
137139

138140
## 3.0.3 - 2026-06-10
139141

src/Bootstrap.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
namespace PhalconKit;
1515

1616
use Phalcon\Application\AbstractApplication;
17+
use Phalcon\Contracts\Events\Manager as EventsManagerContract;
1718
use Phalcon\Di\Di as PhalconDi;
18-
use Phalcon\Events;
19+
use Phalcon\Events\Manager as EventsManager;
1920
use Phalcon\Http\ResponseInterface;
2021
use PhalconKit\Config\ConfigInterface;
2122
use PhalconKit\Cli\Console;
@@ -157,7 +158,7 @@ class Bootstrap
157158
public function __construct(?string $mode = null)
158159
{
159160
$this->setMode($mode);
160-
$this->setEventsManager(new Events\Manager());
161+
$this->setEventsManager(new EventsManager());
161162
$this->setDI();
162163
$this->initialize();
163164
$this->registerConfig();
@@ -400,7 +401,7 @@ protected function attachConfiguredEventListeners(): void
400401

401402
ConfiguredEventListeners::attach(
402403
$this->di,
403-
$this->di->getTyped('eventsManager', Events\ManagerInterface::class),
404+
$this->di->getTyped('eventsManager', EventsManagerContract::class),
404405
$listeners
405406
);
406407
$this->configuredEventListenersAttached = true;

src/Db/Events/Logger.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
namespace PhalconKit\Db\Events;
1515

16+
use Phalcon\Contracts\Events\Event as EventContract;
1617
use Phalcon\Db\Adapter\AbstractAdapter;
17-
use Phalcon\Events\EventInterface;
1818
use Phalcon\Logger\Exception as LoggerException;
1919
use PhalconKit\Di\Injectable;
2020

@@ -28,12 +28,12 @@ class Logger extends Injectable
2828
/**
2929
* Executes before a database query is executed.
3030
*
31-
* @param EventInterface $event The event object.
31+
* @param EventContract $event The event object.
3232
* @param AbstractAdapter $connection The database connection object.
3333
* @return void
3434
* @throws LoggerException If Phalcon cannot write the query log entry.
3535
*/
36-
public function beforeQuery(EventInterface $event, AbstractAdapter $connection): void
36+
public function beforeQuery(EventContract $event, AbstractAdapter $connection): void
3737
{
3838
if ($this->config->path('logger.enable') || $this->config->path('app.logger')) {
3939
if ($this->config->path('loggers.database.enable')) {

src/Db/Events/Profiler.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
namespace PhalconKit\Db\Events;
1515

16+
use Phalcon\Contracts\Events\Event as EventContract;
1617
use Phalcon\Db\Adapter\AbstractAdapter;
17-
use Phalcon\Events\EventInterface;
1818
use PhalconKit\Di\Injectable;
1919

2020
/**
@@ -47,11 +47,11 @@ public function isEnabled(): bool
4747
* Stopped events are ignored so listeners earlier in the chain can cancel
4848
* profiling together with the query.
4949
*
50-
* @param EventInterface $event Database `beforeQuery` event.
50+
* @param EventContract $event Database `beforeQuery` event.
5151
* @param AbstractAdapter $connection Connection that is about to execute
5252
* the statement.
5353
*/
54-
public function beforeQuery(EventInterface $event, AbstractAdapter $connection): void
54+
public function beforeQuery(EventContract $event, AbstractAdapter $connection): void
5555
{
5656
if ($this->isEnabled()) {
5757
if (!$event->isStopped()) {
@@ -69,10 +69,10 @@ public function beforeQuery(EventInterface $event, AbstractAdapter $connection):
6969
*
7070
* @scrutinizer ignore-unused
7171
*
72-
* @param EventInterface $event Database `afterQuery` event.
72+
* @param EventContract $event Database `afterQuery` event.
7373
* @param AbstractAdapter $connection Connection that executed the statement.
7474
*/
75-
public function afterQuery(EventInterface $event, AbstractAdapter $connection): void
75+
public function afterQuery(EventContract $event, AbstractAdapter $connection): void
7676
{
7777
if ($this->isEnabled()) {
7878
$this->profiler->stopProfile();

src/Di/AbstractInjectable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @property \Phalcon\Flash\Direct $flash
3232
* @property \Phalcon\Flash\Session $flashSession
3333
* @property \Phalcon\Session\ManagerInterface $session
34-
* @property \Phalcon\Events\Manager|\Phalcon\Events\ManagerInterface $eventsManager
34+
* @property \Phalcon\Events\Manager|\Phalcon\Contracts\Events\Manager $eventsManager
3535
* @property \Phalcon\Db\Adapter\AdapterInterface $db
3636
* @property \PhalconKit\Encryption\Security|\Phalcon\Encryption\Security $security
3737
* @property \Phalcon\Encryption\Crypt|\Phalcon\Encryption\Crypt\CryptInterface $crypt

src/Di/InjectableProperties.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
* @property \Phalcon\Db\Adapter\AbstractAdapter $db
5151
* @property \Phalcon\Db\Adapter\AbstractAdapter $dbd
5252
* @property \Phalcon\Db\Adapter\AbstractAdapter $dbr
53-
* @property \Phalcon\Events\ManagerInterface $eventsManager
53+
* @property \Phalcon\Contracts\Events\Manager $eventsManager
5454
* @property \Phalcon\Flash\FlashInterface $flash
5555
* @property \Phalcon\Logger\LoggerInterface $logger
5656
* @property \Phalcon\Incubator\Mailer\Manager $mailer

src/Events/ConfiguredEventListeners.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
namespace PhalconKit\Events;
1515

1616
use Phalcon\Di\InjectionAwareInterface;
17+
use Phalcon\Contracts\Events\Manager as EventsManagerContract;
1718
use Phalcon\Events\Manager;
18-
use Phalcon\Events\ManagerInterface;
1919
use PhalconKit\Di\DiInterface;
2020
use PhalconKit\Exception\ConfigurationException;
2121

@@ -63,14 +63,14 @@ private function __construct()
6363
* @param DiInterface $di Container used to resolve listener services and
6464
* inject DI into listener objects that implement Phalcon's
6565
* `InjectionAwareInterface`.
66-
* @param ManagerInterface $eventsManager Events manager that receives the
66+
* @param EventsManagerContract $eventsManager Events manager that receives the
6767
* listener attachments.
6868
* @param array<array-key, mixed> $listeners Event-type map from config.
6969
*
7070
* @throws ConfigurationException When an event type, listener definition,
7171
* listener class, listener service, or priority is invalid.
7272
*/
73-
public static function attach(DiInterface $di, ManagerInterface $eventsManager, array $listeners): void
73+
public static function attach(DiInterface $di, EventsManagerContract $eventsManager, array $listeners): void
7474
{
7575
if ($listeners === []) {
7676
return;

src/Events/EventsAwareTrait.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace PhalconKit\Events;
1515

1616
use Phalcon\Di\Di;
17-
use Phalcon\Events\ManagerInterface;
17+
use Phalcon\Contracts\Events\Manager as EventsManagerContract;
1818
use PhalconKit\Exception\InvalidArgumentException;
1919
use PhalconKit\Support\Helper;
2020
use PhalconKit\Support\Slug;
@@ -34,20 +34,20 @@ trait EventsAwareTrait
3434
/**
3535
* The event manager responsible for handling and triggering events.
3636
*/
37-
protected ?ManagerInterface $eventsManager;
37+
protected ?EventsManagerContract $eventsManager;
3838

3939
/**
4040
* Set the events manager
4141
*/
42-
public function setEventsManager(ManagerInterface $manager): void
42+
public function setEventsManager(EventsManagerContract $manager): void
4343
{
4444
$this->eventsManager = $manager;
4545
}
4646

4747
/**
4848
* Get the events manager.
4949
*/
50-
public function getEventsManager(): ?ManagerInterface
50+
public function getEventsManager(): ?EventsManagerContract
5151
{
5252
$this->eventsManager ??= Di::getDefault()->get('eventsManager');
5353
return $this->eventsManager;
@@ -101,8 +101,10 @@ public function fire(string $task, mixed $data = null, bool $cancelable = false)
101101
$eventType = $this->getEventsPrefix() . ':' . $task;
102102
$eventsManager = $this->getEventsManager();
103103

104-
if (!$eventsManager instanceof ManagerInterface) {
105-
throw new InvalidArgumentException("Events manager must be an instance of '" . ManagerInterface::class . "'.");
104+
if (!$eventsManager instanceof EventsManagerContract) {
105+
throw new InvalidArgumentException(
106+
"Events manager must be an instance of '" . EventsManagerContract::class . "'."
107+
);
106108
}
107109

108110
return $eventsManager->fire($eventType, $this, $data, $cancelable);

src/Mvc/Controller/Traits/Behavior.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
namespace PhalconKit\Mvc\Controller\Traits;
1515

16+
use Phalcon\Contracts\Events\Manager as EventsManagerContract;
1617
use Phalcon\Di\Injectable;
1718
use Phalcon\Dispatcher\AbstractDispatcher;
1819
use Phalcon\Events\Manager;
19-
use Phalcon\Events\ManagerInterface;
2020
use Phalcon\Mvc\Dispatcher as MvcDispatcher;
2121
use PhalconKit\Acl\PermissionName;
2222
use PhalconKit\Mvc\Controller\Attributes\PermissionAttributeResolver;
@@ -118,10 +118,10 @@ public function attachBehaviors(array $behaviors = [], ?string $eventType = null
118118
}
119119
}
120120

121-
protected function getOrCreateEventsManager(): ManagerInterface
121+
protected function getOrCreateEventsManager(): EventsManagerContract
122122
{
123123
$eventsManager = $this->getEventsManager();
124-
if ($eventsManager instanceof ManagerInterface) {
124+
if ($eventsManager instanceof EventsManagerContract) {
125125
return $eventsManager;
126126
}
127127

@@ -130,7 +130,7 @@ protected function getOrCreateEventsManager(): ManagerInterface
130130
$eventsManager = $di->getShared('eventsManager');
131131
}
132132

133-
if (!$eventsManager instanceof ManagerInterface) {
133+
if (!$eventsManager instanceof Manager) {
134134
$eventsManager = new Manager();
135135
}
136136

src/Mvc/Model/Traits/Abstracts/AbstractEventsManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414
namespace PhalconKit\Mvc\Model\Traits\Abstracts;
1515

16-
use Phalcon\Events\ManagerInterface;
16+
use Phalcon\Contracts\Events\Manager as EventsManagerContract;
1717

1818
trait AbstractEventsManager
1919
{
2020
use AbstractInjectable;
2121

22-
abstract public function getEventsManager(): ?ManagerInterface;
22+
abstract public function getEventsManager(): ?EventsManagerContract;
2323

2424
abstract public function fireEventCancel(string $eventName): bool;
2525

0 commit comments

Comments
 (0)