Connector.php 836B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. return new Response(json_decode(curl_exec($api_url), true));
  20. }
  21. public function setElementDatasWithResponse(Response $response, $parameters)
  22. {
  23. foreach ($parameters as $data_id => $searched)
  24. {
  25. if ($response->have($searched))
  26. {
  27. $this->element->setData($data_id, $response->get($searched));
  28. }
  29. }
  30. }
  31. }