The SSH host key has changed on 8 April, 2022 to this one: SHA256:573uTBSeh74kvOo0HJXi5ijdzRm8me27suzNEDlGyrQ
blueroses.hu project repository
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
kekrozsak/src/KekRozsak/FrontBundle/Twig/HelpUrlExtension.php

71 lines
1.6 KiB

<?php
namespace KekRozsak\FrontBundle\Twig;
use JMS\DiExtraBundle\Annotation as DI;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
/**
* Description of HelpUrlExtension
*
* @author Gergely Polonkai
*
* @DI\Service
* @DI\Tag("twig.extension")
*/
class HelpUrlExtension extends \Twig_Extension
{
/**
* @var Symfony\Component\DependencyInjection\ContainerInterface $container
*/
private $container;
/**
* @DI\InjectParams({
* "container" = @DI\Inject("service_container")
* })
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function getGlobals()
{
parent::getGlobals();
$request = $this->container->get('request');
$router = $this->container->get('router');
$currentRoute = $request->get('_route');
$m = array();
$helpRoutes = array($currentRoute . 'Help');
$helpUrl = null;
if (preg_match('/^([^_]+)_([a-z]+)/', $currentRoute, $m)) {
$helpRoutes[] = $m[1] . '_' . $m[2] . 'Help';
}
foreach ($helpRoutes as $helpRoute) {
try {
$helpUrl = $router->generate($helpRoute);
} catch (RouteNotFoundException $e) {
$helpUrl = null;
}
if ($helpUrl !== null) {
break;
}
}
return array(
'helpUrl' => $helpUrl,
);
}
public function getName()
{
return 'HelpUrl';
}
}