All checks were successful
build / build (pull_request) Successful in 5m29s
31 lines
692 B
PHP
31 lines
692 B
PHP
<?php
|
|
|
|
namespace App\Twig;
|
|
|
|
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
|
|
use Twig\Extension\AbstractExtension;
|
|
use Twig\TwigFunction;
|
|
|
|
class Environment extends AbstractExtension
|
|
{
|
|
public function getFunctions(): array
|
|
{
|
|
return [
|
|
new TwigFunction('env', $this->getVar(...)),
|
|
new TwigFunction('entityId', $this->getEntityId(...)),
|
|
];
|
|
}
|
|
|
|
public function getVar(string $name): string
|
|
{
|
|
return $_ENV[$name];
|
|
}
|
|
|
|
public function getEntityId(FieldDto $field): string
|
|
{
|
|
$url = $field->getCustomOption('toggleUrl');
|
|
preg_match('/entityId=(\d+)/', $url, $matches);
|
|
|
|
return $matches[1];
|
|
}
|
|
} |