PHP 클래스 API, glpi

저자: : Tracy Lauren for Heimdall Networks April, 2012
파일 보기 프로젝트 열기: glpi-project/glpi 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$api_url

보호된 프로퍼티들

프로퍼티 타입 설명
$apiclients_id
$app_tokens
$format
$ipnum
$iptxt
$session_write permit writing to $_SESSION

공개 메소드들

메소드 설명
__construct ( )
call ( ) first function used on api call
getHatoasClasses ( $itemtype ) : array retrieve all child class for itemtype parameter
inlineDocumentation ( $file ) Display the API Documentation in Html (parsed from markdown)
messageBadArrayError ( $return_error = true ) Send 400 error to client
messageLostError ( $return_error = true ) Send 405 error to client
messageNotfoundError ( $return_error = true ) Send 404 error to client
messageRightError ( $return_error = true ) Send 401 error to client
messageSessionError ( $return_error = true ) Session Token KO
messageSessionTokenMissing ( $return_error = true ) Session Token missing
returnError ( $message = "Bad Request", $httpcode = 400, $statuscode = "ERROR", $docmessage = true, $return_response = true ) Generic function to send a error message and an error code to client

보호된 메소드들

메소드 설명
arrayRightError ( ) Fill a sub array with a right error
changeActiveEntities ( $params = [] ) : boolean Change active entity to the entities_id one.
changeActiveProfile ( $params = [] ) : boolean set a profile to active
checkSessionToken ( ) : boolean Check that the session_token is provided and match to a valid php session
cors ( $verb = 'GET' )
createItems ( $itemtype, $params = [] ) : array Add an object to GLPI
deleteItems ( $itemtype, $params = [] ) : boolean delete one or more objects in GLPI
getActiveEntities ( ) : array return active entities of current logged user
getActiveProfile ( ) : integer return the current active profile
getFullSession ( ) : array return the current php $_SESSION
getGlpiConfig ( ) : array return the current $CFG_GLPI
getItem ( $itemtype, $id, $params = [] ) : array Return the instance fields of itemtype identified by id
getItems ( $itemtype, $params = [], &$totalcount ) : array Return a collection of rows of the desired itemtype
getMultipleItems ( $params = [] ) : array Return a collection of items queried in input ($items)
getMyEntities ( ) : array return all the possible entity of the current logged user (and for current active profile)
getMyProfiles ( ) : array Return all the profiles associated to logged user
header ( $html = false, $title = "" ) Show API header in debug, it add body and some libs (essentialy to colorise markdown) otherwise, it change only Content-Type of the page
initSession ( $params = [] ) : array Init GLPI Session
killSession ( ) : boolean Kill GLPI Session Use 'session_token' param in $this->parameters
listSearchOptions ( $itemtype, $params = [] ) : array List the searchoptions of provided itemtype. To use with searchItems function
parseDropdowns ( $fields, $params = [] ) : array transform array of fields passed in parameter : change value from integer id to string name of foreign key You can pass an array of array, this method is recursive.
parseIncomingParams ( ) needed to transform params of called api in $this->parameters attribute
retrieveSession ( ) Retrieve GLPI Session initialised by initSession function Use 'session_token' param in $this->parameters
returnResponse ( $response, $code, $additionalheaders ) generic messages
searchItems ( $itemtype, $params = [] ) : Array Expose the GLPI searchEngine
showDebug ( ) Show API Debug
updateItems ( $itemtype, $params = [] ) : array update an object to GLPI

비공개 메소드들

메소드 설명
checkAppToken ( ) check if the app_toke in case of config ask to
getGlpiLastMessage ( ) : array Get last message added in $_SESSION by Session::addMessageAfterRedirect
getSearchOptionUniqID ( $itemtype, $option = [] ) : string Generate an unique id of a searchoption based on: - itemtype - linkfield - joinparams - field
getSearchOptionUniqIDJoins ( $option ) : array Generate subpart of a unique id of a search option with parsing joinparams recursively
initEndpoint ( $unlock_session = true, $endpoint = "" ) Function called by each commun function of the api.
inputObjectToArray ( mixed $input ) : array Transform all stdobject retrieved from a json_decode into arrays
logEndpointUsage ( $endpoint = "" ) Log usage of the api into glpi historical or log files (defined by api config) It stores the ip and the username of the current session.
unlockSessionIfPossible ( ) Unlock the current session (readonly) to permit concurrent call

