Hallo all!
Ich habe ein Array in folgender Form vorliegen.
Code:
Array
(
[resources] => Array
(
[db] => Array
(
[class] => PDO
[adapter] => mysql
[host] => localhost
[user] => root
[pwd] => null
[dbname] => wendt
[charset] => utf8
)
[files] => Array
(
[images] => public/images/
)
[plugins] => Array
(
[acl] => Acl
[auth] => Auth
)
)
[languages] => Array
(
[de] => de
[en] => en
[fr] => fr
)
)
Dieses merhdimensionale Array möchte ich nun zu einem Objekt konvertieren.
Mein Ziel ist es dann so etwas zu haben.
PHP-Code:
$config->resources->db->class;
Hier meine Config.php Klasse. Die ist noch nicht fertig da kommt noch bisschen was dazu, es geht nur um den Teil hier bzw. das Problem.
PHP-Code:
<?php
require_once LIB_PATH . 'Config/ConfigException.php';
class Config
{
protected $_file;
protected $_config;
protected $_configClass;
protected $_data = array();
protected $_configPath;
public function __construct($pPath, $value = null)
{
$this->_configPath = $pPath;
$this->_loadConfigFile();
$this->getConfigFile();
$this->getConfigClass();
$array = $this->_configClass->container();
foreach($array as $key => $value) {
if(is_array($value)) {
$this->_data[$key] = new self($this->_configPath, $value);
// $this->_data[$key] = $value;
}
else {
$this->_data[$key] = $value;
}
}
//echo '<pre>';
// print_r($array);
//echo '</pre>';
}
public function __set($name, $value)
{
if(is_array($value)) {
$this->_data[$name] = new self($this->_configPath, $value);
} else {
$this->_data[$name] = $value;
}
}
public function __get($name)
{
return $this->_data[$name];
}
protected function _loadConfigFile()
{
if(is_dir($this->_configPath)) {
try {
if($resource = opendir($this->_configPath)) {
while(($file = readdir($resource)) !== false ) {
if($file != '.' && $file != '..' && $file != 'thumb') {
$this->_file = substr(strrchr($file, '.'), 1);;
}
}
}
} catch(ConfigException $e) {
return $e->getMessage();
}
}
return $this->_file;
}
/**
*
* Gibt eine Configdatei zurück
* @return String
*/
public function getConfigFile()
{
switch($this->_loadConfigFile()) {
case 'xml':
$this->_config = 'xml';
break;
case 'ini':
$this->_config = 'ini';
break;
case 'php':
$this->_config = 'php';
break;
}
return $this->_config;
}
/**
*
* Instanzieren der jeweiligen conig Klasse
* @return ConfigClass
*/
public function getConfigClass()
{
$class = 'Config' . ucfirst($this->getConfigFile());
require_once LIB_PATH . 'Config/' . $class . '.php';
$this->_configClass = new $class(APPLICATION_PATH . 'config/config.' . $this->getConfigFile());
$this->_configClass->config();
return $this->_configClass;
}
}
Der verursachte Fehler ist Folgender.
Zitat:
|
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 261904 bytes) in D:\Softwareentwicklung\Webentwicklung\WendtNeu\classes\Config\Config.php on line 15
|
Könnt ihr mir weiter helfen? Vielen Dank für eure Zeit und Hilfe.
Gruß der Litter