Skip to content

Commit

Permalink
Application config YML support for the MVC shell
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Oct 5, 2010
1 parent b741e76 commit 64220d7
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions bin/mvcshell.php
Expand Up @@ -6,16 +6,7 @@

// Defaults for configuration
$mvc_config_yaml = file_get_contents(MIDGARDMVC_ROOT. '/midgardmvc_core/configuration/defaults.yml');
if (!extension_loaded('yaml'))
{
// YAML PHP extension is not loaded, include the pure-PHP implementation
require_once MIDGARDMVC_ROOT. '/midgardmvc_core/helpers/spyc.php';
$config = Spyc::YAMLLoad($mvc_config_yaml);
}
else
{
$config = yaml_parse($mvc_config_yaml);
}
$config = midgardmvc_core::read_yaml($mvc_config_yaml);

$config['services_dispatcher'] = 'manual';
$config['providers_component'] = 'midgardmvc';
Expand Down Expand Up @@ -60,7 +51,8 @@
}

if ( !isset($config[$config_key])
&& $config_key != 'midgard')
&& $config_key != 'midgard'
&& $config_key != 'application_config')
{
mvcshell_print("Unrecognized configuration parameter '{$config_key}'");
}
Expand Down Expand Up @@ -93,7 +85,7 @@
// This argument is neither config nor command, add it to the arg list
$remaining_arguments[] = $arguments[$i];
}
mvcshell_check_config($config);
$config = mvcshell_check_config($config);
$midgardmvc = midgardmvc_core::get_instance($config);

call_user_func($commands[$command], $remaining_arguments);
Expand Down Expand Up @@ -126,6 +118,27 @@ function mvcshell_help()

function mvcshell_check_config(array $config)
{

// Check for application config file defined in php.ini
$application_config = get_cfg_var('midgardmvc.application_config');
if (isset($config['application_config']))
{
$application_config = $config['application_config'];
unset($config['application_config']);
}
if ($application_config)
{
if (!file_exists($application_config))
{
mvcshell_print("Specified application configuration file {$application_config} not found.");
}
$local_config = midgardmvc_core::read_yaml(file_get_contents($application_config));
foreach ($local_config as $key => $value)
{
$config[$key] = $value;
}
}

$requires_midgard = false;
if ( $config['providers_hierarchy'] == 'midgardmvc_core_providers_hierarchy_midgardmvc'
|| $config['providers_hierarchy'] == 'midgardmvc')
Expand Down Expand Up @@ -163,6 +176,7 @@ function mvcshell_check_config(array $config)
}
unset($config['midgard']);
}
return $config;
}

function mvcshell_call(array $arguments)
Expand Down

0 comments on commit 64220d7

Please sign in to comment.