Skip to content

Commit

Permalink
[TASK] Use #[AsHelper] attribute in all helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
eliashaeussler committed Dec 18, 2024
1 parent 3bc5168 commit b11f6f2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
4 changes: 3 additions & 1 deletion Classes/Renderer/Helper/BlockHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace Fr\Typo3Handlebars\Renderer\Helper;

use Fr\Typo3Handlebars\Attribute;
use Fr\Typo3Handlebars\Exception;
use Fr\Typo3Handlebars\Renderer;

Expand All @@ -33,12 +34,13 @@
* @license GPL-2.0-or-later
* @see https://github.com/shannonmoeller/handlebars-layouts#block-name
*/
class BlockHelper implements HelperInterface
final readonly class BlockHelper implements HelperInterface
{
/**
* @param array<string, mixed> $options
* @throws Exception\UnsupportedTypeException
*/
#[Attribute\AsHelper('block')]
public function evaluate(string $name, array $options): string
{
$data = $options['_this'];
Expand Down
6 changes: 4 additions & 2 deletions Classes/Renderer/Helper/ContentHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace Fr\Typo3Handlebars\Renderer\Helper;

use Fr\Typo3Handlebars\Attribute;
use Fr\Typo3Handlebars\Renderer;
use Psr\Log;

Expand All @@ -33,16 +34,17 @@
* @license GPL-2.0-or-later
* @see https://github.com/shannonmoeller/handlebars-layouts#content-name-modeappendprependreplace
*/
class ContentHelper implements HelperInterface
final readonly class ContentHelper implements HelperInterface
{
public function __construct(
protected readonly Log\LoggerInterface $logger,
private Log\LoggerInterface $logger,
) {}

/**
* @param array<string, mixed> $options
* @return string|bool
*/
#[Attribute\AsHelper('content')]
public function evaluate(string $name, array $options)
{
$data = $options['_this'];
Expand Down
6 changes: 4 additions & 2 deletions Classes/Renderer/Helper/ExtendHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace Fr\Typo3Handlebars\Renderer\Helper;

use Fr\Typo3Handlebars\Attribute;
use Fr\Typo3Handlebars\Renderer;

/**
Expand All @@ -32,12 +33,13 @@
* @license GPL-2.0-or-later
* @see https://github.com/shannonmoeller/handlebars-layouts#extend-partial-context-keyvalue-
*/
class ExtendHelper implements HelperInterface
final readonly class ExtendHelper implements HelperInterface
{
public function __construct(
protected readonly Renderer\RendererInterface $renderer,
private Renderer\RendererInterface $renderer,
) {}

#[Attribute\AsHelper('extend')]
public function evaluate(string $name): string
{
// Get helper options
Expand Down
10 changes: 6 additions & 4 deletions Classes/Renderer/Helper/RenderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace Fr\Typo3Handlebars\Renderer\Helper;

use Fr\Typo3Handlebars\Attribute;
use Fr\Typo3Handlebars\DataProcessing;
use Fr\Typo3Handlebars\Exception;
use Fr\Typo3Handlebars\Renderer;
Expand All @@ -37,17 +38,18 @@
* @license GPL-2.0-or-later
* @see https://github.com/frctl/fractal/blob/main/packages/handlebars/src/helpers/render.js
*/
class RenderHelper implements HelperInterface
final readonly class RenderHelper implements HelperInterface
{
public function __construct(
protected readonly Renderer\RendererInterface $renderer,
protected readonly Core\TypoScript\TypoScriptService $typoScriptService,
protected readonly Frontend\ContentObject\ContentObjectRenderer $contentObjectRenderer,
private Renderer\RendererInterface $renderer,
private Core\TypoScript\TypoScriptService $typoScriptService,
private Frontend\ContentObject\ContentObjectRenderer $contentObjectRenderer,
) {}

/**
* @throws Exception\InvalidConfigurationException
*/
#[Attribute\AsHelper('render')]
public function evaluate(string $name): SafeString
{
// Get helper options
Expand Down
10 changes: 5 additions & 5 deletions Classes/Renderer/Helper/VarDumpHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@

namespace Fr\Typo3Handlebars\Renderer\Helper;

use Fr\Typo3Handlebars\Attribute\AsHelper;
use TYPO3\CMS\Core\Utility\DebugUtility;
use Fr\Typo3Handlebars\Attribute;
use TYPO3\CMS\Core;

/**
* VarDumpHelper
*
* @author Elias Häußler <e.haeussler@familie-redlich.de>
* @license GPL-2.0-or-later
*/
class VarDumpHelper implements HelperInterface
final readonly class VarDumpHelper implements HelperInterface
{
/**
* @param array<string|int, mixed> $context
*/
#[AsHelper('varDump')]
#[Attribute\AsHelper('varDump')]
public static function evaluate(array $context): string
{
\ob_start();

DebugUtility::debug($context['_this']);
Core\Utility\DebugUtility::debug($context->renderingContext);

Check failure on line 45 in Classes/Renderer/Helper/VarDumpHelper.php

View workflow job for this annotation

GitHub Actions / cgl

Cannot access property $renderingContext on array<int|string, mixed>.

return (string)\ob_get_clean();
}
Expand Down

0 comments on commit b11f6f2

Please sign in to comment.