*/ /** * patConfiguration writer for PHP files * * used by the patConfiguration object to write PHP config files * * $Id: PHP.php,v 1.1 2004/02/29 16:56:46 schst Exp $ * * @package patConfiguration * @subpackage Writer * @author Stephan Schmidt */ class patConfiguration_Writer_PHP extends patConfiguration_Writer { /** * create a php representation of the current config * * @access public * @param array $config config to serialize * @param array $options options for the serialization * @return string $content php representation */ function serializeConfig( $config, $options ) { $varname = isset( $options["varname"] ) ? $options["varname"] : "config"; ksort( $config ); reset( $config ); $php = "configObj->systemVars["appVersion"]."\n"; $php .= " * (c) ".implode( ",", $this->configObj->systemVars["author"] )."\n"; $php .= " * download at http://www.php-tools.net\n"; $php .= " * generated on " . date( "Y-m-d H:i:s", time() ) . "\n"; $php .= " */\n\n"; $php .= "\$".$varname." = array();\n"; while( list( $key, $value ) = each( $config ) ) { $php .= $this->getPHPConfigLine( "\$".$varname."[\"".$key."\"]", $value ); } $php .= "?>"; return $php; } /** * build one line in the php config file * * @access private * @param string $prefix variable name and array index * @param mixed $value value of the config option * @return string $line on line of php code */ function getPHPConfigLine( $prefix, $value ) { if( is_bool( $value ) ) $value = $value ? "true" : "false"; elseif( is_string( $value ) ) $value = "\"".addslashes( $value )."\""; if( is_array( $value ) ) { $line = $prefix." = array();\n";; reset( $value ); while( list( $key, $val ) = each( $value ) ) { if( !is_int( $key ) ) $key = "\"".$key."\""; $line .= $this->getPHPConfigLine( $prefix."[".$key."]", $val ); } return $line; } else return $prefix." = ".$value.";\n"; } } ?>