vendor/omines/datatables-bundle/src/Column/TwigColumn.php line 32

Open in your IDE?
  1. <?php
  2. /*
  3.  * Symfony DataTables Bundle
  4.  * (c) Omines Internetbureau B.V. - https://omines.nl/
  5.  *
  6.  * For the full copyright and license information, please view the LICENSE
  7.  * file that was distributed with this source code.
  8.  */
  9. declare(strict_types=1);
  10. namespace Omines\DataTablesBundle\Column;
  11. use Omines\DataTablesBundle\Exception\MissingDependencyException;
  12. use Symfony\Component\OptionsResolver\OptionsResolver;
  13. use Twig\Environment;
  14. /**
  15.  * TwigColumn.
  16.  *
  17.  * @author Niels Keurentjes <niels.keurentjes@omines.com>
  18.  */
  19. class TwigColumn extends AbstractColumn
  20. {
  21.     /** @var Environment */
  22.     protected $twig;
  23.     /**
  24.      * TwigColumn constructor.
  25.      */
  26.     public function __construct(Environment $twig null)
  27.     {
  28.         if (null === ($this->twig $twig)) {
  29.             throw new MissingDependencyException('You must have TwigBundle installed to use ' . static::class);
  30.         }
  31.     }
  32.     /**
  33.      * {@inheritdoc}
  34.      */
  35.     protected function render($value$context)
  36.     {
  37.         return $this->twig->render($this->getTemplate(), [
  38.             'row' => $context,
  39.             'value' => $value,
  40.             'column' => $this,
  41.         ]);
  42.     }
  43.     /**
  44.      * {@inheritdoc}
  45.      */
  46.     public function normalize($value)
  47.     {
  48.         return $value;
  49.     }
  50.     /**
  51.      * {@inheritdoc}
  52.      */
  53.     protected function configureOptions(OptionsResolver $resolver)
  54.     {
  55.         parent::configureOptions($resolver);
  56.         $resolver
  57.             ->setRequired('template')
  58.             ->setAllowedTypes('template''string')
  59.         ;
  60.         return $this;
  61.     }
  62.     public function getTemplate(): string
  63.     {
  64.         return $this->options['template'];
  65.     }
  66. }