1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace WebserviceBundle\Twig;
- use WebserviceBundle\Services\Webservice;
- use WebserviceBundle\Utils\HttpUtils;
- class RemoteClientExtension extends \Twig_Extension
- {
-
- /**
- * @var Webservice
- */
- protected $webservice;
-
- /**
- * @var string
- */
- protected $remoteClientCreateUrl;
-
-
- /**
- * @param Webservice $webservice
- * @param string $remoteClientCreateUrl
- */
- public function __construct(Webservice $webservice, $remoteClientCreateUrl)
- {
- $this->webservice = $webservice;
- $this->remoteClientCreateUrl = $remoteClientCreateUrl;
- }
- /**
- * @return array
- */
- public function getFunctions()
- {
- return array(
- new \Twig_SimpleFunction('remote_client', array($this, 'getClient')),
- new \Twig_SimpleFunction('remote_client_url', array($this, 'getClientCreateUrl')),
- );
- }
- /**
- * @param int $clientId
- *
- * @return string
- */
- public function getClient($clientId)
- {
- return $this->webservice->getById('client', $clientId);
- }
- /**
- * @return string
- */
- public function getClientCreateUrl()
- {
- $url = HttpUtils::cleanUrl($this->remoteClientCreateUrl);
- if ($url == '' || filter_var($url, FILTER_VALIDATE_URL) === false) {
- return '#';
- }
-
- return $url;
- }
-
- /**
- * @return string
- */
- public function getName()
- {
- return 'remote_client_extension';
- }
- }
|