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.
'xcp' => array(
'pool 1' => array(
'url' => 'https://xcp1.example.net',
'username' => 'username',
'password' => 'password'
),
//'pool 1' => array(
// 'url' => 'https://xcp1.example.net',
// 'username' => 'username',
// 'password' => 'password'
//),
),
);

View File

@ -556,7 +556,7 @@ final class Application extends Base
//--------------------------------------
// Creates master sockets.
foreach ($config->get('listen') as $uri)
foreach ($config['listen'] as $uri)
{
$handle = self::_createServer($uri);
$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->queue(
@ -782,7 +782,7 @@ final class Application extends Base
));
$bytes = @file_put_contents(
$this->_di->get('config')->get('database.json'),
$this->_di->get('config')['database.json'],
$data
);
if ($bytes === false)
@ -799,7 +799,7 @@ final class Application extends Base
*/
private function _loadDatabase()
{
$file = $this->_di->get('config')->get('database.json');
$file = $this->_di->get('config')['database.json'];
if (!file_exists($file))
{
trigger_error(
@ -824,7 +824,7 @@ final class Application extends Base
}
$data = @file_get_contents(
$this->_di->get('config')->get('database.json')
$this->_di->get('config')['database.json']
);
if (($data === false)
|| (($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);
}
/**
*
*/
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;
}
//--------------------------------------
/**
*
*/
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
*/

View File

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