PHP Class Elgg\Ajax\Service

Since: 1.12.0
Afficher le fichier Open project: elgg/elgg Class Usage Examples

Méthodes publiques

Méthode Description
__construct ( PluginHooksService $hooks, SystemMessagesService $msgs, Input $input, Elgg\Amd\Config $amdConfig ) Constructor
appendDeps ( string $hook, string $type, Elgg\Services\AjaxResponse $response, array $params ) : Elgg\Services\AjaxResponse Send required AMD modules list back with the response
appendMessages ( string $hook, string $type, Elgg\Services\AjaxResponse $response, array $params ) : Elgg\Services\AjaxResponse Send system messages back with the response
decodeJson ( mixed $string ) : mixed Attempt to JSON decode the given string
getViews ( ) : string[] Returns an array of views allowed for ajax calls
isAjax2Request ( ) : boolean Did the request come from the elgg/Ajax module?
isReady ( ) : boolean Is the service ready to respond to the request?
registerView ( string $view ) : void Register a view to be available for ajax calls
respondFromApiResponse ( Elgg\Services\AjaxResponse $api_response, string $hook_type = '' ) : Symfony\Component\HttpFoundation\JsonResponse Send a JSON HTTP response based on the given API response
respondFromOutput ( mixed $output, string $hook_type = '', boolean $try_decode = true ) : Symfony\Component\HttpFoundation\JsonResponse Send a JSON HTTP response with the given output
respondWithError ( string $msg = '', integer $status = 400 ) : Symfony\Component\HttpFoundation\JsonResponse Send a JSON HTTP 400 response
unregisterView ( string $view ) : void Unregister a view for ajax calls

Private Methods

Méthode Description
buildHttpResponse ( Elgg\Services\AjaxResponse $api_response, boolean $allow_removing_headers = null ) : Symfony\Component\HttpFoundation\JsonResponse Build a JsonResponse based on an API response object
filterApiResponse ( Elgg\Services\AjaxResponse $api_response, string $hook_type = '' ) : Elgg\Services\AjaxResponse Filter an AjaxResponse through a plugin hook

Method Details

__construct() public méthode

Constructor
public __construct ( PluginHooksService $hooks, SystemMessagesService $msgs, Input $input, Elgg\Amd\Config $amdConfig )
$hooks Elgg\PluginHooksService Hooks service
$msgs Elgg\SystemMessagesService System messages service
$input Elgg\Http\Input Input service
$amdConfig Elgg\Amd\Config AMD config

appendDeps() public méthode

Send required AMD modules list back with the response
public appendDeps ( string $hook, string $type, Elgg\Services\AjaxResponse $response, array $params ) : Elgg\Services\AjaxResponse
$hook string "ajax_response"
$type string "all"
$response Elgg\Services\AjaxResponse Ajax response
$params array Hook params
Résultat Elgg\Services\AjaxResponse

appendMessages() public méthode

Send system messages back with the response
public appendMessages ( string $hook, string $type, Elgg\Services\AjaxResponse $response, array $params ) : Elgg\Services\AjaxResponse
$hook string "ajax_response"
$type string "all"
$response Elgg\Services\AjaxResponse Ajax response
$params array Hook params
Résultat Elgg\Services\AjaxResponse

decodeJson() public méthode

Attempt to JSON decode the given string
public decodeJson ( mixed $string ) : mixed
$string mixed Output string
Résultat mixed

getViews() public méthode

Returns an array of views allowed for ajax calls
public getViews ( ) : string[]
Résultat string[]

isAjax2Request() public méthode

Did the request come from the elgg/Ajax module?
public isAjax2Request ( ) : boolean
Résultat boolean

isReady() public méthode

Some code paths involve multiple layers of handling (e.g. router calls actions/ajax views) so we must check whether the response has already been sent to avoid sending it twice. We can't use headers_sent() because Router needs to use output buffering.
public isReady ( ) : boolean
Résultat boolean

registerView() public méthode

Register a view to be available for ajax calls
public registerView ( string $view ) : void
$view string The view name
Résultat void

respondFromApiResponse() public méthode

Send a JSON HTTP response based on the given API response
public respondFromApiResponse ( Elgg\Services\AjaxResponse $api_response, string $hook_type = '' ) : Symfony\Component\HttpFoundation\JsonResponse
$api_response Elgg\Services\AjaxResponse API response
$hook_type string The hook type. If given, the response will be filtered by hook
Résultat Symfony\Component\HttpFoundation\JsonResponse

respondFromOutput() public méthode

Send a JSON HTTP response with the given output
public respondFromOutput ( mixed $output, string $hook_type = '', boolean $try_decode = true ) : Symfony\Component\HttpFoundation\JsonResponse
$output mixed Output from a page/action handler
$hook_type string The hook type. If given, the response will be filtered by hook
$try_decode boolean Try to convert a JSON string back to an abject
Résultat Symfony\Component\HttpFoundation\JsonResponse

respondWithError() public méthode

Send a JSON HTTP 400 response
public respondWithError ( string $msg = '', integer $status = 400 ) : Symfony\Component\HttpFoundation\JsonResponse
$msg string The error message (not displayed to the user)
$status integer The HTTP status code
Résultat Symfony\Component\HttpFoundation\JsonResponse

unregisterView() public méthode

Unregister a view for ajax calls
public unregisterView ( string $view ) : void
$view string The view name
Résultat void