Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Zend_Measure_Abstract Class Reference
Inheritance diagram for Zend_Measure_Abstract:
Zend_Measure_Acceleration Zend_Measure_Angle Zend_Measure_Area Zend_Measure_Binary Zend_Measure_Capacitance Zend_Measure_Cooking_Volume Zend_Measure_Cooking_Weight Zend_Measure_Current Zend_Measure_Density Zend_Measure_Energy Zend_Measure_Flow_Mass Zend_Measure_Flow_Mole Zend_Measure_Flow_Volume Zend_Measure_Force Zend_Measure_Frequency Zend_Measure_Illumination Zend_Measure_Length Zend_Measure_Lightness Zend_Measure_Number Zend_Measure_Power Zend_Measure_Pressure Zend_Measure_Speed Zend_Measure_Temperature Zend_Measure_Time Zend_Measure_Torque Zend_Measure_Viscosity_Dynamic Zend_Measure_Viscosity_Kinematic Zend_Measure_Volume Zend_Measure_Weight

Public Member Functions

 __construct ($value, $type=null, $locale=null)
 
 getLocale ()
 
 setLocale ($locale=null, $check=false)
 
 getValue ($round=-1, $locale=null)
 
 setValue ($value, $type=null, $locale=null)
 
 getType ()
 
 setType ($type)
 
 equals ($object)
 
 toString ($round=-1, $locale=null)
 
 __toString ()
 
 getConversionList ()
 
 convertTo ($type, $round=2, $locale=null)
 
 add ($object)
 
 sub ($object)
 
 compare ($object)
 

Protected Attributes

 $_value
 
 $_type
 
 $_locale = null
 
 $_units = array()
 

Detailed Description

Definition at line 46 of file Abstract.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $value,
  $type = null,
  $locale = null 
)

Zend_Measure_Abstract is an abstract class for the different measurement types

Parameters
mixed$valueValue as string, integer, real or float
int$typeOPTIONAL a measure type f.e. Zend_Measure_Length::METER
Zend_Locale$localeOPTIONAL a Zend_Locale Type
Exceptions
Zend_Measure_Exception

Definition at line 82 of file Abstract.php.

83  {
84  if (($type !== null) and (Zend_Locale::isLocale($type, null, false))) {
85  $locale = $type;
86  $type = null;
87  }
88 
89  $this->setLocale($locale);
90  if ($type === null) {
91  $type = $this->_units['STANDARD'];
92  }
93 
94  if (isset($this->_units[$type]) === false) {
95  #require_once 'Zend/Measure/Exception.php';
96  throw new Zend_Measure_Exception("Type ($type) is unknown");
97  }
98 
99  $this->setValue($value, $type, $this->_locale);
100  }
setLocale($locale=null, $check=false)
Definition: Abstract.php:119
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16
static isLocale($locale, $strict=false, $compatible=true)
Definition: Locale.php:1683
setValue($value, $type=null, $locale=null)
Definition: Abstract.php:180

Member Function Documentation

◆ __toString()

__toString ( )

Returns a string representation

Returns
string

Definition at line 340 of file Abstract.php.

341  {
342  return $this->toString();
343  }
toString($round=-1, $locale=null)
Definition: Abstract.php:326

◆ add()

add (   $object)

Adds an unit to another one

Parameters
Zend_Measure_Abstract$objectobject of same unit type
Returns
Zend_Measure_Abstract

Definition at line 375 of file Abstract.php.

376  {
377  $object->setType($this->getType());
378  $value = $this->getValue(-1) + $object->getValue(-1);
379 
380  $this->setValue($value, $this->getType(), $this->_locale);
381  return $this;
382  }
$value
Definition: gender.phtml:16
getValue($round=-1, $locale=null)
Definition: Abstract.php:155
setValue($value, $type=null, $locale=null)
Definition: Abstract.php:180

◆ compare()

compare (   $object)

Compares two units

Parameters
Zend_Measure_Abstract$objectobject of same unit type
Returns
boolean

Definition at line 405 of file Abstract.php.

406  {
407  $object->setType($this->getType());
408  $value = $this->getValue(-1) - $object->getValue(-1);
409 
410  if ($value < 0) {
411  return -1;
412  } else if ($value > 0) {
413  return 1;
414  }
415 
416  return 0;
417  }
$value
Definition: gender.phtml:16
getValue($round=-1, $locale=null)
Definition: Abstract.php:155

◆ convertTo()

convertTo (   $type,
  $round = 2,
  $locale = null 
)

Alias function for setType returning the converted unit

