Zend_Measure-Introduction.xml 2.7 KB

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