File_Therion_DataTypes
[ class tree: File_Therion_DataTypes ] [ index: File_Therion_DataTypes ] [ all elements ]

Class: File_Therion_Unit

Source Location: /File_Therion-0.4.1/File/Therion/DataTypes/Unit.php

Class Overview

File_Therion_DataType
   |
   --File_Therion_Unit

Class representing a therion untit object.


Author(s):

Copyright:

  • 2016 Benedikt Hallinger

Variables

Methods


Inherited Variables

Inherited Methods

Class: File_Therion_DataType

File_Therion_DataType::parse()
Parse string content into this datatype
File_Therion_DataType::toString()
Get string representation
File_Therion_DataType::__toString()
Magic __toString() method calls toString().

Class Details

[line 33]
Class representing a therion untit object.

From thbook: length units supported: meter[s], centimeter[s], inch[es], feet[s], yard[s] (also m, cm, in, ft, yd). Angle units supported: degree[s], minute[s] (also deg, min), grad[s], mil[s], percent[age] (clino only). A degree value may be entered in decimal notation (x.y) or in a special notation for degrees, minutes and seconds (deg[:min[:sec]]).



[ Top ]


Class Variables

$quantity =  null

[line 42]

Units quantity
  • Access: protected

Type:   null|float


[ Top ]

$type =  ""

[line 49]

Units type
  • Access: protected

Type:   string


[ Top ]



Method Detail

__construct (Constructor)   [line 113]

File_Therion_Unit __construct( string $quantity, string $type)

Create a new therion unit instance.

When $quantity is NULL, it is only initialized to the type specified. Use this in cases where only the unit itself is interesting. toString() will return only the type in this case.

  • Access: public

Parameters:

string   $quantity   —  Ammount of unit, eg. "123"
string   $type   —  Type, eg. "meter"

[ Top ]

convertTo   [line 251]

void convertTo( string|File_Therion_Unit $typeP)

Convert this unit into another one.

Converts the quantity of this unit into the type specified. If you want to preserve this object, make a copy beforehand!

  • Todo: implement me please (grads/degrees currently raw implemented)
  • Throws: InvalidArgumentException when units are incompatible
  • Throws: File_Therion_Exception when type/alias is not known.
  • Access: public

Parameters:

string|File_Therion_Unit   $typeP   —  target type

[ Top ]

float2string   [line 348]

string float2string( float $floatval)

Normalize float values to therion compatible value.

The representation of float values is dependent on the locale in use. Some locales (de_AT for instance) use comma as float point separator. Also, some locales use a thousands separator.

This method converts a float value to a therion compatible string, which is dot as separator and an empty thousands sign.

  • Access: public

Parameters:

float   $floatval   — 

[ Top ]

getClass   [line 391]

string getClass( )

Gets class of this units instance type ("angle" or "length")
  • Return: "angle" or "length"
  • Access: public

[ Top ]

getQuantity   [line 199]

float|null getQuantity( )

Get this unit instances quantity.
  • Return: null in case unit was only initialized to type
  • Access: public

[ Top ]

getType   [line 230]

string getType( [boolean $normalize = false])

Get type of this unit instance.
  • Return: type name
  • Access: public

Parameters:

boolean   $normalize   —  if TRUE, return unaliased name

[ Top ]

getUnitClass   [line 377]

string getUnitClass( string $type)

Gets class of unit type ("angle" or "length").

If you want to get the class of the current instance, try getClass() instead.

  • Return: "angle" or "length"
  • Access: public

Parameters:

string   $type   —  type name

[ Top ]

parse   [line 152]

File_Therion_Unit parse( $string $string)

Parse string content into this datatype.
  • Return: crafted object
  • Access: public

Overrides File_Therion_DataType::parse() (Parse string content into this datatype)

Parameters:

$string   $string   —  data to parse

[ Top ]

setQuantity   [line 182]

void setQuantity( null|string $quantity)

Set quantity of this instance.

When $quantity is NULL, only unit type is considered.

  • Todo: support special notation for deg/min/seconds (deg[:min[:sec]])
  • Todo: check snytax
  • Access: public

Parameters:

null|string   $quantity   —  Ammount of unit, eg. "123"

[ Top ]

setType   [line 216]

void setType( string $type)

Set type of this unit instance.

Note that therion does not allow unit types to be uppercased (e.g. "Meters" is an error).

If you want to unalias an manually given aliased type, use

  1. $unit->setType($unit->getType(true));

  • Throws: File_Therion_Exception when type/alias is not known.
  • Access: public

Parameters:

string   $type   —  Type of unit, eg. "meters"

[ Top ]

toString   [line 126]

Therion toString( [boolean $normalize = false])

Get string representation
  • Return: compliant String of this unit instance ("1.5 meter")
  • Access: public

Overrides File_Therion_DataType::toString() (Get string representation)

Parameters:

boolean   $normalize   —  if TRUE, return unaliased name

[ Top ]

unalias   [line 318]

string unalias( $type)

Get unaliased name for aliased type ("m" -> "meter")
  • Throws: File_Therion_Exception when type/alias is not known.
  • Access: public

Parameters:

   $type   — 

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:09:46 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.