Parameters
string$typeConstant Type
integer$round(Optional) Rounds the value to a given precision
string | Zend_Locale$locale(Optional) Locale to set for the number
Returns
string

Definition at line 363 of file Abstract.php.

364  {
365  $this->setType($type);
366  return $this->toString($round, $locale);
367  }
toString($round=-1, $locale=null)
Definition: Abstract.php:326
$type
Definition: item.phtml:13

◆ equals()

equals (   $object)

Compare if the value and type is equal

Parameters
Zend_Measure_Abstract$objectobject to compare
Returns
boolean

Definition at line 310 of file Abstract.php.

311  {
312  if ((string) $object == $this->toString()) {
313  return true;
314  }
315 
316  return false;
317  }
toString($round=-1, $locale=null)
Definition: Abstract.php:326

◆ getConversionList()

getConversionList ( )

Returns the conversion list

Returns
array

Definition at line 350 of file Abstract.php.

351  {
352  return $this->_units;
353  }

◆ getLocale()

getLocale ( )

Returns the actual set locale

Returns
string

Definition at line 107 of file Abstract.php.

108  {
109  return $this->_locale;
110  }

◆ getType()

getType ( )

Returns the original type

Returns
type

Definition at line 218 of file Abstract.php.

219  {
220  return $this->_type;
221  }

◆ getValue()

getValue (   $round = -1,
  $locale = null 
)

Returns the internal value

Parameters
integer$round(Optional) Rounds the value to an given precision, Default is -1 which returns without rounding
string | Zend_Locale$locale(Optional) Locale for number representation
Returns
integer|string

Definition at line 155 of file Abstract.php.

156  {
157  if ($round < 0) {
158  $return = $this->_value;
159  } else {
160  $return = Zend_Locale_Math::round($this->_value, $round);
161  }
162 
163  if ($locale !== null) {
164  $this->setLocale($locale, true);
165  return Zend_Locale_Format::toNumber($return, array('locale' => $locale));
166  }
167 
168  return $return;
169  }
setLocale($locale=null, $check=false)
Definition: Abstract.php:119
static toNumber($value, array $options=array())
Definition: Format.php:300
static round($op1, $precision=0)
Definition: Math.php:65

◆ setLocale()

setLocale (   $locale = null,
  $check = false 
)

Sets a new locale for the value representation

Parameters
string | Zend_Locale$locale(Optional) New locale to set
boolean$checkFalse, check but don't set; True, set the new locale
Returns
Zend_Measure_Abstract

Definition at line 119 of file Abstract.php.

120  {
121  if (empty($locale)) {
122  #require_once 'Zend/Registry.php';
123  if (Zend_Registry::isRegistered('Zend_Locale') === true) {
124  $locale = Zend_Registry::get('Zend_Locale');
125  }
126  }
127 
128  if ($locale === null) {
129  $locale = new Zend_Locale();
130  }
131 
132  if (!Zend_Locale::isLocale($locale, true, false)) {
133  if (!Zend_Locale::isLocale($locale, false, false)) {
134  #require_once 'Zend/Measure/Exception.php';
135  throw new Zend_Measure_Exception("Language (" . (string) $locale . ") is unknown");
136  }
137 
138  $locale = new Zend_Locale($locale);
139  }
140 
141  if (!$check) {
142  $this->_locale = (string) $locale;
143  }
144  return $this;
145  }
static isRegistered($index)
Definition: Registry.php:178
static isLocale($locale, $strict=false, $compatible=true)
Definition: Locale.php:1683
static get($index)
Definition: Registry.php:141

◆ setType()

setType (   $type)

Set a new type, and convert the value

Parameters
string$typeNew type to set
Exceptions
Zend_Measure_Exception
Returns
Zend_Measure_Abstract

Definition at line 230 of file Abstract.php.

