Browse Source

Making HelperRegistry accept a ConsoleIO in a setter

Passing it in the contructor was problematic as both classes depend
on each other.
Jose Lorenzo Rodriguez 10 years ago
parent
commit
6ebd6e18d0

+ 2 - 1
src/Console/ConsoleIo.php

@@ -107,7 +107,8 @@ class ConsoleIo
         $this->_out = $out ? $out : new ConsoleOutput('php://stdout');
         $this->_err = $err ? $err : new ConsoleOutput('php://stderr');
         $this->_in = $in ? $in : new ConsoleInput('php://stdin');
-        $this->_helpers = $helpers ? $helpers : new HelperRegistry($this);
+        $this->_helpers = $helpers ? $helpers : new HelperRegistry();
+        $this->_helpers->setIo($this);
     }
 
     /**

+ 2 - 2
src/Console/HelperRegistry.php

@@ -34,11 +34,11 @@ class HelperRegistry extends ObjectRegistry
     protected $_io;
 
     /**
-     * Constructor
+     * Sets The IO instance that should be passed to the shell helpers
      *
      * @param \Cake\Console\ConsoleIo $io An io instance.
      */
-    public function __construct(ConsoleIo $io)
+    public function setIo(ConsoleIo $io)
     {
         $this->_io = $io;
     }

+ 2 - 1
tests/TestCase/Console/HelperRegistryTest.php

@@ -35,7 +35,8 @@ class HelperRegistryTest extends TestCase
         parent::setUp();
         Configure::write('App.namespace', 'TestApp');
         $io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
-        $this->helpers = new HelperRegistry($io);
+        $this->helpers = new HelperRegistry();
+        $this->helpers->setIo($io);
     }
 
     /**