|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2013-2015 2amigOS! Consulting Group LLC |
|
4
|
|
|
* @link http://2amigos.us |
|
5
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace dosamigos\leaflet\plugins\awesome; |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
use dosamigos\leaflet\Plugin; |
|
11
|
|
|
use yii\web\JsExpression; |
|
12
|
|
|
use yii\helpers\Json; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* AwesomeMarker allows to create map icons using FontAwesome Icons. |
|
16
|
|
|
* |
|
17
|
|
|
* Font awesome files are required to be installed |
|
18
|
|
|
* |
|
19
|
|
|
* @see https://github.com/lvoogdt/Leaflet.awesome-markers |
|
20
|
|
|
* @author Antonio Ramirez <[email protected]> |
|
21
|
|
|
* @link http://www.ramirezcobos.com/ |
|
22
|
|
|
* @link http://www.2amigos.us/ |
|
23
|
|
|
* @package dosamigos\leaflet\plugins\awesome |
|
24
|
|
|
*/ |
|
25
|
|
|
class AwesomeMarker extends Plugin |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var string the icon name |
|
29
|
|
|
* @see https://github.com/lvoogdt/Leaflet.awesome-markers#properties |
|
30
|
|
|
*/ |
|
31
|
|
|
public $icon; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Generates the code to generate a maki marker. Helper method made for speed purposes. |
|
35
|
|
|
* |
|
36
|
|
|
* @param string $icon the icon name |
|
37
|
|
|
* @param array $options the maki marker icon |
|
38
|
|
|
* |
|
39
|
|
|
* @return string the resulting js code |
|
40
|
|
|
*/ |
|
41
|
3 |
|
public function make($icon, $options = []) |
|
42
|
|
|
{ |
|
43
|
3 |
|
$options['icon'] = $icon; |
|
44
|
3 |
|
$options = Json::encode($options); |
|
45
|
3 |
|
return new JsExpression("L.AwesomeMarkers.icon($options)"); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Returns the plugin name |
|
50
|
|
|
* @return string |
|
51
|
|
|
*/ |
|
52
|
3 |
|
public function getPluginName() |
|
53
|
|
|
{ |
|
54
|
3 |
|
return 'plugin:awesomemarker'; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Registers plugin asset bundle |
|
59
|
|
|
* |
|
60
|
|
|
* @param \yii\web\View $view |
|
61
|
|
|
* |
|
62
|
|
|
* @return mixed |
|
63
|
|
|
* @codeCoverageIgnore |
|
64
|
|
|
*/ |
|
65
|
|
|
public function registerAssetBundle($view) |
|
66
|
|
|
{ |
|
67
|
|
|
AwesomeMarkerAsset::register($view); |
|
68
|
|
|
return $this; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Returns the javascript ready code for the object to render |
|
73
|
|
|
* @return \yii\web\JsExpression |
|
74
|
|
|
*/ |
|
75
|
3 |
|
public function encode() |
|
76
|
|
|
{ |
|
77
|
3 |
|
$icon = $this->icon; |
|
78
|
|
|
|
|
79
|
3 |
|
if (empty($icon)) { |
|
80
|
3 |
|
return ""; |
|
|
|
|
|
|
81
|
|
|
} |
|
82
|
3 |
|
$this->clientOptions['icon'] = $icon; |
|
83
|
3 |
|
$options = $this->getOptions(); |
|
84
|
3 |
|
$name = $this->getName(); |
|
85
|
|
|
|
|
86
|
3 |
|
$js = "L.AwesomeMarkers.icon($options)"; |
|
87
|
|
|
|
|
88
|
3 |
|
if (!empty($name)) { |
|
89
|
3 |
|
$js = "var $name = $js;"; |
|
90
|
3 |
|
} |
|
91
|
|
|
|
|
92
|
3 |
|
return new JsExpression($js); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.