231  {
232  if (empty($this->_units[$type])) {
233  #require_once 'Zend/Measure/Exception.php';
234  throw new Zend_Measure_Exception("Type ($type) is unknown");
235  }
236 
237  if (empty($this->_type)) {
238  $this->_type = $type;
239  } else {
240  // Convert to standard value
242  if (is_array($this->_units[$this->getType()][0])) {
243  foreach ($this->_units[$this->getType()][0] as $key => $found) {
244  switch ($key) {
245  case "/":
246  if ($found != 0) {
248  }
249  break;
250  case "+":
252  break;
253  case "-":
255  break;
256  default:
258  break;
259  }
260  }
261  } else {
262  $value = call_user_func(Zend_Locale_Math::$mul, $value, $this->_units[$this->getType()][0], 25);
263  }
264 
265  // Convert to expected value
266  if (is_array($this->_units[$type][0])) {
267  foreach (array_reverse($this->_units[$type][0]) as $key => $found) {
268  switch ($key) {
269  case "/":
271  break;
272  case "+":
274  break;
275  case "-":
277  break;
278  default:
279  if ($found != 0) {
281  }
282  break;
283  }
284  }
285  } else {
286  $value = call_user_func(Zend_Locale_Math::$div, $value, $this->_units[$type][0], 25);
287  }
288 
289  $slength = strlen($value);
290  $length = 0;
291  for($i = 1; $i <= $slength; ++$i) {
292  if ($value[$slength - $i] != '0') {
293  $length = 26 - $i;
294  break;
295  }
296  }
297 
298  $this->_value = Zend_Locale_Math::round($value, $length);
299  $this->_type = $type;
300  }
301  return $this;
302  }
static $sub
Definition: Math.php:41
static $mul
Definition: Math.php:43
static $add
Definition: Math.php:40
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16
static $div
Definition: Math.php:44
static round($op1, $precision=0)
Definition: Math.php:65
$i
Definition: gallery.phtml:31

◆ setValue()

setValue (   $value,
  $type = null,
  $locale = null 
)

Set a new value

Parameters
integer | string$valueValue as string, integer, real or float
string$typeOPTIONAL A measure type f.e. Zend_Measure_Length::METER
string | Zend_Locale$localeOPTIONAL Locale for parsing numbers
Exceptions
Zend_Measure_Exception
Returns
Zend_Measure_Abstract

Definition at line 180 of file Abstract.php.

181  {
182  if (($type !== null) and (Zend_Locale::isLocale($type, null, false))) {
183  $locale = $type;
184  $type = null;
185  }
186 
187  if ($locale === null) {
188  $locale = $this->_locale;
189  }
190 
191  $this->setLocale($locale, true);
192  if ($type === null) {
193  $type = $this->_units['STANDARD'];
194  }
195 
196  if (empty($this->_units[$type])) {
197  #require_once 'Zend/Measure/Exception.php';
198  throw new Zend_Measure_Exception("Type ($type) is unknown");
199  }
200 
201  try {
202  $value = Zend_Locale_Format::getNumber($value, array('locale' => $locale));
203  } catch(Exception $e) {
204  #require_once 'Zend/Measure/Exception.php';
205  throw new Zend_Measure_Exception($e->getMessage(), $e->getCode(), $e);
206  }
207 
208  $this->_value = $value;
209  $this->setType($type);
210  return $this;
211  }
setLocale($locale=null, $check=false)
Definition: Abstract.php:119
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16
static isLocale($locale, $strict=false, $compatible=true)
Definition: Locale.php:1683
static getNumber($input, array $options=array())
Definition: Format.php:246

◆ sub()

sub (   $object)

Substracts an unit from another one

Parameters
Zend_Measure_Abstract$objectobject of same unit type
Returns
Zend_Measure_Abstract

Definition at line 390 of file Abstract.php.

391  {
392  $object->setType($this->getType());
393  $value = $this->getValue(-1) - $object->getValue(-1);
394 
395  $this->setValue($value, $this->getType(), $this->_locale);
396  return $this;
397  }
$value
Definition: gender.phtml:16
getValue($round=-1, $locale=null)
Definition: Abstract.php:155
setValue($value, $type=null, $locale=null)
Definition: Abstract.php:180

◆ toString()

toString (   $round = -1,
  $locale = null 
)

Returns a string representation

Parameters
integer$round(Optional) Runds the value to an given exception
string | Zend_Locale$locale(Optional) Locale to set for the number
Returns
string

Definition at line 326 of file Abstract.php.

327  {
328  if ($locale === null) {
329  $locale = $this->_locale;
330  }
331 
332  return $this->getValue($round, $locale) . ' ' . $this->_units[$this->getType()][1];
333  }
getValue($round=-1, $locale=null)
Definition: Abstract.php:155

Field Documentation

◆ $_locale

string $_locale = null
protected

Locale identifier

Definition at line 67 of file Abstract.php.

◆ $_type

string $_type
protected

Original type for this unit

Definition at line 60 of file Abstract.php.

◆ $_units

$_units = array()
protected

Unit types for this measurement

Definition at line 72 of file Abstract.php.

◆ $_value

string $_value
protected

Plain value in standard unit

Definition at line 53 of file Abstract.php.


The documentation for this class was generated from the following file: