Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Zend_Measure_Number Class Reference
Inheritance diagram for Zend_Measure_Number:
Zend_Measure_Abstract

Public Member Functions

 __construct ($value, $type, $locale=null)
 
 setValue ($value, $type=null, $locale=null)
 
 setType ($type)
 
 convertTo ($type, $round=0, $locale=null)
 
- Public Member Functions inherited from Zend_Measure_Abstract
 __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)
 

Data Fields

const STANDARD = 'DECIMAL'
 
const BINARY = 'BINARY'
 
const TERNARY = 'TERNARY'
 
const QUATERNARY = 'QUATERNARY'
 
const QUINARY = 'QUINARY'
 
const SENARY = 'SENARY'
 
const SEPTENARY = 'SEPTENARY'
 
const OCTAL = 'OCTAL'
 
const NONARY = 'NONARY'
 
const DECIMAL = 'DECIMAL'
 
const DUODECIMAL = 'DUODECIMAL'
 
const HEXADECIMAL = 'HEXADECIMAL'
 
const ROMAN = 'ROMAN'
 

Protected Attributes

 $_units
 
- Protected Attributes inherited from Zend_Measure_Abstract
 $_value
 
 $_type
 
 $_locale = null
 
 $_units = array()
 

Detailed Description

Definition at line 39 of file Number.php.

Constructor & Destructor Documentation

◆ __construct()

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

Zend_Measure_Abstract is an abstract class for the different measurement types

Parameters
integer$valueValue
string$type(Optional) A Zend_Measure_Number Type
string | Zend_Locale$locale(Optional) A Zend_Locale
Exceptions
Zend_Measure_ExceptionWhen language is unknown
Zend_Measure_ExceptionWhen type is unknown

Definition at line 145 of file Number.php.

146  {
147  if (($type !== null) and (Zend_Locale::isLocale($type, null, false))) {
148  $locale = $type;
149  $type = null;
150  }
151 
152  if ($locale === null) {
153  $locale = new Zend_Locale();
154  }
155 
156  if (!Zend_Locale::isLocale($locale, true, false)) {
157  if (!Zend_Locale::isLocale($locale, true, false)) {
158  #require_once 'Zend/Measure/Exception.php';
159  throw new Zend_Measure_Exception("Language (" . (string) $locale . ") is unknown");
160  }
161 
162  $locale = new Zend_Locale($locale);
163  }
164 
165  $this->_locale = (string) $locale;
166 
167  if ($type === null) {
168  $type = $this->_units['STANDARD'];
169  }
170 
171  if (isset($this->_units[$type]) === false) {
172  #require_once 'Zend/Measure/Exception.php';
173  throw new Zend_Measure_Exception("Type ($type) is unknown");
174  }
175 
176  $this->setValue($value, $type, $this->_locale);
177  }
$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: Number.php:187

Member Function Documentation

◆ convertTo()

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

Alias function for setType returning the converted unit Default is 0 as this class only handles numbers without precision

Parameters
string$typeType to convert to
integer$round(Optional) Precision to add, will always be 0
Returns
string

Definition at line 415 of file Number.php.

416  {
417  $this->setType($type);
418 
419  // Roman numerals do not need a formatting
420  if ($this->getType() === self::ROMAN) {
421  return $this->_value;
422  }
423 
424  return $this->toString($round, $locale);
425  }
toString($round=-1, $locale=null)
Definition: Abstract.php:326
$type
Definition: item.phtml:13

◆ setType()

setType (   $type)

Set a new type, and convert the value

Parameters
string$typeNew type to set
Exceptions
Zend_Measure_ExceptionWhen a unknown type is given
Returns
void

Definition at line 393 of file Number.php.

394  {
395  if (empty($this->_units[$type]) === true) {
396  #require_once 'Zend/Measure/Exception.php';
397  throw new Zend_Measure_Exception('Unknown type of number:' . $type);
398  }
399 
400  $value = $this->_toDecimal($this->getValue(-1), $this->getType(-1));
401  $value = $this->_fromDecimal($value, $type);
402 
403  $this->_value = $value;
404  $this->_type = $type;
405  }
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16
getValue($round=-1, $locale=null)
Definition: Abstract.php:155

◆ setValue()

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

Set a new value

Parameters
integer$valueValue
string$type(Optional) A Zend_Measure_Number Type
string | Zend_Locale$locale(Optional) A Zend_Locale Type
Exceptions
Zend_Measure_Exception

Definition at line 187 of file Number.php.

