ojstr.twig.ojs_extension:
class: Sfapp\Common\Twig\SfappExtension
arguments: [@service_container]
tags:
- { name: twig.extension }
arguments sayesinden extension dosyasında service container'a erişebileceğim.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Sfapp\Common\Twig; | |
use Symfony\Component\DependencyInjection\ContainerInterface as Container; | |
class SfappExtension extends \Twig_Extension { | |
private $container; | |
public function __construct(Container $container = null) { | |
$this->container = $container; | |
} | |
public function getFunctions() { | |
return array( | |
'testuser' => new \Twig_Function_Method($this, 'checkUser', array('is_safe' => array('html'))) | |
); | |
} | |
public function checkUser() { | |
$securityContext = $this->container->get('security.context'); | |
if ($securityContext->isGranted('IS_AUTHENTICATED_FULLY')) { | |
return "ok"; | |
} | |
return "notok"; | |
} | |
public function getName() { | |
return 'sfapp_extension'; | |
} | |
} |
No comments:
Post a Comment