Commit 9dfc6bfb authored by Jon Pugh's avatar Jon Pugh

Load web_server context into PlatformContext. Pass Application into Context classes,

parent 7f8dfddf
......@@ -8,6 +8,7 @@ use Aegir\Provision\Command\ShellCommand;
use Aegir\Provision\Command\StatusCommand;
use Aegir\Provision\Command\VerifyCommand;
use Aegir\Provision\Console\Config;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\HelpCommand;
use Symfony\Component\Console\Command\ListCommand;
use Symfony\Component\Console\Input\InputInterface;
......@@ -137,16 +138,22 @@ class Application extends BaseApplication
*
* @return array
*/
function getAllContexts() {
function getAllContexts($name = '') {
$contexts = [];
$finder = new \Symfony\Component\Finder\Finder();
$finder->files()->name('*.yml')->in($this->config->get('config_path') . '/provision');
$finder->files()->name('*.' . $name . '.yml')->in($this->config->get('config_path') . '/provision');
foreach ($finder as $file) {
list($context_type, $context_name) = explode('.', $file->getFilename());
$class = '\Aegir\Provision\Context\\' . ucfirst($context_type) . "Context";
$contexts[$context_name] = new $class($context_name, $this->config->all());
$contexts[$context_name] = new $class($context_name, $this->config->all(), $this);
}
if ($name) {
return $contexts[$name];
}
else {
return $contexts;
}
return $contexts;
}
/**
......@@ -158,9 +165,9 @@ class Application extends BaseApplication
* @throws \Exception
*/
function getContext($name) {
if (empty($this->getAllContexts()[$name])) {
if (empty($this->getAllContexts($name))) {
throw new \Exception('Context not found with name: ' . $name);
}
return $this->getAllContexts()[$name];
return $this->getAllContexts($name);
}
}
......@@ -50,6 +50,11 @@ class Context
*/
protected $properties = [];
/**
* @var \Aegir\Provision\Application;
*/
public $application;
/**
* @var LoggerInterface
*/
......@@ -62,9 +67,10 @@ class Context
* @param $console_config
* @param array $options
*/
function __construct($name, $console_config, $options = [])
function __construct($name, $console_config, Application $application, $options = [])
{
$this->name = $name;
$this->application = $application;
$this->loadContextConfig($console_config, $options);
}
......
......@@ -2,6 +2,7 @@
namespace Aegir\Provision\Context;
use Aegir\Provision\Application;
use Aegir\Provision\Context;
use Symfony\Component\Config\Definition\ConfigurationInterface;
......@@ -18,7 +19,35 @@ class PlatformContext extends Context implements ConfigurationInterface
* @var string
*/
public $type = 'platform';
/**
* @var \Aegir\Provision\Context\ServerContext;
*/
public $web_server;
/**
* PlatformContext constructor.
*
* @param $name
* @param $console_config
* @param Application $application
* @param array $options
*/
function __construct($name, $console_config, Application $application, array $options = [])
{
parent::__construct($name, $console_config, $application, $options);
// Load "web_server" context.
if (isset($this->config['web_server'])) {
$this->web_server = $application->getContext($this->config['web_server']);
$this->web_server->logger = $application->logger;
}
else {
throw new \Exception('No web_server found.');
}
}
static function option_documentation()
{
$options = [
......@@ -31,4 +60,11 @@ class PlatformContext extends Context implements ConfigurationInterface
return $options;
}
public function verify() {
parent::verify();
$this->web_server->verify();
return "Platform Context Verified: " . $this->name;
}
}
......@@ -2,6 +2,7 @@
namespace Aegir\Provision\Context;
use Aegir\Provision\Application;
use Aegir\Provision\Context;
use Consolidation\AnnotatedCommand\CommandFileDiscovery;
use Drupal\Console\Core\Style\DrupalStyle;
......@@ -36,9 +37,9 @@ class ServerContext extends Context implements ConfigurationInterface
* @param $console_config
* @param array $options
*/
function __construct($name, $console_config, array $options = [])
function __construct($name, $console_config, Application $application,array $options = [])
{
parent::__construct($name, $console_config, $options);
parent::__construct($name, $console_config, $application, $options);
if (isset($this->config['services'])) {
$this->prepareServices();
}
......
......@@ -16,16 +16,10 @@ class PlatformConfiguration extends Configuration {
const SERVICE_TYPE = 'apache';
public $template = 'server.tpl.php';
public $description = 'web server configuration file';
public $template = 'platform.tpl.php';
public $description = 'platform configuration file';
function filename() {
if (isset($this->data['application_name'])) {
$file = $this->data['application_name'] . '.conf';
return $this->data['server']->config_path . '/' . $file;
}
else {
return FALSE;
}
return $this->service->properties['http_platformd_path'] . '/' . ltrim($this->context->name, '@') . '.conf';
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment