Source for file Length.php

Documentation is available at Length.php

  1. <?php
  2.  
  3. /**
  4.  * Represents a Length as defined by CSS.
  5.  */
  6. {
  7.     
  8.     protected $min$max;
  9.     
  10.     /**
  11.      * @param HTMLPurifier_Length $max Minimum length, or null for no bound. String is also acceptable.
  12.      * @param HTMLPurifier_Length $max Maximum length, or null for no bound. String is also acceptable.
  13.      */
  14.     public function __construct($min null$max null{
  15.         $this->min = $min !== null HTMLPurifier_Length::make($minnull;
  16.         $this->max = $max !== null HTMLPurifier_Length::make($maxnull;
  17.     }
  18.     
  19.     public function validate($string$config$context{
  20.         $string $this->parseCDATA($string);
  21.         
  22.         // Optimizations
  23.         if ($string === ''return false;
  24.         if ($string === '0'return '0';
  25.         if (strlen($string=== 1return false;
  26.         
  27.         $length HTMLPurifier_Length::make($string);
  28.         if (!$length->isValid()) return false;
  29.         
  30.         if ($this->min{
  31.             $c $length->compareTo($this->min);
  32.             if ($c === falsereturn false;
  33.             if ($c 0return false;
  34.         }
  35.         if ($this->max{
  36.             $c $length->compareTo($this->max);
  37.             if ($c === falsereturn false;
  38.             if ($c 0return false;
  39.         }
  40.         
  41.         return $length->toString();
  42.     }
  43.     
  44. }

Documentation generated on Thu, 19 Jun 2008 18:49:43 -0400 by phpDocumentor 1.4.2