convert() публичный Метод

Converts a length object of one unit into another unit.
public convert ( HTMLPurifier_Length $length, string $to_unit ) : HTMLPurifier_Length | boolean
$length HTMLPurifier_Length Instance of HTMLPurifier_Length to convert. You must validate() it before passing it here!
$to_unit string Unit to convert to.
Результат HTMLPurifier_Length | boolean
Пример #1
0
 protected function assertConversion($input, $expect, $unit = null, $test_negative = true)
 {
     $length = HTMLPurifier_Length::make($input);
     if ($expect !== false) {
         $expectl = HTMLPurifier_Length::make($expect);
     } else {
         $expectl = false;
     }
     $to_unit = $unit !== null ? $unit : $expectl->getUnit();
     $converter = new HTMLPurifier_UnitConverter(4, 10);
     $result = $converter->convert($length, $to_unit);
     if (!$result || !$expectl) {
         $this->assertIdentical($result, $expectl);
     } else {
         $this->assertIdentical($result->toString(), $expectl->toString());
     }
     $converter = new HTMLPurifier_UnitConverter(4, 10, true);
     $result = $converter->convert($length, $to_unit);
     if (!$result || !$expectl) {
         $this->assertIdentical($result, $expectl);
     } else {
         $this->assertIdentical($result->toString(), $expectl->toString(), 'BCMath substitute: %s');
     }
     if ($test_negative) {
         $this->assertConversion("-{$input}", $expect === false ? false : "-{$expect}", $unit, false);
     }
 }
 /**
  * Compares two lengths, and returns 1 if greater, -1 if less and 0 if equal.
  * @param HTMLPurifier_Length $l
  * @return int
  * @warning If both values are too large or small, this calculation will
  *          not work properly
  */
 public function compareTo($l)
 {
     if ($l === false) {
         return false;
     }
     if ($l->unit !== $this->unit) {
         $converter = new HTMLPurifier_UnitConverter();
         $l = $converter->convert($l, $this->unit);
         if ($l === false) {
             return false;
         }
     }
     return $this->n - $l->n;
 }