메소드 상세

__construct() 공개 메소드

public __construct ( )

arrayRightError() 보호된 메소드

Fill a sub array with a right error
protected arrayRightError ( )

call() 추상적인 공개 메소드

first function used on api call
abstract public call ( )

changeActiveEntities() 보호된 메소드

Change active entity to the entities_id one.
protected changeActiveEntities ( $params = [] ) : boolean
$params array with theses options : - 'entities_id': (default 'all') ID of the new active entity ("all" = load all possible entities). Optionnal - 'is_recursive': (default false) Also display sub entities of the active entity. Optionnal
리턴 boolean

changeActiveProfile() 보호된 메소드

set a profile to active
protected changeActiveProfile ( $params = [] ) : boolean
$params with theses options : - profiles_id : identifier of profile to set
리턴 boolean

checkSessionToken() 보호된 메소드

Check that the session_token is provided and match to a valid php session
protected checkSessionToken ( ) : boolean
리턴 boolean

cors() 보호된 메소드

protected cors ( $verb = 'GET' )

createItems() 보호된 메소드

Add an object to GLPI
protected createItems ( $itemtype, $params = [] ) : array
$itemtype string itemtype (class) of object
$params array with theses options : - 'input' : object with fields of itemtype to be inserted. You can add several items in one action by passing array of input object. Mandatory.
리턴 array of id

deleteItems() 보호된 메소드

delete one or more objects in GLPI
protected deleteItems ( $itemtype, $params = [] ) : boolean
$itemtype string itemtype (class) of object
$params array with theses options : - 'input' : Array of objects with fields of itemtype to be updated. Mandatory. You must provide in each object a key named 'id' to identify item to delete.* - 'force_purge' : boolean, if itemtype have a dustbin, you can force purge (delete finally). Optionnal. - 'history' : boolean, default true, false to disable saving of deletion in global history. Optionnal.
리턴 boolean or array of boolean

getActiveEntities() 보호된 메소드

return active entities of current logged user
protected getActiveEntities ( ) : array
리턴 array with 3 keys : - active_entity : current set entity - active_entity_recursive : boolean, if we see sons of this entity - active_entities : array all active entities (active_entity and its sons)

getActiveProfile() 보호된 메소드

return the current active profile
protected getActiveProfile ( ) : integer
리턴 integer the profiles_id

getFullSession() 보호된 메소드

return the current php $_SESSION
protected getFullSession ( ) : array
리턴 array

getGlpiConfig() 보호된 메소드

return the current $CFG_GLPI
protected getGlpiConfig ( ) : array
리턴 array

getHatoasClasses() 정적인 공개 메소드

retrieve all child class for itemtype parameter
static public getHatoasClasses ( $itemtype ) : array
$itemtype string
리턴 array child classes

getItem() 보호된 메소드

Return the instance fields of itemtype identified by id
protected getItem ( $itemtype, $id, $params = [] ) : array
$itemtype string itemtype (class) of object
$id integer identifier of object
$params array with theses options : - 'expand_dropdowns': Show dropdown's names instead of id. default: false. Optionnal - 'get_hateoas': Show relation of current item in a links attribute. default: true. Optionnal - 'get_sha1': Get a sha1 signature instead of the full answer. default: false. Optionnal - 'with_components': Only for [Computer, NetworkEquipment, Peripheral, Phone, Printer], Optionnal. - 'with_disks': Only for Computer, retrieve the associated filesystems. Optionnal. - 'with_softwares': Only for Computer, retrieve the associated softwares installations. Optionnal. - 'with_connections': Only for Computer, retrieve the associated direct connections (like peripherals and printers) .Optionnal. - 'with_networkports':Retrieve all network connections and advanced network informations. Optionnal. - 'with_infocoms': Retrieve financial and administrative informations. Optionnal. - 'with_contracts': Retrieve associated contracts. Optionnal. - 'with_documents': Retrieve associated external documents. Optionnal. - 'with_tickets': Retrieve associated itil tickets. Optionnal. - 'with_problems': Retrieve associated itil problems. Optionnal. - 'with_changes': Retrieve associated itil changes. Optionnal. - 'with_notes': Retrieve Notes (if exists, not all itemtypes have notes). Optionnal. - 'with_logs': Retrieve historical. Optionnal.
리턴 array fields of found object

