forked from 2amigos/yii2-google-maps-library
/
Size.php
96 lines (87 loc) · 2.33 KB
/
Size.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* @copyright Copyright (c) 2014 2amigOS! Consulting Group LLC
* @link http://2amigos.us
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
*/
namespace dosamigos\google\maps;
use yii\base\InvalidConfigException;
use yii\base\Component;
/**
* Size
*
* Two-dimensional size, where width is the distance on the x-axis, and height is the distance on the y-axis.
*
* @author Antonio Ramirez <amigo.cobos@gmail.com>
* @link http://www.ramirezcobos.com/
* @link http://www.2amigos.us/
* @package dosamigos\google\maps
*/
class Size extends Component
{
/**
*
* The height along the y-axis, in pixels.
* @var integer height
*/
private $_height;
/**
*
* The width along the x-axis, in pixels.
* @var integer width
*/
private $_width;
/**
* @inheritdoc
* @throws \yii\base\InvalidConfigException
*/
public function init()
{
if (empty($this->_height) || empty($this->_width)) {
throw new InvalidConfigException('"width" and "height" cannot be null.');
}
if (!is_numeric($this->_height) || !is_numeric($this->_width)) {
throw new InvalidConfigException('"width" and "height" must be a numeric string or a number!');
}
parent::init();
}
/**
* Sets Height of the Size
* @param $value
* @throws \yii\base\InvalidConfigException
*/
public function setHeight($value)
{
if (!is_numeric($value)) {
throw new InvalidConfigException('"Height" must be a numeric string or a number!');
}
$this->_height = $value;
}
/**
* Sets the Width of the Size
* @param $value
* @throws \yii\base\InvalidConfigException
*/
public function setWidth($value)
{
if (!is_numeric($value)) {
throw new InvalidConfigException('"Width" must be a numeric string or a number!');
}
$this->_width = $value;
}
/**
*
* returns array representation of the size
*/
public function asArray()
{
return ['width' => $this->_width, 'height' => $this->_height];
}
/**
* @return string Javascript code to return the Size
*/
public function getJs()
{
return "new google.maps.Size({$this->_width}, {$this->_height})";
}
}