Various updates.

This commit is contained in:
Julien Fontanet 2013-03-04 15:57:07 +01:00
parent 0ab5c33ddf
commit 1203149cb7
4 changed files with 98 additions and 23 deletions

View File

@ -41,11 +41,11 @@ return array(
// For now, XCP servers/pool masters must be defined in this file. // For now, XCP servers/pool masters must be defined in this file.
'xcp' => array( 'xcp' => array(
'pool 1' => array( //'pool 1' => array(
'url' => 'https://xcp1.example.net', // 'url' => 'https://xcp1.example.net',
'username' => 'username', // 'username' => 'username',
'password' => 'password' // 'password' => 'password'
), //),
), ),
); );

View File

@ -556,7 +556,7 @@ final class Application extends Base
//-------------------------------------- //--------------------------------------
// Creates master sockets. // Creates master sockets.
foreach ($config->get('listen') as $uri) foreach ($config['listen'] as $uri)
{ {
$handle = self::_createServer($uri); $handle = self::_createServer($uri);
$loop->addRead($handle, array($this, 'handleServer')); $loop->addRead($handle, array($this, 'handleServer'));
@ -564,7 +564,7 @@ final class Application extends Base
//-------------------------------------- //--------------------------------------
foreach ($config->get('xcp') as $_) foreach ($config['xcp'] as $_)
{ {
$xcp = new XCP($loop, $_['url'], $_['username'], $_['password']); $xcp = new XCP($loop, $_['url'], $_['username'], $_['password']);
$xcp->queue( $xcp->queue(
@ -782,7 +782,7 @@ final class Application extends Base
)); ));
$bytes = @file_put_contents( $bytes = @file_put_contents(
$this->_di->get('config')->get('database.json'), $this->_di->get('config')['database.json'],
$data $data
); );
if ($bytes === false) if ($bytes === false)
@ -799,7 +799,7 @@ final class Application extends Base
*/ */
private function _loadDatabase() private function _loadDatabase()
{ {
$file = $this->_di->get('config')->get('database.json'); $file = $this->_di->get('config')['database.json'];
if (!file_exists($file)) if (!file_exists($file))
{ {
trigger_error( trigger_error(
@ -824,7 +824,7 @@ final class Application extends Base
} }
$data = @file_get_contents( $data = @file_get_contents(
$this->_di->get('config')->get('database.json') $this->_di->get('config')['database.json']
); );
if (($data === false) if (($data === false)
|| (($data = json_decode($data, true)) === null)) || (($data = json_decode($data, true)) === null))

View File

@ -25,7 +25,10 @@
/** /**
* *
*/ */
final class Config extends Base final class Config extends Base implements
ArrayAccess,
Countable,
IteratorAggregate
{ {
/** /**
* *
@ -76,6 +79,19 @@ final class Config extends Base
return $this->_resolve($entry); return $this->_resolve($entry);
} }
/**
*
*/
function merge($entries)
{
if ($entries instanceof self)
{
$entries = $entries->_entries;
}
$this->_entries = array_merge_recursive($this->_entries, $entries);
}
/** /**
* *
* *
@ -119,6 +135,66 @@ final class Config extends Base
$entry = $value; $entry = $value;
} }
//--------------------------------------
/**
*
*/
function offsetGet($offset)
{
return $this->get($offset);
}
/**
*
*/
function offsetExists($offset)
{
return (isset($this->_entries[$offset])
|| array_key_exists($offset, $this->_entries));
}
/**
*
*/
function offsetSet($offset, $value)
{
$this->set($offset, $value);
}
/**
*
*/
function offsetUnset($index)
{
trigger_error(
get_class($this).'['.var_export($index, true).'] is not deletable',
E_USER_ERROR
);
}
//--------------------------------------
/**
* @return integer
*/
function count()
{
return count($this->_entries);
}
//--------------------------------------
/**
*
*/
function getIterator()
{
return \ArrayIterator($this->_entries);
}
//--------------------------------------
/** /**
* @var array * @var array
*/ */

View File

@ -32,23 +32,22 @@ function _bootstrap()
if (!isset($application)) if (!isset($application))
{ {
// Variables definition.
$root_dir = defined('__DIR__')
? __DIR__
: dirname(__FILE__)
;
// Class autoloading is done by composer. // Class autoloading is done by composer.
require($root_dir.'/vendor/autoload.php'); require(__DIR__.'/vendor/autoload.php');
// Reads configuration. // Reads configuration.
$config = new Config(array_merge_recursive( $config = new Config;
require($root_dir.'/config/global.php'), foreach (array('global', 'local') as $file)
require($root_dir.'/config/local.php') {
)); $file = __DIR__.'/config/'.$file.'.php';
if (is_file($file))
{
$config->merge(require($file));
}
}
// Injects some variables. // Injects some variables.
$config->set('root_dir', $root_dir); $config['root_dir'] = __DIR__;
// Dependency injector. // Dependency injector.
$di = new DI; $di = new DI;