getItems() 보호된 메소드

Return a collection of rows of the desired itemtype
protected getItems ( $itemtype, $params = [], &$totalcount ) : array
$itemtype string itemtype (class) of object
$params array with theses options : - 'expand_dropdowns' (default: false): show dropdown's names instead of id. Optionnal - 'get_hateoas' (default: true): show relations of items in a links attribute. Optionnal - 'only_id' (default: false): keep only id in fields list. Optionnal - 'range' (default: 0-50): limit the list to start-end attributes - 'sort' (default: id): sort by the field. - 'order' (default: ASC): ASC(ending) or DESC(ending). - 'searchText' (default: NULL): array of filters to pass on the query (with key = field and value the search)
$totalcount integer output parameter who receive the total count of the query resulat. As this function paginate results (with a mysql LIMIT), we can have the full range. (default 0)
리턴 array collection of fields

getMultipleItems() 보호된 메소드

Call self::getItem for each line of $items
protected getMultipleItems ( $params = [] ) : array
$params array with theses options : - items: array containing lines with itemtype and items_id keys Ex: [ [itemtype => 'Ticket', id => 102], [itemtype => 'User', id => 10], [itemtype => 'User', id => 11], ] - 'expand_dropdowns': Show dropdown's names instead of id. default: false. Optionnal - 'get_hateoas': Show relation of current item in a links attribute. default: true. Optionnal - 'get_sha1': Get a sha1 signature instead of the full answer. default: false. Optionnal - 'with_components': Only for [Computer, NetworkEquipment, Peripheral, Phone, Printer], Optionnal. - 'with_disks': Only for Computer, retrieve the associated filesystems. Optionnal. - 'with_softwares': Only for Computer, retrieve the associated softwares installations. Optionnal. - 'with_connections': Only for Computer, retrieve the associated direct connections (like peripherals and printers) .Optionnal. - 'with_networkports': Retrieve all network connections and advanced network informations. Optionnal. - 'with_infocoms': Retrieve financial and administrative informations. Optionnal. - 'with_contracts': Retrieve associated contracts. Optionnal. - 'with_documents': Retrieve associated external documents. Optionnal. - 'with_tickets': Retrieve associated itil tickets. Optionnal. - 'with_problems': Retrieve associated itil problems. Optionnal. - 'with_changes': Retrieve associated itil changes. Optionnal. - 'with_notes': Retrieve Notes (if exists, not all itemtypes have notes). Optionnal. - 'with_logs': Retrieve historical. Optionnal.
리턴 array collection of glpi object's fields

getMyEntities() 보호된 메소드

return all the possible entity of the current logged user (and for current active profile)
protected getMyEntities ( ) : array
리턴 array of entities (with id and name)

getMyProfiles() 보호된 메소드

Return all the profiles associated to logged user
protected getMyProfiles ( ) : array
리턴 array of profiles (with associated rights)

header() 보호된 메소드

Show API header in debug, it add body and some libs (essentialy to colorise markdown) otherwise, it change only Content-Type of the page
protected header ( $html = false, $title = "" )
$html (default false)
$title (default '')

initSession() 보호된 메소드

Init GLPI Session
protected initSession ( $params = [] ) : array
$params array with theses options : - a couple 'name' & 'password' : 2 parameters to login with user auhentication OR - an 'user_token' defined in User Configuration
리턴 array with session_token

inlineDocumentation() 공개 메소드

Display the API Documentation in Html (parsed from markdown)
public inlineDocumentation ( $file )
$file string relative path of documentation file

killSession() 보호된 메소드

Kill GLPI Session Use 'session_token' param in $this->parameters
protected killSession ( ) : boolean
리턴 boolean

listSearchOptions() 보호된 메소드

List the searchoptions of provided itemtype. To use with searchItems function
protected listSearchOptions ( $itemtype, $params = [] ) : array
$itemtype string itemtype (class) of object
$params array
리턴 array all searchoptions of specified itemtype

messageBadArrayError() 공개 메소드

@param $return_error (default true)
public messageBadArrayError ( $return_error = true )

messageLostError() 공개 메소드

@param $return_error (default true)
public messageLostError ( $return_error = true )

messageNotfoundError() 공개 메소드

