Connector.php 925B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Muzich\CoreBundle\lib\Api;
  3. use Muzich\CoreBundle\Entity\Element;
  4. class Connector
  5. {
  6. private $element;
  7. public function __construct(Element $element)
  8. {
  9. $this->element = $element;
  10. }
  11. public function getResponseForUrl($url)
  12. {
  13. $api_url = curl_init($url);
  14. $options = array(
  15. CURLOPT_RETURNTRANSFER => true,
  16. CURLOPT_HTTPHEADER => array('Content-type: application/json')
  17. );
  18. curl_setopt_array($api_url, $options);
  19. //exit($url);
  20. //var_dump(json_decode(curl_exec($api_url), true));
  21. //exit(1);
  22. return new Response(json_decode(curl_exec($api_url), true));
  23. }
  24. public function setElementDatasWithResponse(Response $response, $parameters)
  25. {
  26. foreach ($parameters as $data_id => $searched)
  27. {
  28. if ($response->have($searched))
  29. {
  30. $this->element->setData($data_id, $response->get($searched));
  31. }
  32. }
  33. }
  34. }