Skip to content

Commit

Permalink
Merge branch '11'
Browse files Browse the repository at this point in the history
  • Loading branch information
ipf committed Jul 26, 2024
2 parents e7f7038 + 08b20ea commit debb44d
Show file tree
Hide file tree
Showing 58 changed files with 264 additions and 257 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,38 @@ jobs:
fail-fast: false
matrix:
env:
- { php: 7.4 }
- { php: 8.0 }
- { php: 8.1 }
- { php: 8.2 }

env: ${{ matrix.env }}

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.env.php }}
tools: composer
tools: composer:2
extensions: pdo, sqlite3

# composer
- name: Update Composer
run: |
sudo composer self-update
composer --version
- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache dependencies
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ~/.composer/cache
key: dependencies-composer-${{ hashFiles('composer.json') }}
key: dependencies-composer-${{ matrix.env.php }}-${{ hashFiles('composer.json') }}

- name: Install dependencies
run: composer install

- name: Check coding style
run: composer lint
if: ${{ matrix.env.php == '8.1' }}

- name: Run Unit Tests
run: |
Expand Down
2 changes: 1 addition & 1 deletion .php-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.4
8.1
89 changes: 51 additions & 38 deletions Classes/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,47 +28,52 @@
*
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
use Subugoe\Find\Service\ServiceProviderInterface;
use Subugoe\Find\Utility\ArrayUtility;
use Subugoe\Find\Utility\FrontendUtility;
use TYPO3\CMS\Core\Log\LogManagerInterface;
use TYPO3\CMS\Core\Page\AssetCollector;
use TYPO3\CMS\Core\Utility\ArrayUtility as CoreArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Http\ForwardResponse;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException;
use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;

class SearchController extends ActionController
{
protected array $requestArguments = [];

protected ?object $searchProvider = null;

private \Psr\Log\LoggerInterface $logger;
private LoggerInterface $logger;

public function __construct(LogManagerInterface $logManager)
{
$this->logger = $logManager->getLogger('find');
}

/**
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws NoSuchArgumentException
* @throws StopActionException
*/
public function detailAction(string $id)
public function detailAction(string $id): ResponseInterface
{
$arguments = $this->searchProvider->getRequestArguments();
$detail = $this->searchProvider->getDocumentById($id);

if ($this->request->hasArgument('underlyingQuery')) {
$underlyingQueryInfo = $this->request->getArgument('underlyingQuery');
$this->response->addAdditionalHeaderData(
FrontendUtility::addQueryInformationAsJavaScript(
$underlyingQueryInfo['q'],
$this->settings,
(int) $underlyingQueryInfo['position'],
$arguments
)
$underlyingQueryScriptTagContent = FrontendUtility::addQueryInformationAsJavaScript(
$underlyingQueryInfo['q'],
$this->settings,
(int) $underlyingQueryInfo['position'],
$arguments
);

GeneralUtility::makeInstance(AssetCollector::class)
->addInlineJavaScript('underlyingQueryVar', $underlyingQueryScriptTagContent, ['type' => 'text/javascript'], ['priority' => true]);
}

$this->addStandardAssignments();
Expand All @@ -78,43 +83,49 @@ public function detailAction(string $id)
'arguments' => $arguments,
'config' => $this->searchProvider->getConfiguration(),
]);

return $this->htmlResponse();
}

/**
* Index Action.
*/
public function indexAction()
public function indexAction(): ResponseInterface
{
if (array_key_exists('id', $this->requestArguments)) {
$this->forward('detail');
} else {
$this->searchProvider->setCounter();
$this->response->addAdditionalHeaderData(
FrontendUtility::addQueryInformationAsJavaScript(
$this->searchProvider->getRequestArguments()['q'],
$this->settings,
null,
$this->searchProvider->getRequestArguments()
)
);
return new ForwardResponse('detail');
}

$this->addStandardAssignments();
$defaultQuery = $this->searchProvider->getDefaultQuery();
$this->searchProvider->setCounter();

$viewValues = [
'arguments' => $this->searchProvider->getRequestArguments(),
'config' => $this->searchProvider->getConfiguration(),
];
$underlyingQueryScriptTagContent = FrontendUtility::addQueryInformationAsJavaScript(
$this->searchProvider->getRequestArguments()['q'] ?? [],
$this->settings,
null,
$this->searchProvider->getRequestArguments()
);

CoreArrayUtility::mergeRecursiveWithOverrule($viewValues, $defaultQuery);
$this->view->assignMultiple($viewValues);
}
GeneralUtility::makeInstance(AssetCollector::class)
->addInlineJavaScript('underlyingQueryVar', $underlyingQueryScriptTagContent, ['type' => 'text/javascript'], ['priority' => true]);

$this->addStandardAssignments();
$defaultQuery = $this->searchProvider->getDefaultQuery();

$viewValues = [
'arguments' => $this->searchProvider->getRequestArguments(),
'config' => $this->searchProvider->getConfiguration(),
];

CoreArrayUtility::mergeRecursiveWithOverrule($viewValues, $defaultQuery);
$this->view->assignMultiple($viewValues);

return $this->htmlResponse();
}

/**
* Initialisation and setup.
*/
protected function initializeAction()
protected function initializeAction(): void
{
ksort($this->settings['queryFields']);

Expand All @@ -131,16 +142,18 @@ protected function initializeAction()
/**
* Suggest/Autocomplete action.
*/
public function suggestAction()
public function suggestAction(): ResponseInterface
{
$results = $this->searchProvider->suggestQuery($this->searchProvider->getRequestArguments());
$this->view->assign('suggestions', $results);

return $this->htmlResponse();
}

/**
* Assigns standard variables to the view.
*/
protected function addStandardAssignments()
protected function addStandardAssignments(): void
{
$this->searchProvider->setConfigurationValue('extendedSearch', $this->searchProvider->isExtendedSearch());
$this->searchProvider->setConfigurationValue(
Expand All @@ -154,7 +167,7 @@ protected function addStandardAssignments()
/**
* @param string $activeConnection
*/
protected function initializeConnection($activeConnection)
protected function initializeConnection($activeConnection): void
{
$connectionConfiguration = $this->settings['connections'][$activeConnection];

Expand Down
8 changes: 1 addition & 7 deletions Classes/Service/AbstractServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,15 @@

abstract class AbstractServiceProvider implements ServiceProviderInterface
{
protected string $connectionName;

/**
* @var LogManagerInterface
*/
protected $logger;

protected array $requestArguments = [];

protected array $settings = [];

public function __construct(string $connectionName, array $settings)
public function __construct(protected string $connectionName, protected array $settings)
{
$this->connectionName = $connectionName;
$this->settings = $settings;
$this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger('find');
}

Expand Down
Loading

0 comments on commit debb44d

Please sign in to comment.