. */ namespace SP\Modules\Api\Controllers\Client; use Exception; use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; use SP\DataModel\ItemSearchData; use SP\Domain\Api\Services\ApiResponse; /** * Class SearchController */ final class SearchController extends ClientBase { /** * searchAction */ public function searchAction(): void { try { $this->setupApi(ActionsInterface::CLIENT_SEARCH); $itemSearchData = $this->buildSearchData(); $this->eventDispatcher->notify('search.client', new Event($this)); $this->returnResponse( ApiResponse::makeSuccess( $this->clientService->search($itemSearchData)->getDataAsArray() ) ); } catch (Exception $e) { processException($e); $this->returnResponseException($e); } } /** * @return \SP\DataModel\ItemSearchData * @throws \SP\Domain\Common\Services\ServiceException */ private function buildSearchData(): ItemSearchData { $itemSearchData = new ItemSearchData(); $itemSearchData->setSeachString($this->apiService->getParamString('text')); $itemSearchData->setLimitCount( $this->apiService->getParamInt('count', false, self::SEARCH_COUNT_ITEMS) ); return $itemSearchData; } }