A bare bones front-end for knockout designed for maximum compatibility with "obsolete" browsers
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

46 lines
1.0KB

  1. <?php
  2. namespace App\Knockout;
  3. class AbstractData {
  4. protected $root;
  5. public function __construct()
  6. {
  7. $this->root = env('KNOCKOUT_API', 'https://api.knockout.chat');
  8. }
  9. private function encodeParameters($parameters = [])
  10. {
  11. $parameters = array_map(function($value, $key) {
  12. return urlencode($key) . '=' . urlencode($value);
  13. }, $parameters, array_keys($parameters));
  14. return '?' . implode('&', $parameters);
  15. }
  16. private function curl($path, $parameters = [])
  17. {
  18. $ch = curl_init(implode(null, [
  19. $this->root, $path, $this->encodeParameters($parameters)
  20. ]));
  21. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  22. curl_setopt($ch, CURLOPT_HEADER, 0);
  23. return $ch;
  24. }
  25. public function httpGet($path, $parameters = [])
  26. {
  27. $ch = $this->curl($path, $parameters);
  28. $data = curl_exec($ch);
  29. curl_close($ch);
  30. return $data;
  31. }
  32. public function httpPost($path, $parameters = [], $properties = [])
  33. {
  34. }
  35. }