Skip to content

Commit

Permalink
Initial application.yml support
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Oct 4, 2010
1 parent 678704c commit 2ac3cea
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
16 changes: 16 additions & 0 deletions documentation/index.markdown
Expand Up @@ -6,6 +6,7 @@ Midgard MVC applications are written in the PHP language, and consist of a colle
Basic building blocks:
----------------------

* Application: a configuration file describing the components and other settings used in a Midgard MVC website
* Component: a PHP module intended to run as part of a web application. For example: a news listing. Provides routes, controllers and templates
* Library: a PHP module that can be called by other modules to perform some task. Does not run as part of a website. For example: a form validation library
* Service: a standardized interface to access a given functionality. For example: authentication
Expand All @@ -21,6 +22,21 @@ Installation
- Enable the Midgard2 extension in your `php.ini` with an `extension=midgard2.so`
- Copy Midgard MVC database definitions (`midgardmvc_core/configuration/mgdschema.xml`) to the Midgard schema directory (by default `/usr/share/midgard2/schema/`)

Application configuration
-------------------------

Application configuration is a configuration file read before Midgard MVC starts where you can define application-wide shared configuration settings, including overriding Midgard MVC default configurations. The components used with an application are defined in the application configuration file.

The application configuration is by default located in the root of your Midgard MVC installation directory in a YAML file called `application.yml`. Example:

name: Example Blog
components:
midgardmvc_core
source: git://github.com/midgardproject/midgardmvc_core.git
midgardmvc_create
services_dispatcher: midgard3
providers_component: midgardmvc

Running Midgard MVC
-------------------

Expand Down
39 changes: 31 additions & 8 deletions interface.php
Expand Up @@ -329,19 +329,42 @@ public static function get_instance($local_configuration = null)
return self::$instance;
}

if ( !is_null($local_configuration)
&& !is_array($local_configuration))
if (is_null($local_configuration))
{
// Ratatoskr-style dispatcher selection fallback
$local_configuration = array
(
'services_dispatcher' => $local_configuration,
);
$configuration = array();
}
else
{
if (is_array($local_configuration))
{
// Configuration passed as a PHP array
$configuration = $local_configuration;
}
elseif (is_string($local_configuration))
{
if (substr($local_configuration, 0, 1) == '/')
{
// Application YAML file provided, load configuration from it
$configuration = yaml_parse_file($local_configuration);
}
else
{
// Ratatoskr-style dispatcher selection fallback
$configuration = array
(
'services_dispatcher' => $local_configuration,
);
}
}
else
{
throw new Exception('Unrecognized configuration given for Midgard MVC initialization');
}
}

// Load and return MVC instance
self::$instance = new midgardmvc_core();
self::$instance->load_base_services($local_configuration);
self::$instance->load_base_services($configuration);
return self::$instance;
}
}
Expand Down

0 comments on commit 2ac3cea

Please sign in to comment.