Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Tests export-ignore
.github export-ignore

.gitattributes export-ignore
.gitignore export-ignore

ecs.php export-ignore
phpstan-baseline.neon export-ignore
phpstan.neon export-ignore
phpunit.xml.dist export-ignore
91 changes: 81 additions & 10 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.2
coverage: none
tools: composer:v2
env:
Expand All @@ -29,9 +29,9 @@ jobs:
strategy:
matrix:
php-version:
- 8.1
- 8.2
- 8.3
- 8.4
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -43,16 +43,43 @@ jobs:
coverage: none

- name: PHP lint
run: "find *.php Classes Configuration -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l"
run: "find *.php Classes Configuration Tests -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l"

coding-guideline:
runs-on: ubuntu-latest
needs:
- check-composer
steps:
- uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
coverage: none
tools: composer:v2
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
run: composer install --no-progress --no-interaction --optimize-autoloader

- name: Coding Guideline
run: ./vendor/bin/ecs check

code-quality:
runs-on: ubuntu-latest
needs:
- check-composer
strategy:
matrix:
php-version:
- 8.1
- 8.2
- 8.3
include:
- php-version: '8.2'
typo3-version: '^13.4'
- php-version: '8.3'
typo3-version: '^13.4'
- php-version: '8.4'
typo3-version: '^13.4'
steps:
- uses: actions/checkout@v4

Expand All @@ -66,7 +93,51 @@ jobs:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies with expected TYPO3 version
run: composer require --prefer-dist --no-progress
run: composer require --no-progress --no-interaction --optimize-autoloader "typo3/cms-core:${{ matrix.typo3-version }}"

- name: PHPStan
run: ./vendor/bin/phpstan

- name: Code Quality (by PHPStan)
run: ./vendor/bin/phpstan analyse
tests:
runs-on: ubuntu-latest
needs:
- check-composer
strategy:
matrix:
include:
- php-version: '8.2'
typo3-version: '^13.4'
- php-version: '8.3'
typo3-version: '^13.4'
- php-version: '8.4'
typo3-version: '^13.4'
steps:
- uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php-version }}"
coverage: xdebug
tools: composer:v2
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies with expected TYPO3 version
run: composer require --no-progress --no-interaction --optimize-autoloader "typo3/cms-core:${{ matrix.typo3-version }}"

- name: PHPUnit Tests
run: ./vendor/bin/phpunit --testdox --display-all-issues --coverage-cobertura coverage/coverage.cobertura.xml

- name: Code Coverage Report
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: coverage/coverage.cobertura.xml
badge: false
fail_below_min: true
format: text
hide_branch_rate: true
hide_complexity: true
indicators: true
output: console
thresholds: '80 100'
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/public/
/vendor/
/composer.lock
/.Build/
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.0.0 (2025-09-23)

TYPO3 v13 compatibility, dropping earlier TYPO3 versions.

## 3.0.0 (2022-07-06)

Merge pull request #26 from visol/feature/refactor-namespace
Expand Down
22 changes: 12 additions & 10 deletions Classes/Controller/AbstractHandlebarsController.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

namespace Visol\Handlebars\Controller;

use Visol\Handlebars\View\HandlebarsView;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use Visol\Handlebars\Rendering\HandlebarsContext;
use Visol\Handlebars\View\HandlebarsView;

/***************************************************************
* Copyright notice
Expand Down Expand Up @@ -33,16 +36,15 @@
*/
abstract class AbstractHandlebarsController extends ActionController
{

/** @var HandlebarsView */
protected $view;

/**
* The default view object to use if none of the resolved views can render
* a response for the current request.
*
* @var string
* @api
*/
protected $defaultViewObjectName = HandlebarsView::class;
protected function resolveView(): HandlebarsView
{
$view = GeneralUtility::makeInstance(HandlebarsView::class);
$view->assign('settings', $this->settings);
$view->setRenderingContext(new HandlebarsContext($this->request));

return $view;
}
}
9 changes: 3 additions & 6 deletions Classes/DataProvider/AbstractDataProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Visol\Handlebars\DataProvider;

/***************************************************************
Expand Down Expand Up @@ -31,13 +32,9 @@
*/
abstract class AbstractDataProvider implements DataProviderInterface
{
/**
* @var array
*/
protected $settings;

protected array $settings;

public function __construct($settings)
public function __construct(array $settings)
{
$this->settings = $settings;
}
Expand Down
2 changes: 0 additions & 2 deletions Classes/DataProvider/DataProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@
*/
interface DataProviderInterface
{

/**
* @return array
*/
public function provide();

}
15 changes: 9 additions & 6 deletions Classes/DataProvider/TyposcriptDataProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Visol\Handlebars\DataProvider;

/***************************************************************
Expand Down Expand Up @@ -28,13 +29,15 @@

class TyposcriptDataProvider extends AbstractDataProvider
{
/**
* Entry point
*
* @return array
*/
public function provide()
{
return is_array($this->settings['variables']) ? $this->settings['variables'] : [];
if (
array_key_exists('variables', $this->settings)
&& is_array($this->settings['variables'])
) {
return $this->settings['variables'];
}

return [];
}
}
29 changes: 14 additions & 15 deletions Classes/Engine/HandlebarsEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

