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

Commit

Permalink
Merge branch 'hotfix/4373' of git://github.com/weierophinney/zf2 into…
Browse files Browse the repository at this point in the history
… hotfix/4373
  • Loading branch information
Mike Willbanks committed May 7, 2013
205 parents 3d722b0 + 58d95bc + c9c40bb + 5f29760 + 714d1a8 + 84b0297 + cbc5f03 + 76361f8 + e7209df + 87630e0 + df43daf + f7d6cbb + 7e2b798 + 3ed1ead + 87505b6 + c229265 + eb61c8f + efcb00e + 0a0842f + b6d0c88 + 7edee62 + 60ea64c + a08bcca + b40ec3e + 63172ed + 448f428 + 92a516a + 5ecbc99 + a2df21b + 4de87f2 + 7c259ec + a22bdcb + 084ad9f + 9414e5a + 489be93 + cb39e7e + 54a28dc + c9c769e + dda791d + 70d382a + 8bbad0e + 9321185 + 7ab35a6 + b93694e + 3ea7087 + 0fe3d3a + bd5e189 + d1cba17 + 8d75392 + 3fb5b55 + 6cb0ccb + 30aa565 + 8409977 + 8074ba0 + 8f92486 + 94860d1 + 05d33c4 + 425826b + f0e91f0 + e31468f + 7d2af87 + 2e4dc80 + 19d128f + 1b9e4b2 + 1c46483 + fdda3f2 + 595fcd1 + 213395c + 8e514a8 + 2f30186 + bb4ed65 + 132d5b6 + 030ff33 + f2f20f3 + a50e133 + 4c554ee + dbfb1b8 + ccab83f + 00b350f + 78945d0 + f0e5f4b + ceb7d8c + 9e124d1 + 3de5912 + b6a974a + 10a6438 + cb6c1e7 + 18afd6c + 3baf1bd + c800904 + f52dcb8 + 126ccb2 + e7d6206 + e2d24ab + ec1abfc + 290ea90 + 9f4ca1b + edaa760 + c4c0c95 + d21f055 + 5b18029 + e6b97af + 010fb36 + 64c7b8d + 636523e + 4cc2cd6 + e34098a + 16367cd + 943c77f + 8226e5b + 0b47726 + 3cd8a03 + cc4782c + 9c653a6 + 656dbe5 + 9bce1ba + 7dc18ca + 861130d + 2d2ffbd + 4f413a5 + 2e1067a + 1d082e4 + e8aeb79 + b562091 + ff2fdc3 + 4aa72c0 + 1bb67ac + cd015c8 + 5e89910 + 0c21258 + dd54faf + 57f9063 + b88ce2e + af68643 + 06cd3b4 + 2c71b71 + ee02c35 + 9456314 + 5a77a7b + e98a077 + 738f2e6 + cb1e63c + 736df07 + d0a0154 + 990523c + 78687de + a5b6e79 + 6e9dfe9 + e201a1c + d9b45ef + 76222ad + 16d67da + 1ab2258 + b81d711 + ed2e9bc + 61efe82 + f353ea5 + 1f02519 + 58c1fe8 + ed502d9 + 2defba6 + 4885013 + 06a8384 + 17d9eed + 3b21b5d + c62101c + 909ef34 + 13d376a + 8a75367 + 98a3cf5 + 270f2c4 + 3038cfa + 1112202 + c8fb359 + 8d37cd0 + 4d868a7 + 555cb91 + 7ac5858 + 8103f1f + 9fe9c96 + a3ecac6 + 10e77c1 + e0d3e13 + 19ad608 + e0d665c + 1a5b402 + 56ae12a + 9073fc1 + 2d5b32f + a8e6198 + 83e8f34 + 8248c0b + c9f0cd0 + 30eb247 + 6204c2f + c3855a9 + 4baf625 + dc26d92 + c989091 + bc6d8c5 + ec25337 + 6934141 + 18f8ecc + 5bede1d + d3566be commit 41748cf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 85 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"zendframework/zend-eventmanager": "To support aggregate hydrator usage",
"zendframework/zend-serializer": "Zend\\Serializer component",
"zendframework/zend-servicemanager": "To support hydrator plugin manager usage",
"zendframework/zend-filter": "To support naming strategy hydrator usage",
"pecl-weakref": "Implementation of weak references for Stdlib\\CallbackHandler"
"zendframework/zend-filter": "To support naming strategy hydrator usage"
},
"extra": {
"branch-alias": {
Expand Down
85 changes: 2 additions & 83 deletions src/CallbackHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use Closure;
use ReflectionClass;
use WeakRef;

/**
* CallbackHandler
Expand Down Expand Up @@ -39,12 +38,6 @@ class CallbackHandler
*/
protected static $isPhp54;

/**
* Is pecl/weakref extension installed?
* @var bool
*/
protected static $hasWeakRefExtension;

/**
* Constructor
*
Expand All @@ -60,13 +53,6 @@ public function __construct($callback, array $metadata = array())
/**
* Registers the callback provided in the constructor
*
* If you have pecl/weakref {@see http://pecl.php.net/weakref} installed,
* this method provides additional behavior.
*
* If a callback is a functor, or an array callback composing an object
* instance, this method will pass the object to a WeakRef instance prior
* to registering the callback.
*
* @param callable $callback
* @throws Exception\InvalidCallbackException
* @return void
Expand All @@ -77,44 +63,7 @@ protected function registerCallback($callback)
throw new Exception\InvalidCallbackException('Invalid callback provided; not callable');
}

if (null === static::$hasWeakRefExtension) {
static::$hasWeakRefExtension = class_exists('WeakRef');
}

// If pecl/weakref is not installed, simply store the callback and return
if (!static::$hasWeakRefExtension) {
$this->callback = $callback;
return;
}

// If WeakRef exists, we want to use it.

// If we have a non-closure object, pass it to WeakRef, and then
// register it.
if (is_object($callback) && !$callback instanceof Closure) {
$this->callback = new WeakRef($callback);
return;
}

// If we have a string or closure, register as-is
if (!is_array($callback)) {
$this->callback = $callback;
return;
}

list($target, $method) = $callback;

// If we have an array callback, and the first argument is not an
// object, register as-is
if (!is_object($target)) {
$this->callback = $callback;
return;
}

// We have an array callback with an object as the first argument;
// pass it to WeakRef, and then register the new callback
$target = new WeakRef($target);
$this->callback = array($target, $method);
$this->callback = $callback;
}

/**
Expand All @@ -124,32 +73,7 @@ protected function registerCallback($callback)
*/
public function getCallback()
{
$callback = $this->callback;

// String callbacks -- simply return
if (is_string($callback)) {
return $callback;
}

// WeakRef callbacks -- pull it out of the object and return it
if ($callback instanceof WeakRef) {
return $callback->get();
}

// Non-WeakRef object callback -- return it
if (is_object($callback)) {
return $callback;
}

// Array callback with WeakRef object -- retrieve the object first, and
// then return
list($target, $method) = $callback;
if ($target instanceof WeakRef) {
return array($target->get(), $method);
}

// Otherwise, return it
return $callback;
return $this->callback;
}

/**
Expand All @@ -162,11 +86,6 @@ public function call(array $args = array())
{
$callback = $this->getCallback();

// WeakRef object will return null if the real object was disposed
if (null === $callback) {
return null;
}

// Minor performance tweak, if the callback gets called more than once
if (!isset(static::$isPhp54)) {
static::$isPhp54 = version_compare(PHP_VERSION, '5.4.0rc1', '>=');
Expand Down

0 comments on commit 41748cf

Please sign in to comment.