Skip to content

Commit

Permalink
Load components specified in application configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Oct 4, 2010
1 parent 2ac3cea commit 7cd2c50
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
4 changes: 4 additions & 0 deletions httpd/appserv_app.php
Expand Up @@ -33,6 +33,10 @@ public function __invoke($context)
'services_dispatcher' => 'appserv',
//'services_authentication' => 'runtime',
'providers_component' => 'midgardmvc',
'components' => array
(
'midgardmvc_core' => array(),
),
);
$mvc = midgardmvc_core::get_instance($config);
$mvc->dispatcher->set_request_data($context);
Expand Down
28 changes: 13 additions & 15 deletions providers/component/midgardmvc.php
Expand Up @@ -14,6 +14,7 @@
class midgardmvc_core_providers_component_midgardmvc implements midgardmvc_core_providers_component
{
public $components = array();
private $components_enabled = array();
private $injectors = array
(
'process' => array(),
Expand All @@ -24,6 +25,7 @@ class midgardmvc_core_providers_component_midgardmvc implements midgardmvc_core_

public function __construct()
{
$this->components_enabled = midgardmvc_core::get_instance()->configuration->components;
$this->load_all_manifests();
}

Expand All @@ -38,6 +40,12 @@ public function get($component)
// Component is installed and already loaded
return $this->components[$component];
}

if (!isset($this->components_enabled[$component]))
{
throw new OutOfRangeException("Component {$component} is not enabled in application configuration");
}

if (!isset($this->manifests[$component]))
{
$manifest_path = $this->get_manifest_path($component);
Expand Down Expand Up @@ -156,27 +164,17 @@ private function load_manifest_file($manifest_file)

private function load_all_manifests()
{
// Load manifests and cache them
$manifest_files = array();
$MIDGARDMVC_ROOT = dir(MIDGARDMVC_ROOT);

while (false !== ($component = $MIDGARDMVC_ROOT->read()))
{
if ( substr($component, 0, 1) == '.'
|| $component == 'scaffold'
|| $component == 'PHPTAL'
|| $component == 'PHPTAL.php')
{
continue;
}
// Load manifests enabled in site configuration and cache them
$components = midgardmvc_core::get_instance()->configuration->components;
foreach ($components as $component => $setup_info)
{
$component_path = MIDGARDMVC_ROOT . "/{$component}";
if (!file_exists("{$component_path}/manifest.yml"))
{
continue;
throw new Exception("Component {$component} specified in application configuration is not installed");
}

$this->manifests[$component] = $this->load_manifest_file("{$component_path}/manifest.yml");
}
$MIDGARDMVC_ROOT->close();
}
}

0 comments on commit 7cd2c50

Please sign in to comment.