<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\AdminBundle\Twig;

use Contao\CoreBundle\Filesystem\FilesystemItem;
use Contao\CoreBundle\Filesystem\VirtualFilesystemException;
use Twig\Attribute\AsTwigFunction;

final class FilesystemItemExtension
{
    #[AsTwigFunction('safe_file_size')]
    public function safeFileSize(FilesystemItem $item): ?int
    {
        try {
            return $item->getFileSize();
        } catch (VirtualFilesystemException) {
            return null;
        }
    }
}
