vendor/vich/uploader-bundle/src/Twig/Extension/UploaderExtension.php line 44

Open in your IDE?
  1. <?php
  2. namespace Vich\UploaderBundle\Twig\Extension;
  3. use Twig\Extension\AbstractExtension;
  4. use Twig\TwigFunction;
  5. use Vich\UploaderBundle\Templating\Helper\UploaderHelper;
  6. /**
  7.  * UploaderExtension.
  8.  *
  9.  * @author Dustin Dobervich <ddobervich@gmail.com>
  10.  */
  11. final class UploaderExtension extends AbstractExtension
  12. {
  13.     /**
  14.      * @var UploaderHelper
  15.      */
  16.     private $helper;
  17.     public function __construct(UploaderHelper $helper)
  18.     {
  19.         $this->helper $helper;
  20.     }
  21.     public function getFunctions(): array
  22.     {
  23.         return [
  24.             new TwigFunction('vich_uploader_asset', [$this'asset']),
  25.         ];
  26.     }
  27.     /**
  28.      * Gets the public path for the file associated with the uploadable object.
  29.      *
  30.      * @param object      $object    The object
  31.      * @param string|null $fieldName The field name
  32.      * @param string|null $className The object's class. Mandatory if $obj can't be used to determine it
  33.      *
  34.      * @return string|null The public path or null if file not stored
  35.      */
  36.     public function asset($object, ?string $fieldName null, ?string $className null): ?string
  37.     {
  38.         return $this->helper->asset($object$fieldName$className);
  39.     }
  40. }