188  {
189  if (empty($locale)) {
190  $locale = $this->_locale;
191  }
192 
193  if (empty($this->_units[$type])) {
194  #require_once 'Zend/Measure/Exception.php';
195  throw new Zend_Measure_Exception('unknown type of number:' . $type);
196  }
197 
198  switch($type) {
199  case 'BINARY':
200  preg_match('/[01]+/', $value, $ergebnis);
201  $value = $ergebnis[0];
202  break;
203 
204  case 'TERNARY':
205  preg_match('/[012]+/', $value, $ergebnis);
206  $value = $ergebnis[0];
207  break;
208 
209  case 'QUATERNARY':
210  preg_match('/[0123]+/', $value, $ergebnis);
211  $value = $ergebnis[0];
212  break;
213 
214  case 'QUINARY':
215  preg_match('/[01234]+/', $value, $ergebnis);
216  $value = $ergebnis[0];
217  break;
218 
219  case 'SENARY':
220  preg_match('/[012345]+/', $value, $ergebnis);
221  $value = $ergebnis[0];
222  break;
223 
224  case 'SEPTENARY':
225  preg_match('/[0123456]+/', $value, $ergebnis);
226  $value = $ergebnis[0];
227  break;
228 
229  case 'OCTAL':
230  preg_match('/[01234567]+/', $value, $ergebnis);
231  $value = $ergebnis[0];
232  break;
233 
234  case 'NONARY':
235  preg_match('/[012345678]+/', $value, $ergebnis);
236  $value = $ergebnis[0];
237  break;
238 
239  case 'DUODECIMAL':
240  preg_match('/[0123456789AB]+/', strtoupper($value), $ergebnis);
241  $value = $ergebnis[0];
242  break;
243 
244  case 'HEXADECIMAL':
245  preg_match('/[0123456789ABCDEF]+/', strtoupper($value), $ergebnis);
246  $value = $ergebnis[0];
247  break;
248 
249  case 'ROMAN':
250  preg_match('/[IVXLCDM_]+/', strtoupper($value), $ergebnis);
251  $value = $ergebnis[0];
252  break;
253 
254  default:
255  try {
256  $value = Zend_Locale_Format::getInteger($value, array('locale' => $locale));
257  } catch (Exception $e) {
258  #require_once 'Zend/Measure/Exception.php';
259  throw new Zend_Measure_Exception($e->getMessage(), $e->getCode(), $e);
260  }
263  }
264  break;
265  }
266 
267  $this->_value = $value;
268  $this->_type = $type;
269  }
static $comp
Definition: Math.php:45
static $sqrt
Definition: Math.php:46
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16
static getInteger($input, array $options=array())
Definition: Format.php:694
static $pow
Definition: Math.php:42

Field Documentation

◆ $_units

$_units
protected
Initial value:
= array(
'BINARY' => array(2, '⑵'),
'TERNARY' => array(3, '⑶'),
'QUATERNARY' => array(4, '⑷'),
'QUINARY' => array(5, '⑸'),
'SENARY' => array(6, '⑹'),
'SEPTENARY' => array(7, '⑺'),
'OCTAL' => array(8, '⑻'),
'NONARY' => array(9, '⑼'),
'DECIMAL' => array(10, '⑽'),
'DUODECIMAL' => array(12, '⑿'),
'HEXADECIMAL' => array(16, '⒃'),
'ROMAN' => array(99, ''),
'STANDARD' => 'DECIMAL'
)

Definition at line 61 of file Number.php.

◆ BINARY

const BINARY = 'BINARY'

Definition at line 43 of file Number.php.

◆ DECIMAL

const DECIMAL = 'DECIMAL'

Definition at line 51 of file Number.php.

◆ DUODECIMAL

const DUODECIMAL = 'DUODECIMAL'

Definition at line 52 of file Number.php.

◆ HEXADECIMAL

const HEXADECIMAL = 'HEXADECIMAL'

Definition at line 53 of file Number.php.

◆ NONARY

const NONARY = 'NONARY'

Definition at line 50 of file Number.php.

◆ OCTAL

const OCTAL = 'OCTAL'

Definition at line 49 of file Number.php.

◆ QUATERNARY

const QUATERNARY = 'QUATERNARY'

Definition at line 45 of file Number.php.

◆ QUINARY

const QUINARY = 'QUINARY'

Definition at line 46 of file Number.php.

◆ ROMAN

const ROMAN = 'ROMAN'

Definition at line 54 of file Number.php.

◆ SENARY

const SENARY = 'SENARY'

Definition at line 47 of file Number.php.

◆ SEPTENARY

const SEPTENARY = 'SEPTENARY'

Definition at line 48 of file Number.php.

◆ STANDARD

const STANDARD = 'DECIMAL'

Definition at line 41 of file Number.php.

◆ TERNARY

const TERNARY = 'TERNARY'

Definition at line 44 of file Number.php.


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