Send 404 error to client
public messageNotfoundError ( $return_error = true )
$return_error (default true)

messageRightError() 공개 메소드

Send 401 error to client
public messageRightError ( $return_error = true )
$return_error (default true)

messageSessionError() 공개 메소드

@param $return_error (default true)
public messageSessionError ( $return_error = true )

messageSessionTokenMissing() 공개 메소드

@param $return_error (default true)
public messageSessionTokenMissing ( $return_error = true )

parseDropdowns() 보호된 정적인 메소드

transform array of fields passed in parameter : change value from integer id to string name of foreign key You can pass an array of array, this method is recursive.
protected static parseDropdowns ( $fields, $params = [] ) : array
$fields array to check and transform
리턴 array altered $fields

parseIncomingParams() 추상적인 보호된 메소드

needed to transform params of called api in $this->parameters attribute
abstract protected parseIncomingParams ( )

retrieveSession() 보호된 메소드

Retrieve GLPI Session initialised by initSession function Use 'session_token' param in $this->parameters
protected retrieveSession ( )

returnError() 공개 메소드

Generic function to send a error message and an error code to client
public returnError ( $message = "Bad Request", $httpcode = 400, $statuscode = "ERROR", $docmessage = true, $return_response = true )
$message string message to send (human readable)(default 'Bad Request')
$httpcode integer http code (see : https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) (default 400)
$statuscode string API status (to represend more precisely the current error) (default ERROR)
$docmessage boolean if true, add a link to inline document in message (default true)
$return_response boolean if true, the error will be send to returnResponse function (who may exit after sending data), otherwise, we will return an array with the error (default true)

returnResponse() 추상적인 보호된 메소드

generic messages
abstract protected returnResponse ( $response, $code, $additionalheaders )

searchItems() 보호된 메소드

Expose the GLPI searchEngine
protected searchItems ( $itemtype, $params = [] ) : Array
$itemtype string itemtype (class) of object
$params array with theses options : - 'criteria': array of criterion object to filter search. Optionnal. Each criterion object must provide : - link: (optionnal for 1st element) logical operator in [AND, OR, AND NOT, AND NOT]. - field: id of searchoptions. - searchtype: type of search in [contains, equals, notequals, lessthan, morethan, under, notunder]. - value : value to search. - 'metacriteria' (optionnal): array of metacriterion object to filter search. Optionnal. A meta search is a link with another itemtype (ex: Computer with softwares). Each metacriterion object must provide : - link: logical operator in [AND, OR, AND NOT, AND NOT]. Mandatory - itemtype: second itemtype to link. - field: id of searchoptions. - searchtype: type of search in [contains, equals, notequals, lessthan, morethan, under, notunder]. - value : value to search. - 'sort' : id of searchoption to sort by (default 1). Optionnal. - 'order' : ASC - Ascending sort / DESC Descending sort (default ASC). Optionnal. - 'range' : a string with a couple of number for start and end of pagination separated by a '-'. Ex : 150-200. (default 0-50) Optionnal. - 'forcedisplay': array of columns to display (default empty = empty use display pref and search criterias). Some columns will be always presents (1-id, 2-name, 80-Entity). Optionnal. - 'rawdata': boolean for displaying raws data of Search engine of glpi (like sql request, and full searchoptions)
리턴 Array of raw rows from Search class

showDebug() 보호된 메소드

Show API Debug
protected showDebug ( )

updateItems() 보호된 메소드

update an object to GLPI
protected updateItems ( $itemtype, $params = [] ) : array
$itemtype string itemtype (class) of object
$params array with theses options : - 'input' : Array of objects with fields of itemtype to be updated. Mandatory. You must provide in each object a key named 'id' to identify item to update.
리턴 array of boolean

프로퍼티 상세

$api_url 정적으로 공개적으로 프로퍼티

static public $api_url

$apiclients_id 보호되어 있는 프로퍼티

protected $apiclients_id

$app_tokens 보호되어 있는 프로퍼티

protected $app_tokens

$format 보호되어 있는 프로퍼티

protected $format

$ipnum 보호되어 있는 프로퍼티

protected $ipnum

$iptxt 보호되어 있는 프로퍼티

protected $iptxt

$session_write 보호되어 있는 프로퍼티

permit writing to $_SESSION
protected $session_write