Antidot PHP API  version 0.16.0
##PHP API to simplify integration of Antidot components
 All Classes Files Functions Variables Groups Pages
Public Member Functions | List of all members
AfsJsonClientDataHelper Class Reference

Helper for client data in JSON format. More...

Inheritance diagram for AfsJsonClientDataHelper:
AfsClientDataHelperBase AfsClientDataHelperInterface AfsHelperBase

Public Member Functions

 __construct ($client_data)
 Construct new instance of JSON helper.
 get_value ($path=null, $unused=array(), $visitor=null)
 Retrieves text from JSON content.
 get_values ($name=null, $unused=array(), $visitor=null)
 Same result as get_value method.
 get_nodes ($jpath=null, $unused=array())
 Retrieves full client data node (not only text)
 get_node ($jpath=null, $unused=array())
 Retrieves full client data node (not only text)
 get_mime_type ()
 Retrieve client data's mime type.
- Public Member Functions inherited from AfsClientDataHelperBase
 get_id ()
 Retrieve client data id.
- Public Member Functions inherited from AfsHelperBase
 __get ($name)
 Simple property helper.

Detailed Description

Helper for client data in JSON format.

Constructor & Destructor Documentation

__construct (   $client_data)

Construct new instance of JSON helper.

Parameters
$client_data[in] input data used to initialize the instance.

Reimplemented from AfsClientDataHelperBase.

Member Function Documentation

get_mime_type ( )

Retrieve client data's mime type.

Returns
application/json mime type.

Implements AfsClientDataHelperInterface.

get_node (   $jpath = null,
  $unused = array() 
)

Retrieves full client data node (not only text)

Parameters
$jpath[in] node name to be extracted
$context[in] context used for looking for node with specified name.
Returns
first occurrence of node as array (node format like json_decode in array mode)
Exceptions
AfsNoResultException

Implements AfsClientDataHelperInterface.

get_nodes (   $jpath = null,
  $unused = array() 
)

Retrieves full client data node (not only text)

Parameters
$jpath[in] node name to be extracted
$context[in] context used for looking for node with specified name.
Returns
all matching nodes as array (each node format like json_decode in array mode)
Exceptions
AfsNoResultException

Implements AfsClientDataHelperInterface.

get_value (   $path = null,
  $unused = array(),
  $visitor = null 
)

Retrieves text from JSON content.

Parameters
$name[in] name of the first element to retrieve (default=null, all JSON content is returned as text). Empty string allows to retrieve text content correctly formatted when highlight is activated.
$unusedHum...
$visitor[in] instance of AfsTextVisitorInterface used to format appropriately text content when highlight has been activated (default=null, AfsTextVisitor is used).
Returns
formatted text.
Exceptions
AfsNoResultExceptionwhen required JSON element is not defined.
Example with name=null:
Input JSON client data:
    {
        "clientData": [
            {
                "contents": { "data": [ "afs:t": "KwicString", "text": "some text" ] },
                "id": "data1",
                "mimeType": "application/json"
            }
        ]
    }
Call to get_text(null) will return
{"data":["afs:t":"KwicString","text":"some text"]}
.
Example with name='data':
Same input JSON as previous example:
    {
        "clientData": [
            {
                "contents": { "data": [ "afs:t": "KwicString", "text": "some text" ] },
                "id": "data1",
                "mimeType": "application/json"
            }
        ]
    }
Call to get_text('data') will return
some text 
.
Example with name='':
Client data is a simple text:
 *  {
        "clientData": [
            {
                "contents": [ { "afs:t": "KwicString", "text": "some text" } ],
                "id": "data1",
                "mimeType": "application/json"
            }
        ]
    }
Call to get_text('') will return
some text 
.

Implements AfsClientDataHelperInterface.

get_values (   $name = null,
  $unused = array(),
  $visitor = null 
)

Same result as get_value method.

Parameters
$name[in] name of the first element to retrieve (default=null, all JSON content is returned as text). Empty string allows to retrieve text content correctly formatted when highlight is activated.
$unusedHum...
$visitor[in] instance of AfsTextVisitorInterface used to format appropriately text content when highlight has been activated (default=null, AfsTextVisitor is used).
Returns
formatted text.
Exceptions
AfsNoResultExceptionwhen required JSON element is not defined.

Implements AfsClientDataHelperInterface.