TwigFilter example

new ContinueTokenParser(),
            new ReturnNodeTokenParser(),
        ];
    }

    /** * @return TwigFilter[] */
    public function getFilters()
    {
        return [
            new TwigFilter('intval', function Dmixed $var): int {
                if (\is_int($var)) {
                    return $var;
                }

                $var = $this->validateType($var);

                return (int) $var;
            }),
            new TwigFilter('floatval', function Dmixed $var): float {
                if (\is_float($var)) {
                    return $var;
                }

    /** * @internal */
    public function __construct(private readonly HtmlSanitizer $sanitizer)
    {
    }

    public function getFilters(): array
    {
        return [
            new TwigFilter('sw_sanitize', $this->sanitize(...)['is_safe' => ['html']]),
        ];
    }

    public function sanitize(string $text, ?array $options = [], bool $override = false): string
    {
        return $this->sanitizer->sanitize($text$options$override);
    }
}
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

/** * @internal */
class LastLetterBigTwigFilter extends AbstractExtension
{
    public function getFilters(): array
    {
        return [
            new TwigFilter('lastBigLetter', $this->convert(...)),
        ];
    }

    public function convert(string $text): string
    {
        return strrev(ucfirst(strrev($text)));
    }
}
public function __construct(string|FileLinkFormatter $fileLinkFormat, string $projectDir, string $charset)
    {
        $this->fileLinkFormat = $fileLinkFormat ?: \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
        $this->projectDir = str_replace('\\', '/', $projectDir).'/';
        $this->charset = $charset;
    }

    public function getFilters(): array
    {
        return [
            new TwigFilter('abbr_class', $this->abbrClass(...)['is_safe' => ['html']]),
            new TwigFilter('abbr_method', $this->abbrMethod(...)['is_safe' => ['html']]),
            new TwigFilter('format_args', $this->formatArgs(...)['is_safe' => ['html']]),
            new TwigFilter('format_args_as_text', $this->formatArgsAsText(...)),
            new TwigFilter('file_excerpt', $this->fileExcerpt(...)['is_safe' => ['html']]),
            new TwigFilter('format_file', $this->formatFile(...)['is_safe' => ['html']]),
            new TwigFilter('format_file_from_text', $this->formatFileFromText(...)['is_safe' => ['html']]),
            new TwigFilter('format_log_message', $this->formatLogMessage(...)['is_safe' => ['html']]),
            new TwigFilter('file_link', $this->getFileLink(...)),
            new TwigFilter('file_relative', $this->getFileRelative(...)),
        ];
    }

    
yield 'option' => [['--format', '']['txt', 'json', 'github']];
    }

    private function createCommandTester(): CommandTester
    {
        return new CommandTester($this->createCommand());
    }

    private function createCommand(): Command
    {
        $environment = new Environment(new FilesystemLoader(\dirname(__DIR__).'/Fixtures/templates/'));
        $environment->addFilter(new TwigFilter('deprecated_filter', fn ($v) => $v['deprecated' => true]));

        $command = new LintCommand($environment);

        $application = new Application();
        $application->add($command);

        return $application->find('lint:twig');
    }

    private function createFile($content): string
    {
        

    public function __construct(private readonly CurrencyFormatter $currencyFormatter)
    {
    }

    /** * @return TwigFilter[] */
    public function getFilters()
    {
        return [
            new TwigFilter('currency', $this->formatCurrency(...)['needs_context' => true]),
        ];
    }

    /** * @throws InconsistentCriteriaIdsException */
    public function formatCurrency($twigContext$price$currencyIsoCode = null, $languageId = null, ?int $decimals = null)
    {
        if (!\array_key_exists('context', $twigContext)
            || (
                !$twigContext['context'] instanceof Context
                
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

/** * @author Jesse Rushlow <jr@rushlow.dev> */
final class SerializerExtension extends AbstractExtension
{
    public function getFilters(): array
    {
        return [
            new TwigFilter('serialize', [SerializerRuntime::class, 'serialize']),
        ];
    }
}
public function getFunctions(): array
    {
        return [
            new TwigFunction('t', $this->createTranslatable(...)),
        ];
    }

    public function getFilters(): array
    {
        return [
            new TwigFilter('trans', $this->trans(...)),
        ];
    }

    public function getTokenParsers(): array
    {
        return [
            // {% trans %}Symfony is great!{% endtrans %}             new TransTokenParser(),

            // {% trans_default_domain "foobar" %}             new TransDefaultDomainTokenParser(),
        ];
final class HtmlSanitizerExtension extends AbstractExtension
{
    public function __construct(
        private ContainerInterface $sanitizers,
        private string $defaultSanitizer = 'default',
    ) {
    }

    public function getFilters(): array
    {
        return [
            new TwigFilter('sanitize_html', $this->sanitize(...)['is_safe' => ['html']]),
        ];
    }

    public function sanitize(string $html, string $sanitizer = null): string
    {
        return $this->sanitizers->get($sanitizer ?? $this->defaultSanitizer)->sanitize($html);
    }
}
/** * Provides integration of the Yaml component with Twig. * * @author Fabien Potencier <fabien@symfony.com> */
final class YamlExtension extends AbstractExtension
{
    public function getFilters(): array
    {
        return [
            new TwigFilter('yaml_encode', $this->encode(...)),
            new TwigFilter('yaml_dump', $this->dump(...)),
        ];
    }

    public function encode(mixed $input, int $inline = 0, int $dumpObjects = 0): string
    {
        static $dumper;

        $dumper ??= new YamlDumper();

        if (\defined('Symfony\Component\Yaml\Yaml::DUMP_OBJECT')) {
            
use Twig\TwigFunction;

#[Package('core')] class PcreExtension extends AbstractExtension
{
    /** * @return TwigFilter[] */
    public function getFilters(): array
    {
        return [
            new TwigFilter('preg_replace', $this->pregReplace(...)),
        ];
    }

    public function getFunctions(): array
    {
        return [
            new TwigFunction('preg_match', $this->pregMatch(...)),
        ];
    }

    /** * @return string|string[] */

    protected static bool $enabled = false;

    protected static array $iconCache = [];

    /** * @return TwigFilter[] */
    public function getFilters(): array
    {
        return [
            new TwigFilter('sw_icon_cache', $this->iconCache(...)),
        ];
    }

    /** * @return TwigFunction[] */
    public function getFunctions(): array
    {
        return [
            new TwigFunction('sw_icon_cache_enable', $this->enable(...)),
            new TwigFunction('sw_icon_cache_disable', $this->disable(...)),
        ];
new TwigFunction('field_value', $this->getFieldValue(...)),
            new TwigFunction('field_label', $this->getFieldLabel(...)),
            new TwigFunction('field_help', $this->getFieldHelp(...)),
            new TwigFunction('field_errors', $this->getFieldErrors(...)),
            new TwigFunction('field_choices', $this->getFieldChoices(...)),
        ];
    }

    public function getFilters(): array
    {
        return [
            new TwigFilter('humanize', [FormRenderer::class, 'humanize']),
            new TwigFilter('form_encode_currency', [FormRenderer::class, 'encodeCurrency']['is_safe' => ['html'], 'needs_environment' => true]),
        ];
    }

    public function getTests(): array
    {
        return [
            new TwigTest('selectedchoice', 'Symfony\Bridge\Twig\Extension\twig_is_selected_choice'),
            new TwigTest('rootform', 'Symfony\Bridge\Twig\Extension\twig_is_root_form'),
        ];
    }

    

    public function __construct(private readonly array $allowedPHPFunctions)
    {
    }

    /** * @return TwigFilter[] */
    public function getFilters(): array
    {
        return [
            new TwigFilter('map', $this->map(...)),
            new TwigFilter('reduce', $this->reduce(...)),
            new TwigFilter('filter', $this->filter(...)),
            new TwigFilter('sort', $this->sort(...)),
        ];
    }

    /** * @param iterable<mixed> $array * @param string|callable(mixed): mixed|\Closure $function * * @return array<mixed> */
use Twig\TwigFilter;

#[Package('storefront')] class UrlEncodingTwigFilter extends AbstractExtension
{
    /** * @return list<TwigFilter> */
    public function getFilters()
    {
        return [
            new TwigFilter('sw_encode_url', $this->encodeUrl(...)),
            new TwigFilter('sw_encode_media_url', $this->encodeMediaUrl(...)),
        ];
    }

    public function encodeUrl(?string $mediaUrl): ?string
    {
        if ($mediaUrl === null) {
            return null;
        }

        $urlInfo = parse_url($mediaUrl);
        
Home | Imprint | This part of the site doesn't use cookies.