1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Nip Framework |
5
|
|
|
* |
6
|
|
|
* @category Nip |
7
|
|
|
* @copyright 2009 Nip Framework |
8
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
class Nip_Service_Maps { |
|
|
|
|
12
|
|
|
|
13
|
|
|
protected $_api_key; |
14
|
|
|
protected $_provider; |
15
|
|
|
protected $_providerObj; |
16
|
|
|
|
17
|
|
|
protected $_params = []; |
18
|
|
|
protected $_objects = []; |
19
|
|
|
|
20
|
|
|
public function __construct() { |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function __call($name, $arguments) { |
24
|
|
|
if (strpos($name, 'render') === 0) { |
25
|
|
|
return call_user_func_array(array($this->getProvider(), $name), $arguments); |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return Nip_Service_Maps_Provider_Abstract |
31
|
|
|
*/ |
32
|
|
|
public function getProvider() |
33
|
|
|
{ |
34
|
|
|
if (!$this->_providerObj) { |
35
|
|
|
$this->initProvider(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return $this->_providerObj; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function setProvider($name) { |
42
|
|
|
$this->_provider = $name; |
43
|
|
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function initProvider() { |
47
|
|
|
if ($this->_provider) { |
48
|
|
|
$class = 'Nip_Service_Maps_Provider_' . ucfirst($this->_provider); |
49
|
|
|
$this->_providerObj = new $class(); |
50
|
|
|
$this->_providerObj->setService($this); |
51
|
|
|
return true; |
52
|
|
|
} |
53
|
|
|
trigger_error('No provider set for ' . get_class($this)); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getApiKey() |
57
|
|
|
{ |
58
|
|
|
return $this->_api_key; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function setApiKey($key) |
62
|
|
|
{ |
63
|
|
|
$this->_api_key = $key; |
64
|
|
|
|
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function addObject(Nip_Service_Maps_Objects_Abstract $object) { |
69
|
|
|
$this->_objects[] = $object; |
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getNewObject($name) { |
74
|
|
|
$name = 'Nip_Service_Maps_Objects_' . ucfirst($name); |
75
|
|
|
$object = new $name(); |
76
|
|
|
$object->setService($this); |
77
|
|
|
return $object; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getObjects() { |
81
|
|
|
return $this->_objects; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function setParam($key, $value) { |
85
|
|
|
$this->_params[$key] = $value; |
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function getParam($key) { |
90
|
|
|
return $this->_params[$key]; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function render() { |
94
|
|
|
return $this->getProvider()->render(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.