Zend_Measure-Introduction.xml 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.measure.introduction">
  4. <title>Introduction</title>
  5. <para>
  6. <classname>Zend_Measure_*</classname> classes provide a generic and easy way for working with measurements. Using
  7. <classname>Zend_Measure_*</classname> classes, you can convert measurements into different units of the same type. They
  8. can be added, subtracted and compared against each other. From a given input made in the user's native language,
  9. the unit of measurement can be automatically extracted. Numerous units of measurement are supported.
  10. </para>
  11. <example id="zend.measure.introduction.example-1">
  12. <title>Converting measurements</title>
  13. <para>
  14. The following introductory example shows automatic conversion of units of measurement. To convert a
  15. measurement, its value and its type have to be known. The value can be an integer, a float, or even a string
  16. containing a number. Conversions are only possible for units of the same type (mass, area, temperature,
  17. velocity, etc.), not between types.
  18. </para>
  19. <programlisting language="php"><![CDATA[
  20. $locale = new Zend_Locale('en');
  21. $unit = new Zend_Measure_Length(100, Zend_Measure_Length::METER, $locale);
  22. // Convert meters to yards
  23. echo $unit->convertTo(Zend_Measure_Length::YARD);
  24. ]]></programlisting>
  25. </example>
  26. <para>
  27. <classname>Zend_Measure_*</classname> includes support for many different units of measurement. The units of measurement
  28. all have a unified notation: <classname>Zend_Measure_&lt;TYPE&gt;::NAME_OF_UNIT</classname>, where &lt;TYPE&gt;
  29. corresponds to a well-known physical or numerical property. . Every unit of measurement consists of a conversion
  30. factor and a display unit. A detailed list can be found in the chapter
  31. <link linkend="zend.measure.types"><code>Types of measurements</code>
  32. </link>
  33. .
  34. </para>
  35. <example id="zend.measure.introduction.example-2">
  36. <title>The meter measurement</title>
  37. <para>
  38. The <code>meter</code> is used for measuring lengths, so its type constant can be found in the
  39. <code>Length</code> class. To refer to this unit of measurement, the notation <constant>Length::METER</constant>
  40. must be used. The display unit is <code>m</code>.
  41. </para>
  42. <programlisting language="php"><![CDATA[
  43. echo Zend_Measure_Length::STANDARD; // outputs 'Length::METER'
  44. echo Zend_Measure_Length::KILOMETER; // outputs 'Length::KILOMETER'
  45. $unit = new Zend_Measure_Length(100,'METER');
  46. echo $unit;
  47. // outputs '100 m'
  48. ]]></programlisting>
  49. </example>
  50. </sect1>
  51. <!--
  52. vim:se ts=4 sw=4 et:
  53. -->