| Total Complexity | 8 |
| Total Lines | 58 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | class TwigExtension extends AbstractExtension |
||
| 11 | { |
||
| 12 | protected $doctrine; |
||
| 13 | |||
| 14 | public function getFunctions(): array |
||
| 15 | { |
||
| 16 | return [ |
||
| 17 | new TwigFunction('findUser', [$this, 'findUser']), |
||
| 18 | new TwigFunction('class', [$this, 'getClass']), |
||
| 19 | new TwigFunction('tablename', [$this, 'getTablename']), |
||
| 20 | ]; |
||
| 21 | } |
||
| 22 | |||
| 23 | public function getFilters(): array |
||
| 27 | ]; |
||
| 28 | } |
||
| 29 | |||
| 30 | public function __construct(RegistryInterface $doctrine) |
||
| 31 | { |
||
| 32 | $this->doctrine = $doctrine; |
||
| 33 | } |
||
| 34 | |||
| 35 | public function findUser($id, $repository) |
||
| 36 | { |
||
| 37 | if (null === $id) { |
||
| 38 | return null; |
||
| 39 | } |
||
| 40 | |||
| 41 | $em = $this->doctrine->getManager(); |
||
| 42 | $repo = $em->getRepository($repository); |
||
| 43 | |||
| 44 | return $repo->find($id); |
||
| 45 | } |
||
| 46 | |||
| 47 | public function getClass($entity): string |
||
| 48 | { |
||
| 49 | return \get_class($entity); |
||
| 50 | } |
||
| 51 | |||
| 52 | public function getTablename($entity): string |
||
| 59 | ; |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * {@inheritdoc} |
||
| 64 | */ |
||
| 65 | public function getName(): string |
||
| 68 | } |
||
| 69 | } |
||
| 70 |