Skip to content

Commit

Permalink
Use ContainerAwareTrait.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-1-anderson committed Sep 9, 2016
1 parent d5b9362 commit 1356eca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
19 changes: 12 additions & 7 deletions src/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
use Robo\Contract\BuilderAwareInterface;
use Robo\Common\IO;
use Robo\Exception\TaskExitException;
use League\Container\ContainerInterface;
use League\Container\ContainerAwareInterface;
use League\Container\ContainerAwareTrait;

class Runner
class Runner implements ContainerAwareInterface
{
const ROBOCLASS = 'RoboFile';
const ROBOFILE = 'RoboFile.php';

use IO;
use ContainerAwareTrait;

/**
* @var string RoboClass
Expand All @@ -37,17 +41,12 @@ class Runner
* @param null $roboClass
* @param null $roboFile
*/
public function __construct($roboClass = null, $roboFile = null, $container = null)
public function __construct($roboClass = null, $roboFile = null)
{
// set the const as class properties to allow overwriting in child classes
$this->roboClass = $roboClass ? $roboClass : self::ROBOCLASS ;
$this->roboFile = $roboFile ? $roboFile : self::ROBOFILE;
$this->dir = getcwd();

// Store the container in our config object if it was provided.
if ($container != null) {
Robo::setContainer($container);
}
}

protected function loadRoboFile($output)
Expand Down Expand Up @@ -110,9 +109,15 @@ public function run($input = null, $output = null, $app = null, $commandFiles =
$this->setInput($input);
$this->setOutput($output);

// If our client gave us a container, then also set it inside
// the static Robo class.
if ($this->getContainer()) {
Robo::setContainer($this->getContainer());
}
// If we were not provided a container, then create one
if (!Robo::hasContainer()) {
Robo::createDefaultContainer($input, $output, $app);
$this->setContainer(Robo::getContainer());
// Automatically register a shutdown function and
// an error handler when we provide the container.
$this->installRoboHandlers();
Expand Down
5 changes: 4 additions & 1 deletion src/Tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
use Robo\Common\IO;
use Robo\Contract\IOAwareInterface;
use Robo\Contract\BuilderAwareInterface;
use League\Container\ContainerAwareInterface;
use League\Container\ContainerAwareTrait;

class Tasks implements BuilderAwareInterface, IOAwareInterface
class Tasks implements BuilderAwareInterface, IOAwareInterface, ContainerAwareInterface
{
use ContainerAwareTrait;
use LoadAllTasks; // uses TaskAccessor, which uses BuilderAwareTrait
use IO;

Expand Down

0 comments on commit 1356eca

Please sign in to comment.