Skip to content

Commit

Permalink
[#16606] - refactor: changed fire method to request key/keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
noone-silent committed Jun 8, 2024
1 parent 566c600 commit 09a6657
Show file tree
Hide file tree
Showing 15 changed files with 225 additions and 144 deletions.
33 changes: 17 additions & 16 deletions phalcon/Cache/AbstractCache.zep
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ abstract class AbstractCache implements CacheInterface, EventsAwareInterface
{
var result;

this->fire("cache:beforeDelete");
this->fire("cache:beforeDelete", key);

this->checkKey(key);

let result = this->adapter->delete(key);

this->fire("cache:afterDelete");
this->fire("cache:afterDelete", key);

return result;
}
Expand All @@ -155,7 +155,7 @@ abstract class AbstractCache implements CacheInterface, EventsAwareInterface

this->checkKeys(keys);

this->fire("cache:beforeDeleteMultiple");
this->fire("cache:beforeDeleteMultiple", keys);

let result = true;
for key in keys {
Expand All @@ -164,7 +164,7 @@ abstract class AbstractCache implements CacheInterface, EventsAwareInterface
}
}

this->fire("cache:afterDeleteMultiple");
this->fire("cache:afterDeleteMultiple", keys);

return result;
}
Expand All @@ -187,11 +187,11 @@ abstract class AbstractCache implements CacheInterface, EventsAwareInterface

this->checkKey(key);

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

let result = this->adapter->get(key, defaultValue);

this->fire("cache:afterGet");
this->fire("cache:afterGet", key);

return result;
}
Expand All @@ -205,14 +205,14 @@ abstract class AbstractCache implements CacheInterface, EventsAwareInterface

this->checkKeys(keys);

this->fire("cache:beforeGetMultiple");
this->fire("cache:beforeGetMultiple", keys);

let results = [];
for element in keys {
let results[element] = this->get(element, defaultValue);
}

this->fire("cache:afterGetMultiple");
this->fire("cache:afterGetMultiple", keys);

return results;
}
Expand All @@ -233,11 +233,11 @@ abstract class AbstractCache implements CacheInterface, EventsAwareInterface

this->checkKey(key);

this->fire("cache:beforeHas");
this->fire("cache:beforeHas", key);

let result = this->adapter->has(key);

this->fire("cache:afterHas");
this->fire("cache:afterHas", key);

return result;
}
Expand Down Expand Up @@ -266,11 +266,11 @@ abstract class AbstractCache implements CacheInterface, EventsAwareInterface

this->checkKey(key);

this->fire("cache:beforeSet");
this->fire("cache:beforeSet", key);

let result = this->adapter->set(key, value, ttl);

this->fire("cache:afterSet");
this->fire("cache:afterSet", key);

return result;
}
Expand All @@ -284,7 +284,7 @@ abstract class AbstractCache implements CacheInterface, EventsAwareInterface

this->checkKeys(values);

this->fire("cache:beforeSetMultiple");
this->fire("cache:beforeSetMultiple", array_keys(values));

let result = true;
for key, value in values {
Expand All @@ -293,7 +293,7 @@ abstract class AbstractCache implements CacheInterface, EventsAwareInterface
}
}

this->fire("cache:afterSetMultiple");
this->fire("cache:afterSetMultiple", array_keys(values));

return result;
}
Expand All @@ -302,14 +302,15 @@ abstract class AbstractCache implements CacheInterface, EventsAwareInterface
* Trigger an event for the eventsManager.
*
* @var string $eventName
* @var mixed $keys
*/
protected function fire(string eventName) -> void
protected function fire(string eventName, var keys) -> void
{
if (this->eventsManager === null) {
return;
}

this->eventsManager->fire(eventName, this);
this->eventsManager->fire(eventName, this, keys, false);
}

/**
Expand Down
11 changes: 6 additions & 5 deletions phalcon/Storage/Adapter/AbstractAdapter.zep
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ abstract class AbstractAdapter implements AdapterInterface, EventsAwareInterface
{
var content, result;

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

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

return defaultValue;
}
Expand All @@ -173,7 +173,7 @@ abstract class AbstractAdapter implements AdapterInterface, EventsAwareInterface

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

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

return result;
}
Expand Down Expand Up @@ -429,13 +429,14 @@ abstract class AbstractAdapter implements AdapterInterface, EventsAwareInterface
* Trigger an event for the eventsManager.
*
* @var string $eventName
* @var mixed $keys
*/
protected function fire(string eventName) -> void
protected function fire(string eventName, var keys) -> void
{
if (this->eventsManager === null) {
return;
}

this->eventsManager->fire(eventName, this);
this->eventsManager->fire(eventName, this, keys, false);
}
}
22 changes: 11 additions & 11 deletions phalcon/Storage/Adapter/Apcu.zep
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ class Apcu extends AbstractAdapter
{
var result;

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

let result = this->phpApcuDec(this->getPrefixedKey(key), value);

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

return result;
}
Expand All @@ -100,11 +100,11 @@ class Apcu extends AbstractAdapter
{
var result;

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

let result = (bool) this->phpApcuDelete(this->getPrefixedKey(key));

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

return result;
}
Expand Down Expand Up @@ -147,11 +147,11 @@ class Apcu extends AbstractAdapter
{
var result;

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

let result = this->phpApcuExists(this->getPrefixedKey(key));

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

return typeof result === "bool" ? result : false;
}
Expand All @@ -168,11 +168,11 @@ class Apcu extends AbstractAdapter
{
var result;

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

let result = this->phpApcuInc(this->getPrefixedKey(key), value);

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

return result;
}
Expand All @@ -195,12 +195,12 @@ class Apcu extends AbstractAdapter
{
var result;

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

if (typeof ttl === "integer" && ttl < 1) {
let result = this->delete(key);

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

return result;
}
Expand All @@ -211,7 +211,7 @@ class Apcu extends AbstractAdapter
this->getTtl(ttl)
);

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

return typeof result === "bool" ? result : false;
}
Expand Down
22 changes: 11 additions & 11 deletions phalcon/Storage/Adapter/Libmemcached.zep
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ class Libmemcached extends AbstractAdapter
{
var result;

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

let result = this->getAdapter()->decrement(key, value);

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

return result;
}
Expand All @@ -94,11 +94,11 @@ class Libmemcached extends AbstractAdapter
{
var result;

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

let result = this->getAdapter()->delete(key, 0);

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

return result;
}
Expand Down Expand Up @@ -181,13 +181,13 @@ class Libmemcached extends AbstractAdapter
{
var connection, result, code;

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

let connection = this->getAdapter(),
result = connection->get(key),
code = connection->getResultCode();

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

return \Memcached::RES_NOTFOUND !== code;
}
Expand All @@ -205,11 +205,11 @@ class Libmemcached extends AbstractAdapter
{
var result;

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

let result = this->getAdapter()->increment(key, value);

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

return result;
}
Expand All @@ -233,12 +233,12 @@ class Libmemcached extends AbstractAdapter
{
var result;

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

if (typeof ttl === "integer" && ttl < 1) {
let result = this->delete(key);

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

return result;
}
Expand All @@ -251,7 +251,7 @@ class Libmemcached extends AbstractAdapter
)
;

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

return typeof result === "bool" ? result : false;
}
Expand Down
Loading

0 comments on commit 09a6657

Please sign in to comment.