Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#16705] - refactor: remove has() check in doGet(). #16709

Open
wants to merge 3 commits into
base: 5.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Changed `Phalcon\Filter\Validation\Validator\Email` to allow UTF8 in local part. [#16637](https://github.com/phalcon/cphalcon/issues/16637)
- Changed `Phalcon\Cache\Cache::getMultiple()` to use `mget()` when the `Phalcon\Cache\Adapter\Redis` is used. [#16689](https://github.com/phalcon/cphalcon/issues/16689)
- Changed `Phalcon\Storage\Adapter\AbstractAdapter` and dropped `has()` check before receiving the value. [#16705](https://github.com/phalcon/cphalcon/issues/16705)

### Added
- Added `dispatch:beforeCallAction` and `dispatch:afterCallAction` to last-minute modifications to handler and method (mostly for debugging).
Expand Down
5 changes: 2 additions & 3 deletions phalcon/Storage/Adapter/AbstractAdapter.zep
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,13 @@ abstract class AbstractAdapter implements AdapterInterface, EventsAwareInterface

this->fire(this->eventType . ":beforeGet", key);

if (true !== this->has(key)) {
let content = this->doGet(key);
if (content === false) {
this->fire(this->eventType . ":afterGet", key);

return defaultValue;
}

let content = this->doGet(key);

let result = this->getUnserializedData(content, defaultValue);

this->fire(this->eventType . ":afterGet", key);
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/Cache/Adapter/Memory/EventsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public function cacheCacheEventTriggers(IntegrationTester $I, Example $example):
$manager = new Manager();
$adapter->setEventsManager(new Manager());

// Avoid unset warning
$adapter->set('test', 'test');

$manager->attach(
'cache:' . $example->offsetGet(0),
static function (Event $event) use (&$counter, $example): void {
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/Cache/Cache/GetEventsManagerCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ static function () use (&$counter) {

$adapter->setEventsManager($manager);

// Avoid unset warning.
if ($example->offsetGet(1) !== 'set' && $example->offsetGet(1) !== 'setMultiple') {
$adapter->set('test', 'test');
$adapter->set('test2', 'test2');
}

$I->assertInstanceOf($manager::class, $adapter->getEventsManager());

call_user_func_array([$adapter, $example->offsetGet(1)], $example->offsetGet(2));
Expand Down
24 changes: 24 additions & 0 deletions tests/integration/Storage/Adapter/EventsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public function storageAdapterEventsBeforeGet(IntegrationTester $I, Example $exa
)
);

$adapter->set('test', 'test');

$manager->attach(
'storage:beforeGet',
static function (Event $event) use (&$counter, $example): void {
Expand Down Expand Up @@ -109,6 +111,8 @@ public function storageAdapterEventsAfterGet(IntegrationTester $I, Example $exam
)
);

$adapter->set('test', 'test');

$manager->attach(
'storage:afterGet',
static function (Event $event) use (&$counter, $example): void {
Expand Down Expand Up @@ -157,6 +161,8 @@ public function storageAdapterEventsBeforeHas(IntegrationTester $I, Example $exa
)
);

$adapter->set('test', 'test');

$manager->attach(
'storage:beforeHas',
static function (Event $event) use (&$counter, $example): void {
Expand Down Expand Up @@ -205,6 +211,8 @@ public function storageAdapterEventsAfterHas(IntegrationTester $I, Example $exam
)
);

$adapter->set('test', 'test');

$manager->attach(
'storage:afterHas',
static function (Event $event) use (&$counter, $example): void {
Expand Down Expand Up @@ -253,6 +261,8 @@ public function storageAdapterEventsBeforeDelete(IntegrationTester $I, Example $
)
);

$adapter->set('test', 'test');

$manager->attach(
'storage:beforeDelete',
static function (Event $event) use (&$counter, $example): void {
Expand Down Expand Up @@ -301,6 +311,8 @@ public function storageAdapterEventsAfterDelete(IntegrationTester $I, Example $e
)
);

$adapter->set('test', 'test');

$manager->attach(
'storage:afterDelete',
static function (Event $event) use (&$counter, $example): void {
Expand Down Expand Up @@ -349,6 +361,8 @@ public function storageAdapterEventsBeforeIncrement(IntegrationTester $I, Exampl
)
);

$adapter->set('test', 'test');

$manager->attach(
'storage:beforeIncrement',
static function (Event $event) use (&$counter, $example): void {
Expand Down Expand Up @@ -397,6 +411,8 @@ public function storageAdapterEventsAfterIncrement(IntegrationTester $I, Example
)
);

$adapter->set('test', 'test');

$manager->attach(
'storage:afterIncrement',
static function (Event $event) use (&$counter, $example): void {
Expand Down Expand Up @@ -445,6 +461,8 @@ public function storageAdapterEventsBeforeDecrement(IntegrationTester $I, Exampl
)
);

$adapter->set('test', 'test');

$manager->attach(
'storage:beforeDecrement',
static function (Event $event) use (&$counter, $example): void {
Expand Down Expand Up @@ -493,6 +511,8 @@ public function storageAdapterEventsAfterDecrement(IntegrationTester $I, Example
)
);

$adapter->set('test', 'test');

$manager->attach(
'storage:afterDecrement',
static function (Event $event) use (&$counter, $example): void {
Expand Down Expand Up @@ -541,6 +561,8 @@ public function storageAdapterEventsBeforeSet(IntegrationTester $I, Example $exa
)
);

$adapter->set('test', 'test');

$manager->attach(
'storage:beforeSet',
static function (Event $event) use (&$counter, $example): void {
Expand Down Expand Up @@ -589,6 +611,8 @@ public function storageAdapterEventsAfterSet(IntegrationTester $I, Example $exam
)
);

$adapter->set('test', 'test');

$manager->attach(
'storage:afterSet',
static function (Event $event) use (&$counter, $example): void {
Expand Down
Loading