\Hazaar\View\Widgets
JSONObject
A JSON encodable object.

When rendered this object will output a string of JSON code that can be used by any client-side JavaScript code. It supports all data types including arrays, objects, strings, numbers as well as functions.

Tags

Since

1.1

Summary
Methods Properties Constants
add
get
set
No constants
Properties
$properties
$properties
Methods
__construct()
__construct($properties = Array ( ) )

JSON Object Constructor

Parameters

$propertiesarray

Optional array of properties to populate the object with.

add()
add($key, $items) : Hazaar\\Widgets\\JSONObject

Add an item to a property array.

Parameters

$key

No description

$items

No description

Returns

\Hazaar\View\Widgets\Hazaar\\Widgets\\JSONObject
count()
count() : int

Returns the number of properties currently set.

Returns

int
encode()
encode($items, $properties_only = false) : string

Encodes an item or an array of items into an object or array depending on whether the source array is an associative array or numeric array.

Parameters

$itemsmixed

A item or array of items to encode.

$properties_only

No description

Returns

string

A JSON encoded representation of the item(s).

encodeItem()
encodeItem($item) : string

Encode a single item into it’s JSON representation. Supported argument types are: int, float, bool, ViewableObject, null and strings. ViewableObject objects will be rendered (by calling their render() method) and their output used as is.

Parameters

$itemmixed

The item to encode.

Returns

string

The JSON representation of the item.

get()
get($key, $encoded = false) : mixed

Get and existing property. If the property doesn’t exist, null will be returned.

Parameters

$key

No description

$encoded

No description

Returns

mixed

The requested property.

properties()
properties() : array

Returns an array of properties currently set.

Returns

array
renderObject()
renderObject() : string

Render the object into encoded JSON output.

Returns

string
renderProperties()
renderProperties($items = null)

Parameters

$items

No description

set()
set($key, $value, $type = null) : Hazaar\\Widgets\\JSONObject

Set a single property

Parameters

$key

No description

$value

No description

$type

No description

Returns

\Hazaar\View\Widgets\Hazaar\\Widgets\\JSONObject
setFunction()
setFunction($key, $code, $argdef = Array ( ) ) : Hazaar\\Widgets\\JSONObject

Add a JavaScript function to the list of properties. If the $code argument is just a string it will be converted to a JavaScript object.

Parameters

$key

No description

$code

No description

$argdef

No description

Returns

\Hazaar\View\Widgets\Hazaar\\Widgets\\JSONObject