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