Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

registry entries *must* be wrapped in a callable from now on

  • Loading branch information...
commit a0eee5869354ff55513993258e2ada204f38f519 1 parent 5529705
@pmjones pmjones authored
View
24 src/Aura/Sql/GatewayLocator.php
@@ -32,13 +32,20 @@ class GatewayLocator implements IteratorAggregate
/**
*
+ * Tracks whether or not a registry entry has been converted from a
+ * callable to a gateway object.
+ *
+ * @var array
+ *
+ */
+ protected $converted = [];
+
+ /**
+ *
* Constructor.
*
* @param array $registry An array of key-value pairs where the key is the
- * recode name and the value is the gateway
- * object. The value may also be a closure that returns a gateway object.
- * Note that is has to be a closure, not just any callable, because the
- * gateway object itself might be callable.
+ * gateway name and the value is a callable that returns a gateway object.
*
*/
public function __construct(array $registry = [])
@@ -66,15 +73,15 @@ public function getIterator()
*
* @param string $name The gateway name.
*
- * @param string $spec The gateway specification, typically a closure that
- * builds and returns a gateway object.
+ * @param callable $spec A callable that returns a gateway object.
*
* @return void
*
*/
- public function set($name, $spec)
+ public function set($name, callable $spec)
{
$this->registry[$name] = $spec;
+ $this->converted[$name] = false;
}
/**
@@ -92,9 +99,10 @@ public function get($name)
throw new Exception\NoSuchGateway($name);
}
- if ($this->registry[$name] instanceof \Closure) {
+ if (! $this->converted[$name]) {
$func = $this->registry[$name];
$this->registry[$name] = $func();
+ $this->converted[$name] = true;
}
return $this->registry[$name];
View
2  tests/Aura/Sql/UnitOfWorkTest.php
@@ -49,7 +49,7 @@ protected function setUp()
$this->gateway = new Gateway($this->connections, $this->mapper);
$this->gateways = new GatewayLocator([
- 'mock' => $this->gateway,
+ 'mock' => function () { return $this->gateway; },
]);
$this->work = new UnitOfWork($this->gateways);
Please sign in to comment.
Something went wrong with that request. Please try again.