PageRenderTime 71ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/joomla/openstreetmap/openstreetmap.php

https://gitlab.com/lankerd/paGO---Testing-Site
PHP | 163 lines | 43 code | 20 blank | 100 comment | 3 complexity | 5196566a31af59323c6ea264dfb06ae1 MD5 | raw file
  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage Openstreetmap
  5. *
  6. * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. defined('JPATH_PLATFORM') or die();
  10. use Joomla\Registry\Registry;
  11. /**
  12. * Joomla Platform class for interact with Openstreetmap API.
  13. *
  14. * @since 13.1
  15. */
  16. class JOpenstreetmap
  17. {
  18. /**
  19. * Options for the Openstreetmap object.
  20. *
  21. * @var Registry
  22. * @since 13.1
  23. */
  24. protected $options;
  25. /**
  26. * The HTTP client object to use in sending HTTP requests.
  27. *
  28. * @var JHttp
  29. * @since 13.1
  30. */
  31. protected $client;
  32. /**
  33. * The OAuth client.
  34. *
  35. * @var JOpenstreetmapOauth
  36. * @since 13.1
  37. */
  38. protected $oauth;
  39. /**
  40. * Openstreetmap API object for changesets.
  41. *
  42. * @var JOpenstreetmapChangesets
  43. * @since 13.1
  44. */
  45. protected $changesets;
  46. /**
  47. * Openstreetmap API object for elements.
  48. *
  49. * @var JOpenstreetmapElements
  50. * @since 13.1
  51. */
  52. protected $elements;
  53. /**
  54. * Openstreetmap API object for GPS.
  55. *
  56. * @var JOpenstreetmapGps
  57. * @since 13.1
  58. */
  59. protected $gps;
  60. /**
  61. * Openstreetmap API object for info.
  62. *
  63. * @var JOpenstreetmapInfo
  64. * @since 13.1
  65. */
  66. protected $info;
  67. /**
  68. * Openstreetmap API object for user.
  69. *
  70. * @var JOpenstreetmapUser
  71. * @since 13.1
  72. */
  73. protected $user;
  74. /**
  75. * Constructor.
  76. *
  77. * @param JOpenstreetmapOauth $oauth Openstreetmap oauth client
  78. * @param Registry $options Openstreetmap options object
  79. * @param JHttp $client The HTTP client object
  80. *
  81. * @since 13.1
  82. */
  83. public function __construct(JOpenstreetmapOauth $oauth = null, Registry $options = null, JHttp $client = null)
  84. {
  85. $this->oauth = $oauth;
  86. $this->options = isset($options) ? $options : new Registry;
  87. $this->client = isset($client) ? $client : new JHttp($this->options);
  88. // Setup the default API url if not already set.
  89. $this->options->def('api.url', 'http://api.openstreetmap.org/api/0.6/');
  90. // $this->options->def('api.url', 'http://api06.dev.openstreetmap.org/api/0.6/');
  91. }
  92. /**
  93. * Method to get object instances
  94. *
  95. * @param string $name Name of property to retrieve
  96. *
  97. * @return JOpenstreetmapObject Openstreetmap API object
  98. *
  99. * @since 13.1
  100. * @throws InvalidArgumentException
  101. */
  102. public function __get($name)
  103. {
  104. $class = 'JOpenstreetmap' . ucfirst($name);
  105. if (class_exists($class))
  106. {
  107. if (false == isset($this->$name))
  108. {
  109. $this->$name = new $class($this->options, $this->client, $this->oauth);
  110. }
  111. return $this->$name;
  112. }
  113. throw new InvalidArgumentException(sprintf('Argument %s produced an invalid class name: %s', $name, $class));
  114. }
  115. /**
  116. * Get an option from the JOpenstreetmap instance.
  117. *
  118. * @param string $key The name of the option to get.
  119. *
  120. * @return mixed The option value.
  121. *
  122. * @since 13.1
  123. */
  124. public function getOption($key)
  125. {
  126. return $this->options->get($key);
  127. }
  128. /**
  129. * Set an option for the Openstreetmap instance.
  130. *
  131. * @param string $key The name of the option to set.
  132. * @param mixed $value The option value to set.
  133. *
  134. * @return JOpenstreetmap This object for method chaining.
  135. *
  136. * @since 13.1
  137. */
  138. public function setOption($key, $value)
  139. {
  140. $this->options->set($key, $value);
  141. return $this;
  142. }
  143. }