Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/zendframework/zendframework#6259-cache-event-pos…
Browse files Browse the repository at this point in the history
…t-after-pre-should-always-be-triggered' into develop

Close zendframework/zendframework#6259
  • Loading branch information
Ocramius committed Nov 14, 2014
153 parents 0f942af + a5fb9cb + 02e14e6 + e24be06 + 1cd130f + 2f4d84a + c5055d9 + b5302e2 + 9969a8b + 83a796c + 7f06dd1 + 40e1948 + fae5b14 + 1d8b0d4 + 0885ee4 + 31378a4 + 22dc55a + 4fe9653 + 0835021 + 26ee41a + be4158f + a1e2d7e + 4abdf38 + e59ea5a + fbff658 + 48d0341 + 401d180 + 4e95264 + 5431207 + a7a7974 + 7c3f597 + a50748b + 700cf3a + 1582c31 + 016f50c + 9852497 + 073b126 + bd99c5c + 56451bd + 8fe4cad + 18812d8 + 89590ab + 0f8f25b + c2a03a9 + 4c690cd + 52cb4e6 + f7ed984 + 1d190a2 + 3c5d19b + c3c849d + faa6e57 + ad46181 + 12a401e + 3738445 + 65aacba + bf5f5a3 + c2ac9c0 + 6d7cf99 + 1841b47 + f81171b + 5ffaadf + cd6d5f2 + a512601 + 926e71f + 1f29b3e + a75171a + 9a8e72f + 814716e + 88d9371 + 678232d + a0560e8 + 4ff045c + ac805a6 + 41f360c + 1939a3c + 730da5d + dd0a1b5 + 1bc1ed5 + cea3413 + f2b47df + 2b8aa6a + 42cb3fe + 46afe3b + ef4289e + f40a98a + 8c27e9d + 512d6ca + b1452f8 + 9f6e228 + cf96a5a + aa9ef86 + 04be01e + 93487ba + c640cb5 + ab2b436 + a876e82 + 01f54c9 + f0abecc + 920eae1 + db4f625 + f51678c + 5975f0e + e9d78fe + 03de5ee + d7320d7 + 16ff5c5 + f170b61 + b506606 + f6c7309 + 675c421 + 43220df + c076d41 + e9406c0 + bb1710e + 565433c + be0baa3 + 8d2dae7 + ba17210 + bf83129 + 40926a2 + a7690f0 + 4fbd64e + f1f095f + 5077dc6 + 7d6f60c + a5f3296 + e036825 + 337996c + 285fc46 + 277a8aa + 0103b22 + 0d32a70 + bb27ee5 + e8ecd1e + f2b29a0 + 5205046 + 257c166 + 3122c56 + a8eef4b + 736bf24 + f1bdd85 + 30d927d + 0b20126 + ef5cf6f + 2efe2a7 + 9c5c0a0 + b163911 + 078c1c8 + ae78853 + 4290f30 + 77fe406 + fb5d494 + 2a8ac17 commit 9ae6165
Show file tree
Hide file tree
Showing 2 changed files with 197 additions and 97 deletions.
191 changes: 94 additions & 97 deletions src/Storage/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,10 @@ protected function triggerPost($eventName, ArrayObject $args, & $result)
{
$postEvent = new PostEvent($eventName . '.post', $this, $args, $result);
$eventRs = $this->getEventManager()->trigger($postEvent);
if ($eventRs->stopped()) {
return $eventRs->last();
}

return $postEvent->getResult();
return $eventRs->stopped()
? $eventRs->last()
: $postEvent->getResult();
}

