<?php

namespace Opentalent\OtCore\ViewHelpers;

use FluidTYPO3\Vhs\Utility\ErrorUtility;
use Opentalent\OtCore\Website\OtPageRepository;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

/**
 * Class OtAbstractViewHelper
 * Base class for Opentalent viewhelpers
 *
 * @package Opentalent\OtCore\ViewHelpers
 */
class OtAbstractViewHelper  extends AbstractViewHelper implements LoggerAwareInterface {
    use LoggerAwareTrait;

    /**
     * @var OtPageRepository
     *
     */
    protected OtPageRepository $pageRepository;

    /**
     * Throw a VHS viewhelper error
     */
    protected function throwException(string $msg) {
        ErrorUtility::throwViewHelperException($msg);
    }

    /**
     * @param OtPageRepository $pageRepository
     */
    public function injectOtPageRepository(OtPageRepository $pageRepository)
    {
        $this->pageRepository = $pageRepository;
    }

    /**
     * Returns the language service.
     *
     * @return \TYPO3\CMS\Core\Localization\LanguageService
     */
    protected function getLanguageService(): \TYPO3\CMS\Core\Localization\LanguageService
    {
        return $GLOBALS['LANG'];
    }
}
