\Nano4\DataContainer

Data Object -- Base class for all Nano4\Data classes.

These are "magic" objects which are meant for converting data between different formats easily, with PHP arrays, JSON and XML as the default targets.

The load() method, which can be used in the constructor, will determine the data type either by a 'type' parameter passed to it, or by calling the detect_datatype() method (a default version is supplied, feel free to override it, or create chains using parent:: calls.) when the type has been determined, the data will be passed to a method called load$type() which will be used to load the data.

It is expected that custom methods to perform operations on the data will be added, as well as operations to return the data in specific formats (typically the same ones that you accept in the load() statement.)

The default version can load PHP arrays, plus JSON and YAML strings. It also has to_array(), to_json() and to_yaml() methods to return in those formats. The JSON and YAML methods wrap around the array ones, so overriding the array methods is all you really need to do. The default versions perform no transformations, but simply set our data to the PHP array result.

This will also detect SimpleXML and DOM objects, and XML strings. In order to load any of the above objects, you need to implement the load_simple_xml() method (XML strings and DOM objects will be converted to SimpleXMLElement objects and passed through.)

In order to use the to_dom_document(), to_dom_element() or to_xml() methods you must implement a to_simple_xml() method first (again for simplicity we call to_simple_xml() then convert the object it return to the desired format.)

Add extra formats as desired, chaining the detect_data_type() and detect_string_type() methods is easy, so go crazy!

Summary

Methods
Properties
Constants
append()
insert()
swap()
current()
key()
next()
rewind()
valid()
offsetExists()
offsetGet()
offsetSet()
offsetUnset()
count()
is()
__get()
__isset()
__unset()
__set()
array_keys()
__construct()
parent()
load_data()
load()
clear()
spawn()
load_array()
load_json()
load_yaml()
to_array()
jsonSerialize()
to_json()
to_yaml()
load_simple_xml()
to_simple_xml()
load_xml_string()
load_dom_node()
to_dom_element()
to_dom_document()
to_xml()
get_classname()
get_namespace()
get_parent()
position_of()
at_position()
get_data_index()
get_itemclass()
find()
newItem()
addItem()
No public properties found
No constants found
__construct_data()
detect_data_type()
detect_string_type()
get_simple_xml_element()
add_data_index()
$parent
$data
$newconst
$constprops
$save_opts
$data_opts
$data_itemclass
$data_index
$data_allow_null
N/A
No private methods found
No private properties found
N/A

Properties

$parent

$parent : 

Type

$data

$data : 

Type

$newconst

$newconst : 

Type

$constprops

$constprops : 

Type

$save_opts

$save_opts : 

Type

$data_opts

$data_opts : 

Type

$data_itemclass

$data_itemclass : 

Type

$data_index

$data_index : 

Type

$data_allow_null

$data_allow_null : 

Type

Methods

append()

append(  $item,   $indexname = Null) 

Parameters

$item
$indexname

insert()

insert(  $item,   $pos,   $indexname = Null) 

Parameters

$item
$pos
$indexname

swap()

swap(  $pos1,   $pos2) 

Parameters

$pos1
$pos2

current()

current() 

key()

key() 

next()

next() 

rewind()

rewind() 

valid()

valid() 

offsetExists()

offsetExists(  $offset) 

Parameters

$offset

offsetGet()

offsetGet(  $offset) 

Parameters

$offset

offsetSet()

offsetSet(  $offset,   $value) 

Parameters

$offset
$value

offsetUnset()

offsetUnset(  $offset) 

Parameters

$offset

count()

count() 

is()

is(  $key) 

Parameters

$key

__get()

__get(  $name) 

Parameters

$name

__isset()

__isset(  $name) 

Parameters

$name

__unset()

__unset(  $name) 

Parameters

$name

__set()

__set(  $name,   $value) 

Parameters

$name
$value

array_keys()

array_keys() 

__construct()

__construct(  $mixed = Null,   $opts = Null) 

The public constructor. The default version simply forwards to the internal method, see below.

Parameters

$mixed
$opts

parent()

parent() 

load_data()

load_data(  $data,   $opts = array()) 

Parameters

$data
$opts

load()

load(  $data,   $opts = array()) 

Parameters

$data
$opts

clear()

clear(  $opts = array()) 

Parameters

$opts

spawn()

spawn(  $opts = array()) 

Parameters

$opts

load_array()

load_array(  $array,   $opts = array()) 

Parameters

$array
$opts

load_json()

load_json(  $json,   $opts = Null) 

Parameters

$json
$opts

load_yaml()

load_yaml(  $yaml,   $opts = Null) 

Parameters

$yaml
$opts

to_array()

to_array(  $opts = array()) 

Parameters

$opts

jsonSerialize()

jsonSerialize() 

to_json()

to_json(  $opts = Null) 

Parameters

$opts

to_yaml()

to_yaml(  $opts = Null) 

Parameters

$opts

load_simple_xml()

load_simple_xml(  $simplexml,   $opts = Null) 

Parameters

$simplexml
$opts

to_simple_xml()

to_simple_xml(  $opts = Null) 

Parameters

$opts

load_xml_string()

load_xml_string(  $string,   $opts = Null) 

Parameters

$string
$opts

load_dom_node()

load_dom_node(  $dom,   $opts = Null) 

Parameters

$dom
$opts

to_dom_element()

to_dom_element(  $opts = Null) 

Parameters

$opts

to_dom_document()

to_dom_document(  $opts = Null) 

Parameters

$opts

to_xml()

to_xml(  $opts = Null) 

Parameters

$opts

get_classname()

get_classname(  $object = Null) 

Parameters

$object

get_namespace()

get_namespace(  $object = Null) 

Parameters

$object

get_parent()

get_parent(  $class = Null) 

Get either our parent class, or a parent class in our heirarchy with a given classname (as returned by get_classname(), so no Namespaces.)

Parameters

$class

position_of()

position_of(  $item) 

Parameters

$item

at_position()

at_position(  $offset) 

Parameters

$offset

get_data_index()

get_data_index(  $key) 

Parameters

$key

get_itemclass()

get_itemclass() 

find()

find(  $query,   $single = False,   $spawn = True) 

Parameters

$query
$single
$spawn

newItem()

newItem(mixed  $data = Null, array  $opts = array()) : mixed

Create a new child item, and return it.

Parameters

mixed $data

Data to build object from (optional.)

array $opts

Options to build object with (optional.)

Returns

mixed —

Either a child Item, or Null on failure.

addItem()

addItem(integer  $pos = Null, mixed  $data = Null, array  $opts = array()) 

Create a new child item, and add it to our data.

Parameters

integer $pos

Position to insert at. -1 = End, 0 = Beginning. Optional, defaults to -1 if not specified.

mixed $data

Optional -- passed to newItem().

array $opts

Optional -- passed to newItem().

__construct_data()

__construct_data(  $mixed = Null,   $opts = Null) 

Internal constructor method.

Supports two forms, the original form has the data as the first parameter, and a set of options as the second.

The second form sends the options as the first parameter, with a named 'data' option to specify the data. In this case, the second parameter should be left off.

Parameters

$mixed
$opts

detect_data_type()

detect_data_type(  $data) 

Parameters

$data

detect_string_type()

detect_string_type(  $string) 

Parameters

$string

get_simple_xml_element()

get_simple_xml_element(  $opts) 

Parameters

$opts

add_data_index()

add_data_index(  $item,   $indexname = Null) 

Parameters

$item
$indexname