summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Pugh2017-11-16 21:08:03 (GMT)
committerJon Pugh2017-11-16 21:08:03 (GMT)
commit10bf4473188dde47ca9c93619d97615623fad18c (patch)
treeae6b1cbc51fe04bcff0344b1fc46ccf6696fd17e
parent1a3ac1281979cb47fda57cdfad8bb29740991787 (diff)
Adding ContainerAwareTrait to Provision class, adding ProvisionTasks.php
-rw-r--r--src/Provision.php30
-rw-r--r--src/ProvisionTasks.php61
2 files changed, 87 insertions, 4 deletions
diff --git a/src/Provision.php b/src/Provision.php
index edfc19a..df8e2f9 100644
--- a/src/Provision.php
+++ b/src/Provision.php
@@ -7,6 +7,9 @@ use Aegir\Provision\Commands\ExampleCommands;
use Aegir\Provision\Console\Config as ConsoleConfig;
use Consolidation\Config\Loader\ConfigProcessor;
+use League\Container\Container;
+use League\Container\ContainerAwareTrait;
+use Robo\Collection\CollectionBuilder;
use Robo\Common\ConfigAwareTrait;
use Robo\Config\Config;
use Robo\Robo;
@@ -18,11 +21,13 @@ use Symfony\Component\Console\Output\OutputInterface;
class Provision {
const APPLICATION_NAME = 'Aegir Provision';
+ const VERSION = '4.x-dev';
const REPOSITORY = 'aegir-project/provision';
use ConfigAwareTrait;
+ use ContainerAwareTrait;
- private $runner;
+ public $runner;
public function __construct(
// Config $config,
@@ -39,14 +44,15 @@ class Provision {
$this->setConfig($config);
// Create Application.
- $application = new \Aegir\Provision\Application(self::APPLICATION_NAME, $config->get('version'));
+ $application = new \Aegir\Provision\Application(self::APPLICATION_NAME, self::VERSION);
+ $application->provision = $this;
$application->console = $output;
$application->setConfig($consoleConfig);
// Create and configure container.
$container = Robo::createDefaultContainer($input, $output, $application, $config);
-// $this->setContainer($container);
-// $container->add(MyCustomService::class);
+ $this->setContainer($container);
+ $this->configureContainer($container);
// Instantiate Robo Runner.
$this->runner = new RoboRunner([
@@ -63,4 +69,20 @@ class Provision {
return $status_code;
}
+ /**
+ * Register the necessary classes for BLT.
+ */
+ public function configureContainer(Container $container) {
+
+ // FROM https://github.com/acquia/blt :
+ // We create our own builder so that non-command classes are able to
+ // implement task methods, like taskExec(). Yes, there are now two builders
+ // in the container. "collectionBuilder" used for the actual command that
+ // was executed, and "builder" to be used with non-command classes.
+ $tasks = new ProvisionTasks();
+ $builder = new CollectionBuilder($tasks);
+ $tasks->setBuilder($builder);
+ $container->add('builder', $builder);
+
+ }
}
diff --git a/src/ProvisionTasks.php b/src/ProvisionTasks.php
new file mode 100644
index 0000000..f490118
--- /dev/null
+++ b/src/ProvisionTasks.php
@@ -0,0 +1,61 @@
+<?php
+
+namespace Aegir\Provision;
+
+use Consolidation\Config\ConfigInterface;
+use League\Container\ContainerAwareInterface;
+use League\Container\ContainerAwareTrait;
+use Psr\Log\LoggerAwareInterface;
+use Psr\Log\LoggerAwareTrait;
+use Robo\Collection\CollectionBuilder;
+use Robo\Common\ConfigAwareTrait;
+use Robo\Common\IO;
+use Robo\Contract\BuilderAwareInterface;
+use Robo\Contract\ConfigAwareInterface;
+use Robo\Contract\IOAwareInterface;
+use Robo\Task\Base\loadTasks;
+
+/**
+ * Base class for BLT Robo commands.
+ */
+class ProvisionTasks implements ConfigAwareInterface, LoggerAwareInterface, BuilderAwareInterface, IOAwareInterface, ContainerAwareInterface
+{
+
+ use ContainerAwareTrait;
+ use loadTasks;
+
+ use ConfigAwareTrait;
+// use InspectorAwareTrait;
+ use IO;
+ use LoggerAwareTrait;
+
+ /**
+ * Set the config reference
+ *
+ * @param ConfigInterface $config
+ *
+ * @return $this
+ */
+ public function setConfig(ConfigInterface $config) {
+ $this->config = $config;
+ }
+
+ /**
+ * Get the config reference
+ *
+ * @return ConfigInterface
+ */
+ public function getConfig() {
+ return $this->config;
+ }
+
+ public function getBuilder()
+ {
+ return $this->builder;
+ }
+
+ public function setBuilder(CollectionBuilder $builder)
+ {
+ $this->builder = $builder;
+ }
+}