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