12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?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 array
- */
- public function getJSON($parameter = 'client', $filters = [])
- {
- $url = $this->webservice->buildUrl($parameter, $filters);
- $result = json_decode($this->webservice->makeGetRequest($url), true);
- if ($result) {
- return current(json_decode($this->webservice->makeGetRequest($url), true));
- }
- return [];
- }
- /**
- * @return string
- */
- public function getName()
- {
- return 'get_json_extension';
- }
- }
|