YANA 4 PHP Framework
Docs For Class SML
Simple Markup Language (SML) Files
This is a wrapper-class that may be used to work with *.config and *.sml files.
SML files provide the same semantics and functionality as JSON encoded files, are as easy to read and understand, but they stick with XML-style markup, which is widely used and understood by most people.
Located in /includes/class_sml.php
Object | --InputStream | --SecureInputStream | --SecureFileStream | --SML
Class | Description |
---|---|
ConfigFile | ConfigFile (deprecated) |
SmlFile | SML Files (deprecated, upper-case only) |
StructureFile | database schema file |
Name | Type | Description |
---|---|---|
$filename | string | |
$case_sensitive | int |
Create a new instance of this class. This extends the super class constructor.
Note the additional parameter $case_sensitive. This parameter decides on how to return key names.
It's value can be one of the following constants:
Name | Type | Description |
---|---|---|
$input | string | |
$case_sensitive | int |
This function is pretty much the same as SML::getFile() 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 SML::encode().
The argument $case_sensitive can be used to decide how keys should be treated.
Valid values for $case_sensitive are:
Note: to reaccess an encoded value look at the following examples.
Handling boolean values:
- $input_bool = true;
- // the following returns true
- $input_bool === $decoded['MY_VAR'];
... or shorter:
- $input_bool = true
- // the following returns true
Handling string values and nummerics:
- $input_string = 'foo';
- // the following returns true
-
- $input_int = 123;
- // the following returns true
Handling the 'NULL' value:
- $input_null = null;
- // the following returns true
Arrays (were key case does matter):
- $input_array = array(1,2,3,array(4,5),'a'=>6,'B'=>7);
- // the following returns true
- $input_array == $output_array;
When dealing with nummeric arrays, or associative arrays where all keys should be uppercase, or if you just don't care, you may set the $case_sensitive parameter to CASE_UPPER.
- $input_array = array(1,2,3,array(4,5),'A'=>6,'B'=>7);
- // the following returns true
- $input_array == $output_array;
The obvious advantage of doing so is: you can rely on the writing of keys with no need to care for case-sensitivity.
Name | Type | Description |
---|---|---|
$data | scalar|array|object | |
$name | string | |
$case_sensitive | int | |
$indent |
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 $case_sensitive 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 $case_sensitive are:
Name | Type | Description |
---|---|---|
$key | string | (optional) |
This function has two synopsis:
1st: if parameter $key is provided.
2nd: if parameter $key is missing, == '' or the wildcard '*'.
Redefinition of: InputStream::exists()
Name | Type | Description |
---|---|---|
$key | string | (optional) |
Returns the value at the position specified by $key. If key is the character '*' or empty, than the whole document is returned.
Example: use "foo1.foo2" to get the contents of the "foo2" child tag inside the "foo1" root tag. Or, more technical speaking, to get the "foo2" element of the "foo1" array.
Redefinition of: SecureInputStream::get()
Name | Type | Description |
---|---|---|
$input | array|string | filename or file content |
$case_sensitive | int | CASE_UPPER|CASE_LOWER|CASE_MIXED |
The argument $input can wether be a filename or a numeric array of strings created by file($filename).
The argument $case_sensitive can be used to decide how keys should be treated.
Valid values for $case_sensitive are:
Redefinition of: SecureInputStream::getFileContent()
Name | Type | Description |
---|---|---|
$key | string | adress of data |
Get a value from the file.
Name | Type | Description |
---|---|---|
$array | array |
This merges the current file content with the provided array. New values will replace old ones.
Returns bool(true) on success and bool(false) on error.
Since version 2.9 this function has two synopsis:
The first one merges the current content with the new content, by merging both arrays. Existing elements in the old array get replaced by new ones.
The second sets a new value at the address provided in $key to $value. If the key already exists, it's value gets updated. As an alternative, if you like to be more accurate, you may choose to use SML->setVar(), which offers only the second synopsis.
Redefinition of: SecureFileStream::insert()
Name | Type | Description |
---|---|---|
$key | string | (optional) |
This returns how many elements can be found inside the array at position $key. If $key points to a non-existing value, or an empty array, the function returns 0.
Redefinition of: SecureFileStream::length()
You should always call this before anything else. Returns the file content on success and bool(false) on error.
Redefinition of: SecureInputStream::read()
Name | Type | Description |
---|---|---|
$key | string | (optional) |
Redefinition of: SecureFileStream::remove()
Changes to the file will not be safed unless you explicitely call $configFile->write(). So if you want or need to revert your changes just call $configFile->reset() and all will be fine.
Redefinition of: SecureInputStream::reset()
Name | Type | Description |
---|---|---|
$array | array |
Replaces the file content with the provided array.
Returns bool(true) on success and bool(false) on error.
Name | Type | Description |
---|---|---|
$key | string | adress of old data |
$value | mixed | new data |
Create or update new key / value pair.
Redefinition of: SecureInputStream::toString()
Inherited From SecureFileStream
Inherited From SecureInputStream
Inherited From InputStream
Inherited From Object
Documentation generated on Sun, 11 Mar 2007 15:02:44 +0100 by phpDocumentor 1.3.1