<?php

namespace Opentalent\OtTemplating\ViewHelpers\Request;

use Closure;
use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;

/**
 *   Return true if the requested website's domain is a custom domain,
 *   i.e. its domain is not of the form *.opentalent.fr
 *
 *     {namespace ot=Opentalent\OtTemplating\ViewHelpers}
 *
 *     {ot:request.isCustomDomain()}
 *
 * @package Opentalent\OtTemplating\ViewHelpers
 */
class IsCustomDomainViewHelper extends OtAbstractViewHelper {

    /**
     * -- This method is expected by Fluid --
     * Declares the viewhelper's parameters
     */
    public function initializeArguments()
    {
    }

    /**
     * -- This method is expected by Fluid --
     * Renders the content as html
     *
     * @param array $arguments
     * @param Closure $renderChildrenClosure
     * @param RenderingContextInterface $renderingContext
     * @return string|null
     */
    public static function renderStatic(
        array $arguments,
        Closure $renderChildrenClosure,
        RenderingContextInterface $renderingContext
    ) {
        return !preg_match(
            "/.*\.opentalent\.fr/",
            $_SERVER['HTTP_HOST']
        );
    }
}
