libSmalldb  v0.3
Static Public Member Functions | List of all members
Utils Class Reference

Static Public Member Functions

static template_format ($template, $values, $escaping_function= 'htmlspecialchars')
 
static filename_format ($template, $values)
 
static write_json_file ($filename, $json_array, array $whitelist=null, $json_options=null)
 Encode array to JSON using json_encode, but insert PHP snippet to protect sensitive data. More...
 
static parse_json_file ($filename)
 JSON version of parse_ini_file(). More...
 

Member Function Documentation

static filename_format (   $template,
  $values 
)
static
Todo:
How to invalidate this cache?

Here is the caller graph for this function:

static write_json_file (   $filename,
  $json_array,
array  $whitelist = null,
  $json_options = null 
)
static

Encode array to JSON using json_encode, but insert PHP snippet to protect sensitive data.

If $filename is set, JSON will be written to given file. Otherwise you are expected to store returned string into *.json.php file.

Stop snippet: When JSON file is evaluated as PHP, stop snippet will interrupt evaluation without breaking JSON syntax, only underscore key is appended (and overwritten if exists).

To make sure that whitelisted keys does not contain PHP tags, all occurrences of '<?' are replaced with '<_?' in whitelisted values.

Default $json_options are:

  • PHP >= 5.4: JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
  • PHP < 5.4: JSON_NUMERIC_CHECK

Options JSON_HEX_TAG and JSON_HEX_APOS are disabled, becouse they break PHP snippet.

static parse_json_file (   $filename)
static

JSON version of parse_ini_file().

Throws JsonException on error.

Todo:
Use different exception ?

Here is the caller graph for this function: