1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace WebserviceBundle\Twig;
- use Buzz\Message\RequestInterface as HttpRequestInterface;
- use WebserviceBundle\Services\Webservice;
- use WebserviceBundle\Utils\HttpUtils;
- class GetJSONExtension extends \Twig_Extension
- {
- /**
- * @var Webservice
- */
- protected $webservice;
- /**
- * @param Webservice $webservice
- */
- public function __construct(Webservice $webservice)
- {
- $this->webservice = $webservice;
- }
- /**
- * @return array
- */
- public function getFunctions()
- {
- return array(
- new \Twig_SimpleFunction('get_json', array($this, 'getJSON')),
- );
- }
- /**
- * @param int $clientId
- *
- * @return string
- */
- public function getJSON($parameter = 'client', $filters = [])
- {
- $url = $this->webservice->buildUrl($parameter, $filters);
- return current(json_decode($this->webservice->makeGetRequest($url), true));
- }
- /**
- * @return string
- */
- public function getName()
- {
- return 'get_json_extension';
- }
- }
|