Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit a0eee5869354ff55513993258e2ada204f38f519 1 parent 5529705
Paul M. Jones authored
24  src/Aura/Sql/GatewayLocator.php
@@ -32,13 +32,20 @@ class GatewayLocator implements IteratorAggregate
32 32
 
33 33
     /**
34 34
      * 
  35
+     * Tracks whether or not a registry entry has been converted from a 
  36
+     * callable to a gateway object.
  37
+     * 
  38
+     * @var array
  39
+     * 
  40
+     */
  41
+    protected $converted = [];
  42
+    
  43
+    /**
  44
+     * 
35 45
      * Constructor.
36 46
      * 
37 47
      * @param array $registry An array of key-value pairs where the key is the
38  
-     * recode name and the value is the gateway
39  
-     * object. The value may also be a closure that returns a gateway object.
40  
-     * Note that is has to be a closure, not just any callable, because the
41  
-     * gateway object itself might be callable.
  48
+     * gateway name and the value is a callable that returns a gateway object.
42 49
      * 
43 50
      */
44 51
     public function __construct(array $registry = [])
@@ -66,15 +73,15 @@ public function getIterator()
66 73
      * 
67 74
      * @param string $name The gateway name.
68 75
      * 
69  
-     * @param string $spec The gateway specification, typically a closure that
70  
-     * builds and returns a gateway object.
  76
+     * @param callable $spec A callable that returns a gateway object.
71 77
      * 
72 78
      * @return void
73 79
      * 
74 80
      */
75  
-    public function set($name, $spec)
  81
+    public function set($name, callable $spec)
76 82
     {
77 83
         $this->registry[$name] = $spec;
  84
+        $this->converted[$name] = false;
78 85
     }
79 86
 
80 87
     /**
@@ -92,9 +99,10 @@ public function get($name)
92 99
             throw new Exception\NoSuchGateway($name);
93 100
         }
94 101
 
95  
-        if ($this->registry[$name] instanceof \Closure) {
  102
+        if (! $this->converted[$name]) {
96 103
             $func = $this->registry[$name];
97 104
             $this->registry[$name] = $func();
  105
+            $this->converted[$name] = true;
98 106
         }
99 107
 
100 108
         return $this->registry[$name];
2  tests/Aura/Sql/UnitOfWorkTest.php
@@ -49,7 +49,7 @@ protected function setUp()
49 49
         $this->gateway = new Gateway($this->connections, $this->mapper);
50 50
         
51 51
         $this->gateways = new GatewayLocator([
52  
-            'mock' => $this->gateway,
  52
+            'mock' => function () { return $this->gateway; },
53 53
         ]);
54 54
         
55 55
         $this->work = new UnitOfWork($this->gateways);

0 notes on commit a0eee58

Please sign in to comment.
Something went wrong with that request. Please try again.