You are browsing the documentation for iTop 3.0 which is not the current version.

Consider browsing to iTop 3.2 documentation

šŸ”™ Back

RestUtils

api

Helpers for implementing REST services

API synthesis

List of the public API methods. When manipulating RestUtils, You can call those methods:

  • FindObjectFromKey() ā€” Find an object from a polymorph search specification (Rest/Json)
  • GetClass() ā€” Read a class from a Rest/Json structure.
  • GetFieldList() ā€” Read a list of attribute codes from a Rest/Json structure.
  • GetMandatoryParam() ā€” Read a mandatory parameter from from a Rest/Json structure.
  • GetOptionalParam() ā€” Read an optional parameter from from a Rest/Json structure.
  • InitTrackingComment() ā€” Registering tracking information. Any further object modification be associated with the given comment, when the modification getsrecorded into the DB
  • MakeObjectFromFields() ā€” Interpret a Rest/Json structure that defines attribute values, and build an object
  • MakeValue() ā€” Interpret the Rest/Json value and get a valid attribute value
  • UpdateObjectFromFields() ā€” Interpret a Rest/Json structure that defines attribute values, and update the given object

Public methods

FindObjectFromKey

api public static

Find an object from a polymorph search specification (Rest/Json)
public static FindObjectFromKey($sClass, $key, $bAllowNullValue = false)

Parameters

types name default description
string $sClass Name of the class
mixed $key Either search criteria (substructure), or an object or an OQL string.
boolean $bAllowNullValue false Allow the cases such as key = 0 or key = {null} and return null then

Returns

\DBObject The object found

Throws

\Exception If the input structure is not valid or it could not find exactly one object

GetClass

api public static

Read a class from a Rest/Json structure.
public static GetClass($oData, $sParamName)

Parameters

types name default description
\StdClass $oData Structured input data. Must contain the entry defined by sParamName.
string $sParamName Name of the parameter to fetch from the input data

Returns

string

Throws

\Exception If the parameter is missing or the class is unknown

GetFieldList

api public static

Read a list of attribute codes from a Rest/Json structure.
public static GetFieldList($sClass, $oData, $sParamName)

Parameters

types name default description
string $sClass Name of the class
\StdClass $oData Structured input data.
string $sParamName Name of the parameter to fetch from the input data

Returns

array of class => list of attributes (see RestResultWithObjects::AddObject that uses it)

Throws

\Exception

GetMandatoryParam

api public static

Read a mandatory parameter from from a Rest/Json structure.
public static GetMandatoryParam($oData, $sParamName)

Parameters

types name default description
\StdClass $oData Structured input data. Must contain the entry defined by sParamName.
string $sParamName Name of the parameter to fetch from the input data

Returns

mixed parameter value if present

Throws

\Exception If the parameter is missing

GetOptionalParam

api public static

Read an optional parameter from from a Rest/Json structure.
public static GetOptionalParam($oData, $sParamName, $default)

Parameters

types name default description
\StdClass $oData Structured input data.
string $sParamName Name of the parameter to fetch from the input data
mixed $default Default value if the parameter is not found in the input data

Returns

mixed

Throws

\Exception

InitTrackingComment

api public static

Registering tracking information. Any further object modification be associated with the given comment, when the modification getsrecorded into the DB
public static InitTrackingComment($oData)

Parameters

types name default description
\StdClass $oData Structured input data. Must contain 'comment'.

Throws

\Exception

MakeObjectFromFields

api public static

Interpret a Rest/Json structure that defines attribute values, and build an object
public static MakeObjectFromFields($sClass, $aFields)

Parameters

types name default description
string $sClass Name of the class
array $aFields A hash of attribute code ā‡’ value specification.

Returns

\DBObject The newly created object

Throws

\Exception If the specification of the values is not valid

MakeValue

api public static

Interpret the Rest/Json value and get a valid attribute value
public static MakeValue($sClass, $sAttCode, $value)

Parameters

types name default description
string $sClass Name of the class
string $sAttCode Attribute code
mixed $value Depending on the type of attribute (a scalar, or search criteria, or list of related objectsā€¦)

Returns

mixed The value that can be used with DBObject::Set()

Throws

\Exception If the specification of the value is not valid.

UpdateObjectFromFields

api public static

Interpret a Rest/Json structure that defines attribute values, and update the given object
public static UpdateObjectFromFields($oObject, $aFields)

Parameters

types name default description
\DBObject $oObject The object being modified
array $aFields A hash of attribute code ā‡’ value specification.

Returns

\DBObject The object modified

Throws

\Exception If the specification of the values is not valid

šŸ”™ Back

3_0_0/customization/api/extensions/restutils.txt Ā· Last modified: 2022/03/09 14:55 by 127.0.0.1
Back to top
Contact us