/**
Expand All @@ -246,11 +245,9 @@ protected function triggerException($eventName, ArrayObject $args, & $result, \E
throw $exceptionEvent->getException();
}

if ($eventRs->stopped()) {
return $eventRs->last();
}

return $exceptionEvent->getResult();
return $eventRs->stopped()
? $eventRs->last()
: $exceptionEvent->getResult();
}

/**
Expand Down Expand Up @@ -357,17 +354,17 @@ public function getItem($key, & $success = null, & $casToken = null)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

if ($args->offsetExists('success') && $args->offsetExists('casToken')) {
if ($eventRs->stopped()) {
$result = $eventRs->last();
} elseif ($args->offsetExists('success') && $args->offsetExists('casToken')) {
$result = $this->internalGetItem($args['key'], $args['success'], $args['casToken']);
} elseif ($args->offsetExists('success')) {
$result = $this->internalGetItem($args['key'], $args['success']);
} else {
$result = $this->internalGetItem($args['key']);
}

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = null;
Expand Down Expand Up @@ -411,11 +408,11 @@ public function getItems(array $keys)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalGetItems($args['keys']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalGetItems($args['keys']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = array();
Expand Down Expand Up @@ -468,11 +465,11 @@ public function hasItem($key)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalHasItem($args['key']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalHasItem($args['key']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = false;
Expand Down Expand Up @@ -518,11 +515,11 @@ public function hasItems(array $keys)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalHasItems($args['keys']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalHasItems($args['keys']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = array();
Expand Down Expand Up @@ -572,11 +569,11 @@ public function getMetadata($key)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalGetMetadata($args['key']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalGetMetadata($args['key']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = false;
Expand Down Expand Up @@ -624,11 +621,11 @@ public function getMetadatas(array $keys)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalGetMetadatas($args['keys']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalGetMetadatas($args['keys']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = array();
Expand Down Expand Up @@ -683,11 +680,11 @@ public function setItem($key, $value)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalSetItem($args['key'], $args['value']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalSetItem($args['key'], $args['value']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = false;
Expand Down Expand Up @@ -729,11 +726,11 @@ public function setItems(array $keyValuePairs)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalSetItems($args['keyValuePairs']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalSetItems($args['keyValuePairs']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = array_keys($keyValuePairs);
Expand Down Expand Up @@ -785,11 +782,11 @@ public function addItem($key, $value)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalAddItem($args['key'], $args['value']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalAddItem($args['key'], $args['value']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = false;
Expand Down Expand Up @@ -837,11 +834,11 @@ public function addItems(array $keyValuePairs)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalAddItems($args['keyValuePairs']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalAddItems($args['keyValuePairs']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = array_keys($keyValuePairs);
Expand Down Expand Up @@ -893,11 +890,11 @@ public function replaceItem($key, $value)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalReplaceItem($args['key'], $args['value']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalReplaceItem($args['key'], $args['value']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = false;
Expand Down Expand Up @@ -946,11 +943,11 @@ public function replaceItems(array $keyValuePairs)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalReplaceItems($args['keyValuePairs']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalReplaceItems($args['keyValuePairs']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = array_keys($keyValuePairs);
Expand Down Expand Up @@ -1005,11 +1002,11 @@ public function checkAndSetItem($token, $key, $value)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalCheckAndSetItem($args['token'], $args['key'], $args['value']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalCheckAndSetItem($args['token'], $args['key'], $args['value']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = false;
Expand Down Expand Up @@ -1062,11 +1059,11 @@ public function touchItem($key)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalTouchItem($args['key']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalTouchItem($args['key']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = false;
Expand Down Expand Up @@ -1116,11 +1113,11 @@ public function touchItems(array $keys)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalTouchItems($args['keys']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalTouchItems($args['keys']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $keys, $e);
Expand Down Expand Up @@ -1169,11 +1166,11 @@ public function removeItem($key)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalRemoveItem($args['key']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalRemoveItem($args['key']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = false;
Expand Down Expand Up @@ -1214,11 +1211,11 @@ public function removeItems(array $keys)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalRemoveItems($args['keys']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalRemoveItems($args['keys']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $keys, $e);
Expand Down Expand Up @@ -1269,11 +1266,11 @@ public function incrementItem($key, $value)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalIncrementItem($args['key'], $args['value']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalIncrementItem($args['key'], $args['value']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = false;
Expand Down Expand Up @@ -1329,11 +1326,11 @@ public function incrementItems(array $keyValuePairs)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalIncrementItems($args['keyValuePairs']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalIncrementItems($args['keyValuePairs']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = array();
Expand Down Expand Up @@ -1386,11 +1383,11 @@ public function decrementItem($key, $value)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalDecrementItem($args['key'], $args['value']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalDecrementItem($args['key'], $args['value']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = false;
Expand Down Expand Up @@ -1446,11 +1443,11 @@ public function decrementItems(array $keyValuePairs)

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalDecrementItems($args['keyValuePairs']);
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalDecrementItems($args['keyValuePairs']);

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = array();
Expand Down Expand Up @@ -1493,11 +1490,11 @@ public function getCapabilities()

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalGetCapabilities();
$result = $eventRs->stopped()
? $eventRs->last()
: $this->internalGetCapabilities();

return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
$result = false;
Expand Down
Loading

0 comments on commit 9ae6165

Please sign in to comment.