PHP Класс Elgg\Ajax\Service

С версии: 1.12.0
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__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

Приватные методы

Метод Описание
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

Описание методов

__construct() публичный Метод

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() публичный Метод

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
Результат Elgg\Services\AjaxResponse

appendMessages() публичный Метод

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
Результат Elgg\Services\AjaxResponse

decodeJson() публичный Метод

Attempt to JSON decode the given string
public decodeJson ( mixed $string ) : mixed
$string mixed Output string
Результат mixed

getViews() публичный Метод

Returns an array of views allowed for ajax calls
public getViews ( ) : string[]
Результат string[]

isAjax2Request() публичный Метод

Did the request come from the elgg/Ajax module?
public isAjax2Request ( ) : boolean
Результат boolean

isReady() публичный Метод

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
Результат boolean

registerView() публичный Метод

Register a view to be available for ajax calls
public registerView ( string $view ) : void
$view string The view name
Результат void

respondFromApiResponse() публичный Метод

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
Результат Symfony\Component\HttpFoundation\JsonResponse

respondFromOutput() публичный Метод

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
Результат Symfony\Component\HttpFoundation\JsonResponse

respondWithError() публичный Метод

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
Результат Symfony\Component\HttpFoundation\JsonResponse

unregisterView() публичный Метод

Unregister a view for ajax calls
public unregisterView ( string $view ) : void
$view string The view name
Результат void