Skip to content

Commit

Permalink
Merge pull request #4 from itx-informationssysteme/v12
Browse files Browse the repository at this point in the history
v12
  • Loading branch information
Benjamin Jasper authored Jul 8, 2024
2 parents a67361a + 427f77d commit 0b18903
Show file tree
Hide file tree
Showing 37 changed files with 441 additions and 135 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: publish
on:
workflow_dispatch:
release:
types: [published]
jobs:
publish:
name: Publish new version to TER
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-20.04
env:
TYPO3_EXTENSION_KEY: ${{ secrets.TYPO3_EXTENSION_KEY }}
TYPO3_API_USERNAME: ${{ secrets.TYPO3_API_USERNAME }}
TYPO3_API_PASSWORD: ${{ secrets.TYPO3_API_PASSWORD }}
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Check tag
run: |
if ! [[ ${{ github.ref }} =~ ^refs/tags/[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$ ]]; then
exit 1
fi
- name: Get version
id: get-version
run: echo ::set-output name=version::${GITHUB_REF/refs\/tags\//}

- name: Get comment
id: get-comment
run: |
readonly local comment=$(git tag -n1 -l ${{ steps.get-version.outputs.version }} | sed "s/^[0-9.]*[ ]*//g")
if [[ -z "${comment// }" ]]; then
echo ::set-output name=comment::Released version ${{ steps.get-version.outputs.version }} of ${{ env.TYPO3_EXTENSION_KEY }}
else
echo ::set-output name=comment::$comment
fi
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
extensions: intl, mbstring, json, zip, curl
tools: composer:v2

- name: Install tailor
run: composer global require typo3/tailor --prefer-dist --no-progress --no-suggest

- name: Publish to TER
run:
php ~/.composer/vendor/bin/tailor ter:publish --comment "${{ steps.get-comment.outputs.comment }}" ${{
steps.get-version.outputs.version }}
41 changes: 41 additions & 0 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Static analysis

on:
push:
branches: [main]
pull_request:
branches: [main, v12]

jobs:
phpstan:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- php-version: 8.2
- php-version: 8.3
steps:
- uses: actions/checkout@v2

- id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}-${{ matrix.php-version }}
restore-keys: |
${{ runner.os }}-composer-
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: none
tools: composer:v2

- run:
composer config --no-plugins allow-plugins.typo3/class-alias-loader true && composer config --no-plugins
allow-plugins.typo3/cms-composer-installers true

- run: composer install --no-progress

- run: vendor/bin/phpstan analyse Classes -c phpstan.neon
11 changes: 2 additions & 9 deletions Classes/Builder/FieldBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
use Itx\Typo3GraphQL\Exception\UnsupportedTypeException;
use JetBrains\PhpStorm\ArrayShape;

/** @package Itx\Typo3GraphQL\Builder */
class FieldBuilder
{
private string $name;
Expand Down Expand Up @@ -122,14 +122,7 @@ public function getType(): ?Type
* @return array<string, mixed>
* @throws UnsupportedTypeException
*/
#[ArrayShape([
'args' => "\mixed[][]|null",
'name' => "string",
'description' => "null|string",
'deprecationReason' => "null|string",
'resolve' => "callable",
'type' => Type::class,
])] public function build(): array
public function build(): array
{
if ($this->type === null) {
throw new UnsupportedTypeException('Type must be set', 1589716096);
Expand Down
11 changes: 2 additions & 9 deletions Classes/EventListener/AfterTcaEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,19 @@

class AfterTcaEventListener
{
protected ConfigurationService $configurationService;

public function __construct(ConfigurationService $configurationService)
{
$this->configurationService = $configurationService;
}

public function __invoke(AfterTcaCompilationEvent $event): void
{
$tca = $event->getTca();

$items = [];
foreach ($this->configurationService->getModels() as $model => $modelConfiguration) {
foreach ((ConfigurationService::loadConfiguration()['models'] ?? []) as $model => $modelConfiguration) {
if ($modelConfiguration['enabled'] === false) {
continue;
}

$splitModel = explode('\\', $model);

$items[] = [$splitModel[array_key_last($splitModel)], $model];
$items[] = ['label' => $splitModel[array_key_last($splitModel)], 'value' => $model];
}

$tca['tx_typo3graphql_domain_model_filter']['columns']['model']['config']['items'] = $items;
Expand Down
17 changes: 17 additions & 0 deletions Classes/Hook/DataHandlerHooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Itx\Typo3GraphQL\Hook;

use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class DataHandlerHooks
{
public function processDatamap_afterDatabaseOperations($status, $table, $id, array $fieldArray, \TYPO3\CMS\Core\DataHandling\DataHandler &$pObj) {
$container = GeneralUtility::getContainer();
/** @var FrontendInterface $cache */
$cache = $container->get('cache.typo3_graphql_cache');

$cache->flushByTag($table);
}
}
126 changes: 126 additions & 0 deletions Classes/Middleware/ExtbaseBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php

declare(strict_types=1);
namespace Itx\Typo3GraphQL\Middleware;

/*
* This file is part of TYPO3 CMS-based extension "SlimPHP Bridge" by b13.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*/

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Routing\PageArguments;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Core\Bootstrap;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

/**
* Sets up TSFE and Extbase, in order to use Extbase within a Slim Controller
*/
class ExtbaseBridge
{
private string $typo3Version = '';
private Context $context;

public function __construct(Context $context)
{
$this->context = $context;
$this->typo3Version = (string)(new \TYPO3\CMS\Core\Information\Typo3Version());
}

public function boot(ServerRequestInterface $request, RequestHandlerInterface $handler): void
{
$site = $request->getAttribute('site');
if (!$site instanceof Site) {
return;
}

if (($GLOBALS['TYPO3_REQUEST'] ?? null) === null) {
$GLOBALS['TYPO3_REQUEST'] = $request;
}

if (!isset($GLOBALS['TSFE']) || !$GLOBALS['TSFE'] instanceof TypoScriptFrontendController) {
$request = $this->createGlobalTsfe($site, $request);
} else {
$GLOBALS['TSFE']->id = $site->getRootPageId();
}

$request = $this->bootFrontend($request);
$this->bootExtbase($request);
}

protected function createGlobalTsfe(Site $site, ServerRequestInterface $request): ServerRequestInterface
{
if (version_compare($this->typo3Version, '11.5', '>=')) {
$controller = GeneralUtility::makeInstance(
TypoScriptFrontendController::class,
$this->context,
$site,
$request->getAttribute('language', $site->getDefaultLanguage()),
new PageArguments($site->getRootPageId(), '0', []),
$request->getAttribute('frontend.user')
);

$controller->determineId($request);

$request = $request->withAttribute('frontend.controller', $controller);

// Make TSFE globally available
// @todo deprecate $GLOBALS['TSFE'] once TSFE is retrieved from the
// PSR-7 request attribute frontend.controller throughout TYPO3 core
$GLOBALS['TSFE'] = $controller;
} else {
$GLOBALS['TSFE'] = GeneralUtility::makeInstance(
TypoScriptFrontendController::class,
null,
$site,
$request->getAttribute('language'),
null,
$request->getAttribute('frontend.user')
);
}

return $request;
}

protected function bootFrontend(ServerRequestInterface $request): ServerRequestInterface
{
if (version_compare($this->typo3Version, '12.2', '>=')) {
// Run Frontend TypoScript
$request = $GLOBALS['TSFE']->getFromCache($request);
} elseif (version_compare($this->typo3Version, '11.5', '>=')) {
// nothing to do, TSFE is already ready
} else {
$GLOBALS['TSFE']->fetch_the_id($request);
$GLOBALS['TSFE']->getConfigArray($request);
$GLOBALS['TSFE']->settingLanguage($request);
$GLOBALS['TSFE']->newCObj();
}
return $request;
}

protected function bootExtbase(ServerRequestInterface $request): void
{
if (version_compare($this->typo3Version, '12.4', '>=')) {
GeneralUtility::makeInstance(Bootstrap::class)->initialize([
'extensionName' => 'typo3_graphql',
'vendorName' => 'Itx',
'pluginName' => 'graphql',
], $request);
}else {
GeneralUtility::makeInstance(Bootstrap::class)->initialize([
'extensionName' => 'typo3_graphql',
'vendorName' => 'Itx',
'pluginName' => 'graphql',
], $request);
}
}
}
22 changes: 12 additions & 10 deletions Classes/Middleware/GraphQLServerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,16 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Log\LoggerInterface;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class GraphQLServerMiddleware implements MiddlewareInterface
{
protected SchemaGenerator $schemaGenerator;
protected LoggerInterface $logger;
protected ConfigurationService $configurationService;

public function __construct(SchemaGenerator $schemaGenerator, LoggerInterface $logger, ConfigurationService $configurationService)
{
$this->schemaGenerator = $schemaGenerator;
$this->logger = $logger;
$this->configurationService = $configurationService;
}

/**
* @param ServerRequestInterface $request
* @param RequestHandlerInterface $handler
Expand All @@ -61,6 +54,15 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$request = $request->withParsedBody($parsedBody);
}

$container = GeneralUtility::getContainer();
// Get all di dependencies
$this->schemaGenerator = $container->get(SchemaGenerator::class);
$this->configurationService = $container->get(ConfigurationService::class);

// Start Extbase
$extbaseBridge = new ExtbaseBridge(GeneralUtility::makeInstance(Context::class));
$extbaseBridge->boot($request, $handler);

$typeRegistry = new TypeRegistry();

$schema = $this->schemaGenerator->generate($typeRegistry);
Expand All @@ -80,7 +82,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
];

if ($isIntrospectionEnabled === false) {
$rules[] = new DisableIntrospection();
$rules[] = new DisableIntrospection(true);
}

$serverConfig = [
Expand Down
1 change: 1 addition & 0 deletions Classes/Middleware/RequestObjectFixerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
return $handler->handle($request);
}
}

Loading

0 comments on commit 0b18903

Please sign in to comment.