[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/webservice/ -> lib.php (summary)

Web services utility functions and classes

Copyright: 2009 Jerome Mouneyrac <[email protected]>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1784 lines (71 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 4 classes

webservice:: (27 methods):
  authenticate_user()
  add_ws_authorised_user()
  remove_ws_authorised_user()
  update_ws_authorised_user()
  get_ws_authorised_users()
  get_ws_authorised_user()
  generate_user_ws_tokens()
  get_user_ws_tokens()
  get_created_by_user_ws_token()
  get_token_by_id()
  delete_user_ws_token()
  delete_service()
  get_user_ws_token()
  get_external_functions()
  get_external_functions_by_enabled_services()
  get_not_associated_external_functions()
  get_service_required_capabilities()
  get_user_capabilities()
  get_missing_capabilities_by_users()
  get_external_service_by_id()
  get_external_service_by_shortname()
  get_external_function_by_id()
  add_external_function_to_service()
  add_external_service()
  update_external_service()
  service_function_exists()
  remove_external_function_from_service()

webservice_access_exception:: (2 methods):
  __construct()
  webservice_protocol_is_enabled()

webservice_test_client_interface:: (1 method):
  simpletest()

webservice_server_interface:: (24 methods):
  run()
  __construct()
  authenticate_user()
  authenticate_by_token()
  set_web_service_call_settings()
  __construct()
  run()
  init_service_class()
  get_virtual_method_code()
  get_phpdoc_type()
  generate_simple_struct_class()
  service_class_method_body()
  cast_objects_to_array()
  init_zend_server()
  parse_request()
  send_headers()
  exception_handler()
  send_error()
  session_cleanup()
  run()
  exception_handler()
  session_cleanup()
  load_function_info()
  execute()


Class: webservice  - X-Ref

General web service library

authenticate_user($token)   X-Ref
Authenticate user (used by download/upload file scripts)

param: string $token
return: array - contains the authenticated user, token and service objects

add_ws_authorised_user($user)   X-Ref
Allow user to call a service

param: stdClass $user a user

remove_ws_authorised_user($user, $serviceid)   X-Ref
Disallow a user to call a service

param: stdClass $user a user
param: int $serviceid

update_ws_authorised_user($user)   X-Ref
Update allowed user settings (ip restriction, valid until...)

param: stdClass $user

get_ws_authorised_users($serviceid)   X-Ref
Return list of allowed users with their options (ip/timecreated / validuntil...)
for a given service

param: int $serviceid the service id to search against
return: array $users

get_ws_authorised_user($serviceid, $userid)   X-Ref
Return an authorised user with their options (ip/timecreated / validuntil...)

param: int $serviceid the service id to search against
param: int $userid the user to search against
return: stdClass

generate_user_ws_tokens($userid)   X-Ref
Generate all tokens of a specific user

param: int $userid user id

get_user_ws_tokens($userid)   X-Ref
Return all tokens of a specific user
+ the service state (enabled/disabled)
+ the authorised user mode (restricted/not restricted)

param: int $userid user id
return: array

get_created_by_user_ws_token($userid, $tokenid)   X-Ref
Return a token that has been created by the user (i.e. to created by an admin)
If no tokens exist an exception is thrown

The returned value is a stdClass:
->id token id
->token
->firstname user firstname
->lastname
->name service name

param: int $userid user id
param: int $tokenid token id
return: stdClass

get_token_by_id($tokenid)   X-Ref
Return a database token record for a token id

param: int $tokenid token id
return: object token

delete_user_ws_token($tokenid)   X-Ref
Delete a token

param: int $tokenid token id

delete_service($serviceid)   X-Ref
Delete a service
Also delete function references and authorised user references.

param: int $serviceid service id

get_user_ws_token($token)   X-Ref
Get a full database token record for a given token value

param: string $token

get_external_functions($serviceids)   X-Ref
Get the functions list of a service list (by id)

param: array $serviceids service ids
return: array of functions

get_external_functions_by_enabled_services($serviceshortnames, $enabledonly = true)   X-Ref
Get the functions of a service list (by shortname). It can return only enabled functions if required.

param: array $serviceshortnames service shortnames
param: bool $enabledonly if true then only return functions for services that have been enabled
return: array functions

get_not_associated_external_functions($serviceid)   X-Ref
Get functions not included in a service

param: int $serviceid service id
return: array functions

get_service_required_capabilities($serviceid)   X-Ref
Get list of required capabilities of a service, sorted by functions
Example of returned value:
Array
(
[moodle_group_create_groups] => Array
(
[0] => moodle/course:managegroups
)

[moodle_enrol_get_enrolled_users] => Array
(
[0] => moodle/site:viewparticipants
[1] => moodle/course:viewparticipants
[2] => moodle/role:review
[3] => moodle/site:accessallgroups
[4] => moodle/course:enrolreview
)
)

param: int $serviceid service id
return: array

get_user_capabilities($userid)   X-Ref
Get user capabilities (with context)
Only useful for documentation purpose
WARNING: do not use this "broken" function. It was created in the goal to display some capabilities
required by users. In theory we should not need to display this kind of information
as the front end does not display it itself. In pratice,
admins would like the info, for more info you can follow: MDL-29962

param: int $userid user id
return: array

get_missing_capabilities_by_users($users, $serviceid)   X-Ref
Get missing user capabilities for a given service
WARNING: do not use this "broken" function. It was created in the goal to display some capabilities
required by users. In theory we should not need to display this kind of information
as the front end does not display it itself. In pratice,
admins would like the info, for more info you can follow: MDL-29962

param: array $users users
param: int $serviceid service id
return: array of missing capabilities, keys being the user ids

get_external_service_by_id($serviceid, $strictness=IGNORE_MISSING)   X-Ref
Get an external service for a given service id

param: int $serviceid service id
param: int $strictness IGNORE_MISSING, MUST_EXIST...
return: stdClass external service

get_external_service_by_shortname($shortname, $strictness=IGNORE_MISSING)   X-Ref
Get an external service for a given shortname

param: string $shortname service shortname
param: int $strictness IGNORE_MISSING, MUST_EXIST...
return: stdClass external service

get_external_function_by_id($functionid, $strictness=IGNORE_MISSING)   X-Ref
Get an external function for a given function id

param: int $functionid function id
param: int $strictness IGNORE_MISSING, MUST_EXIST...
return: stdClass external function

add_external_function_to_service($functionname, $serviceid)   X-Ref
Add a function to a service

param: string $functionname function name
param: int $serviceid service id

add_external_service($service)   X-Ref
Add a service
It generates the timecreated field automatically.

param: stdClass $service
return: serviceid integer

update_external_service($service)   X-Ref
Update a service
It modifies the timemodified automatically.

param: stdClass $service

service_function_exists($functionname, $serviceid)   X-Ref
Test whether an external function is already linked to a service

param: string $functionname function name
param: int $serviceid service id
return: bool true if a matching function exists for the service, else false.

remove_external_function_from_service($functionname, $serviceid)   X-Ref
Remove a function from a service

param: string $functionname function name
param: int $serviceid service id

Class: webservice_access_exception  - X-Ref

Exception indicating access control problem in web service call
This exception should return general errors about web service setup.
Errors related to the user like wrong username/password should not use it,
you should not use this exception if you want to let the client implement
some code logic against an access error.

__construct($debuginfo)   X-Ref
Constructor

param: string $debuginfo the debug info

webservice_protocol_is_enabled($protocol)   X-Ref
Check if a protocol is enabled

param: string $protocol name of WS protocol ('rest', 'soap', 'xmlrpc', 'amf'...)
return: bool true if the protocol is enabled

Interface: webservice_test_client_interface  - X-Ref

Mandatory interface for all test client classes.

simpletest($serverurl, $function, $params)   X-Ref
Execute test client WS request

param: string $serverurl server url (including the token param)
param: string $function web service function name
param: array $params parameters of the web service function
return: mixed

Interface: webservice_server_interface  - X-Ref

Mandatory interface for all web service protocol classes

run()   X-Ref
Process request from client.


__construct($authmethod)   X-Ref
Constructor

param: integer $authmethod authentication method one of WEBSERVICE_AUTHMETHOD_*

authenticate_user()   X-Ref
Authenticate user using username+password or token.
This function sets up $USER global.
It is safe to use has_capability() after this.
This method also verifies user is allowed to use this
server.


authenticate_by_token($tokentype)   X-Ref
User authentication by token

param: string $tokentype token type (EXTERNAL_TOKEN_EMBEDDED or EXTERNAL_TOKEN_PERMANENT)
return: stdClass the authenticated user

set_web_service_call_settings()   X-Ref
Intercept some moodlewssettingXXX $_GET and $_POST parameter
that are related to the web service call and are not the function parameters


__construct($authmethod, $zend_class)   X-Ref
Constructor

param: int $authmethod authentication method - one of WEBSERVICE_AUTHMETHOD_*
param: string $zend_class Name of the zend server class

run()   X-Ref
Process request from client.


init_service_class()   X-Ref
Load virtual class needed for Zend api


get_virtual_method_code($function)   X-Ref
returns virtual method code

param: stdClass $function a record from external_function
return: string PHP code

get_phpdoc_type($keydesc)   X-Ref
No description

generate_simple_struct_class(external_single_structure $structdesc)   X-Ref
Generate 'struct'/'object' type name
Some servers (our Zend ones) parse the phpdoc to know the parameter types.
The purpose to this function is to be overwritten when the common object|struct type are not understood by the server.
See webservice/soap/locallib.php - the SOAP server requires detailed structure)

param: external_single_structure $structdesc the structure for which we generate the phpdoc type
return: string the phpdoc type

service_class_method_body($function, $params)   X-Ref
You can override this function in your child class to add extra code into the dynamically
created service class. For example it is used in the amf server to cast types of parameters and to
cast the return value to the types as specified in the return value description.

param: stdClass $function a record from external_function
param: array $params web service function parameters
return: string body of the method for $function ie. everything within the {} of the method declaration.

cast_objects_to_array($param)   X-Ref
Recursive function to recurse down into a complex variable and convert all
objects to arrays.

param: mixed $param value to cast
return: mixed Cast value

init_zend_server()   X-Ref
Set up zend service class


parse_request()   X-Ref
This method parses the $_POST and $_GET superglobals and looks for
the following information:
1/ user authentication - username+password or token (wsusername, wspassword and wstoken parameters)

return: void

send_headers()   X-Ref
Internal implementation - sending of page headers.


exception_handler($ex)   X-Ref
Specialised exception handler, we can not use the standard one because
it can not just print html to output.

param: exception $ex

send_error($ex=null)   X-Ref
Send the error information to the WS client
formatted as XML document.

param: exception $ex

session_cleanup($exception=null)   X-Ref
Future hook needed for emulated sessions.

param: exception $exception null means normal termination, $exception received when WS call failed

run()   X-Ref
Process request from client.


exception_handler($ex)   X-Ref
Specialised exception handler, we can not use the standard one because
it can not just print html to output.

param: exception $ex

session_cleanup($exception=null)   X-Ref
Future hook needed for emulated sessions.

param: exception $exception null means normal termination, $exception received when WS call failed

load_function_info()   X-Ref
Fetches the function description from database,
verifies user is allowed to use this function and
loads all paremeters and return descriptions.


execute()   X-Ref
Execute previously loaded function using parameters parsed from the request data.




Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1