>> YANA 4 PHP Framework >> Docs for page config.php

/includes/config.php

Description

Handling of Config- and SML-Files

Functions

Read variables from an encoded string
array decodeConfigString (
string $input, [int $mode = CASE_UPPER]
)
List of parameters:
Name Type Description
$input string
$mode int
Description:

This function is pretty much the same as getConfigFile() except for the fact that it is working on strings rather than files.

Returns NULL on error.

The argument $input has to be a string, that has been encoded using makeConfig().

The argument $mode can be used to decide how keys should be treated.

Valid values for $mode are:

  • CASE_UPPER upper-case all keys
  • CASE_LOWER lower-case all keys
  • CASE_MIXED leave keys in mixed case

Note: to reaccess an encoded value look at the following examples.

Handling boolean values:

  1. $input_bool = true;
  2. $encoded = makeConfig($input_bool, 'MY_VAR');
  3. $decoded = decodeConfigString($encoded);
  4. // the following returns true
  5. $input_bool === $decoded['MY_VAR'];

... or shorter:

  1. $input_bool = true
  2. // the following returns true
  3. $input_bool === array_pop(decodeConfigString(makeConfig($input_bool)));

Handling string values and nummerics:

  1. $input_string = 'foo';
  2. // the following returns true
  3. $input_string === array_pop(decodeConfigString(makeConfig($input_string)));
  4.  
  5. $input_int = 123;
  6. // the following returns true
  7. $input_int == array_pop(decodeConfigString(makeConfig($input_int)));

Handling the 'NULL' value:

  1. $input_null = null;
  2. // the following returns true
  3. is_null( array_pop(decodeConfigString(makeConfig($input_string))) );

Arrays (were key case does matter):

  1. $input_array = array(1,2,3,array(4,5),'a'=>6,'B'=>7);
  2. $output_array = decodeConfigString(makeConfig($input_array,null,CASE_MIXED),CASE_MIXED);
  3. // the following returns true
  4. $input_array == $output_array;

When dealing with nummeric arrays, or associative arrays where all keys are uppercase, or if you just don't care, there is also an ...

... even shorter way to do it:

  1. $input_array = array(1,2,3,array(4,5),'A'=>6,'B'=>7);
  2. $output_array = decodeConfigString(makeConfig($input_array));
  3. // the following returns true
  4. $input_array == $output_array;

  • see: makeconfig()
  • see: getconfigfile()
  • see: importconfigfile()
  • name: decodeconfigstring()
Read a config file and return its contents
array getConfigFile (
array|string $input, [int $mode = CASE_UPPER]
)
List of parameters:
Name Type Description
$input array|string
$mode int
Description:

The argument $input can wether be a filename or a numeric array of strings created by file($filename).

The argument $mode can be used to decide how keys should be treated.

Valid values for $mode are:

  • CASE_UPPER upper-case all keys
  • CASE_LOWER lower-case all keys
  • CASE_MIXED leave keys in mixed case

  • see: makeconfig()
  • see: importconfigfile()
  • name: getconfigfile()
Read a config file and copy its contents to the global scope
void importConfigFile (
string $filename, [mixed $mode = CASE_UPPER], int $mode
)
List of parameters:
Name Type Description
$filename string
$mode int
Description:

The argument $mode can be used to decide how keys should be treated.

Valid values for $mode are:

  • CASE_UPPER upper-case all keys
  • CASE_LOWER lower-case all keys
  • CASE_MIXED leave keys in mixed case

  • see: makeconfig()
  • see: getconfigfile()
  • name: importconfigfile()
Create a config file from scalar variable or array data.
void makeConfig (
mixed $data, [mixed $name = null], [mixed $mode = CASE_UPPER], [mixed $indent = 0], string $filename, int $mode
)
List of parameters:
Name Type Description
$filename string
$mode int
Description:

The argument $name can be used to specify the name of the root node. If $name is omitted, no root node is created.

Note that this function will issue an E_USER_NOTICE if $name is omitted and $data is a scalar value. In this case the scalar variable will be named '0' by default.

The argument $mode can be used to decide how keys should be treated.

Note that any tags from string inputs will be stripped. You should convert tags to entities, before submiting the input.

Valid values for $mode are:

  • CASE_UPPER upper-case all keys
  • CASE_LOWER lower-case all keys
  • CASE_MIXED leave keys in mixed case

  • see: importconfigfile()
  • see: getconfigfile()
  • name: makeconfig()

Documentation generated on Fri, 10 Nov 2006 00:35:53 +0100 by phpDocumentor 1.3.0RC4

yana author: Thomas MeyerHomepage: www.all-community.de/pub