use Visol\Handlebars\DataProvider\DataProviderInterface;
use Visol\Handlebars\Exception\NoTemplateConfiguredException;
use Visol\Handlebars\Exception\TemplateNotFoundException;
use Visol\Handlebars\HelperRegistry;
use LightnCandy\LightnCandy;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use Visol\Handlebars\DataProvider\DataProviderInterface;
use Visol\Handlebars\Exception\NoTemplateConfiguredException;
use Visol\Handlebars\Exception\TemplateNotFoundException;
use Visol\Handlebars\HelperRegistry;

/**
* Class HandlebarsEngine
Expand All @@ -53,7 +53,7 @@ class HandlebarsEngine
protected ?string $partialsRootPath;

protected ?string $template;

protected array $dataProviders;

protected array $additionalData;
Expand All @@ -71,7 +71,7 @@ public function __construct(array $settings)
$this->template = $settings['template'] ?? $settings['templatePath'] ?? null;
$this->dataProviders = $settings['dataProviders'] ?? [];
$this->additionalData = $settings['additionalData'] ?? [];
$this->tempPath = Environment::getProjectPath() . '/' . $settings['tempPath'];
$this->tempPath = Environment::getProjectPath() . '/' . ($settings['tempPath'] ?? '');
}

/**
Expand Down Expand Up @@ -118,11 +118,10 @@ public function getRendererForTemplate(string $template): callable
if (!isset($templatePathAndFilename)) {
throw new TemplateNotFoundException($template, $this->templatesRootPath);
}

$compiledCodePathAndFilename = $this->getCompiledCodePathAndFilename($templatePathAndFilename);

if (!is_file($compiledCodePathAndFilename) || $this->isBackendUserOnline()) { // if we have a BE login always compile the template

// Compiling to PHP Code
$compiledCode = LightnCandy::compile($this->getTemplateCode($templatePathAndFilename), $this->getOptions());

Expand Down Expand Up @@ -180,7 +179,7 @@ protected function getPartialCode($cx, $name): string
{
$partialContent = '';
$partialFileNameAndPath = $this->getPartialPathAndFileName($name);
if (file_exists($partialFileNameAndPath)) {
if (is_string($partialFileNameAndPath) && file_exists($partialFileNameAndPath)) {
return file_get_contents($partialFileNameAndPath);
}
return $partialContent;
Expand Down Expand Up @@ -211,7 +210,7 @@ protected function getTemplatePathAndFilename(string $template): ?string
if (isset($this->templatesRootPath)) {
$candidates[] = $this->templatesRootPath . $template;
}

return $this->findHbsFile($candidates);
}

Expand All @@ -229,7 +228,7 @@ protected function getPartialPathAndFileName(string $name): ?string
if (isset($this->templatesRootPath)) {
$candidates[] = $this->templatesRootPath . $name;
}

return $this->findHbsFile($candidates);
}

Expand All @@ -240,8 +239,8 @@ protected function findHbsFile(array $basenameCandidates): ?string
$basenameCandidate,
$basenameCandidate . '.hbs'
];
foreach($candidates as $candidate) {

foreach ($candidates as $candidate) {
$pathAndFilename = GeneralUtility::getFileAbsFileName($candidate);
if (is_file($pathAndFilename)) {
return $pathAndFilename;
Expand All @@ -251,7 +250,7 @@ protected function findHbsFile(array $basenameCandidates): ?string

return null;
}

/**
* Returns backend user online status
*/
Expand Down Expand Up @@ -281,7 +280,7 @@ protected function getViewHelpers(): array
$this->getDefaultHelpers(),
HelperRegistry::getInstance()->getHelpers()
);
array_walk($helpers, fn($helperFunction) => \Closure::bind($helperFunction, $this, $this));
array_walk($helpers, fn ($helperFunction) => \Closure::bind($helperFunction, $this, $this));
return $helpers;
}
}
1 change: 0 additions & 1 deletion Classes/Exception/NoTemplateConfiguredException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class NoTemplateConfiguredException extends \RuntimeException
{

}
3 changes: 1 addition & 2 deletions Classes/HelperRegistry.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Visol\Handlebars;

/*
Expand All @@ -17,7 +18,6 @@
*/
class HelperRegistry implements SingletonInterface
{

/**
* @var array
*/
Expand Down Expand Up @@ -61,5 +61,4 @@ public function getHelpers(): array
{
return $this->helpers;
}

}
Loading