示例#1
0
 /**
  * Validates the node for correctness.
  *
  * The following options are supported:
  *   - Node::REPAIR - If something is broken, and automatic repair may
  *                    be attempted.
  *
  * An array is returned with warnings.
  *
  * Every item in the array has the following properties:
  *    * level - (number between 1 and 3 with severity information)
  *    * message - (human readable message)
  *    * node - (reference to the offending node)
  *
  * @param int $options
  * @return array
  */
 public function validate($options = 0)
 {
     $warnings = parent::validate($options);
     if (isset($this->minimumPropertyValues[$this->name])) {
         $minimum = $this->minimumPropertyValues[$this->name];
         $parts = $this->getParts();
         if (count($parts) < $minimum) {
             $warnings[] = array('level' => 1, 'message' => 'This property must have at least ' . $minimum . ' components. It only has ' . count($parts), 'node' => $this);
             if ($options & self::REPAIR) {
                 $parts = array_pad($parts, $minimum, '');
                 $this->setParts($parts);
             }
         }
     }
     return $warnings;
 }
 /**
  * Validates the node for correctness.
  *
  * The following options are supported:
  *   Node::REPAIR - May attempt to automatically repair the problem.
  *
  * This method returns an array with detected problems.
  * Every element has the following properties:
  *
  *  * level - problem level.
  *  * message - A human-readable string describing the issue.
  *  * node - A reference to the problematic node.
  *
  * The level means:
  *   1 - The issue was repaired (only happens if REPAIR was turned on)
  *   2 - An inconsequential issue
  *   3 - A severe issue.
  *
  * @param int $options
  * @return array
  */
 public function validate($options = 0)
 {
     $messages = parent::validate($options);
     $value = $this->getValue();
     try {
         DateTimeParser::parseVCardDateTime($value);
     } catch (\InvalidArgumentException $e) {
         $messages[] = array('level' => 3, 'message' => 'The supplied value (' . $value . ') is not a correct DATE-AND-OR-TIME property', 'node' => $this);
     }
     return $messages;
 }
示例#3
0
 /**
  * Validates the node for correctness.
  *
  * The following options are supported:
  *   Node::REPAIR - May attempt to automatically repair the problem.
  *
  * This method returns an array with detected problems.
  * Every element has the following properties:
  *
  *  * level - problem level.
  *  * message - A human-readable string describing the issue.
  *  * node - A reference to the problematic node.
  *
  * The level means:
  *   1 - The issue was repaired (only happens if REPAIR was turned on)
  *   2 - An inconsequential issue
  *   3 - A severe issue.
  *
  * @param int $options
  *
  * @return array
  */
 function validate($options = 0)
 {
     $messages = parent::validate($options);
     $valueType = $this->getValueType();
     $values = $this->getParts();
     try {
         foreach ($values as $value) {
             switch ($valueType) {
                 case 'DATE':
                     DateTimeParser::parseDate($value);
                     break;
                 case 'DATE-TIME':
                     DateTimeParser::parseDateTime($value);
                     break;
             }
         }
     } catch (InvalidDataException $e) {
         $messages[] = ['level' => 3, 'message' => 'The supplied value (' . $value . ') is not a correct ' . $valueType, 'node' => $this];
     }
     return $messages;
 }
示例#4
0
 /**
  * Validates the node for correctness.
  *
  * The following options are supported:
  *   Node::REPAIR - May attempt to automatically repair the problem.
  *
  * This method returns an array with detected problems.
  * Every element has the following properties:
  *
  *  * level - problem level.
  *  * message - A human-readable string describing the issue.
  *  * node - A reference to the problematic node.
  *
  * The level means:
  *   1 - The issue was repaired (only happens if REPAIR was turned on)
  *   2 - An inconsequential issue
  *   3 - A severe issue.
  *
  * @param int $options
  * @return array
  */
 public function validate($options = 0)
 {
     $messages = parent::validate($options);
     $valueType = $this->getValueType();
     $value = $this->getValue();
     try {
         switch ($valueType) {
             case 'DATE':
                 $foo = DateTimeParser::parseDate($value);
                 break;
             case 'DATE-TIME':
                 $foo = DateTimeParser::parseDateTime($value);
                 break;
         }
     } catch (\LogicException $e) {
         $messages[] = array('level' => 3, 'message' => 'The supplied value (' . $value . ') is not a correct ' . $valueType, 'node' => $this);
     }
     return $messages;
 }
示例#5
0
 /**
  * Validates the node for correctness.
  *
  * The following options are supported:
  *   Node::REPAIR - May attempt to automatically repair the problem.
  *
  * This method returns an array with detected problems.
  * Every element has the following properties:
  *
  *  * level - problem level.
  *  * message - A human-readable string describing the issue.
  *  * node - A reference to the problematic node.
  *
  * The level means:
  *   1 - The issue was repaired (only happens if REPAIR was turned on)
  *   2 - An inconsequential issue
  *   3 - A severe issue.
  *
  * @param int $options
  *
  * @return array
  */
 function validate($options = 0)
 {
     $repair = $options & self::REPAIR;
     $warnings = parent::validate($options);
     $values = $this->getParts();
     foreach ($values as $key => $value) {
         if ($value === '') {
             $warnings[] = ['level' => $repair ? 1 : 3, 'message' => 'Invalid value for ' . $key . ' in ' . $this->name, 'node' => $this];
             if ($repair) {
                 unset($values[$key]);
             }
         } elseif ($key == 'BYMONTH') {
             $byMonth = (array) $value;
             foreach ($byMonth as $i => $v) {
                 if (!is_numeric($v) || (int) $v < 1 || (int) $v > 12) {
                     $warnings[] = ['level' => $repair ? 1 : 3, 'message' => 'BYMONTH in RRULE must have value(s) between 1 and 12!', 'node' => $this];
                     if ($repair) {
                         if (is_array($value)) {
                             unset($values[$key][$i]);
                         } else {
                             unset($values[$key]);
                         }
                     }
                 }
             }
         }
     }
     if (!isset($values['FREQ'])) {
         $warnings[] = ['level' => $repair ? 1 : 3, 'message' => 'FREQ is required in ' . $this->name, 'node' => $this];
         if ($repair) {
             $this->parent->remove($this);
         }
     }
     if ($repair) {
         $this->setValue($values);
     }
     return $warnings;
 }
示例#6
0
 /**
  * Validates the node for correctness.
  *
  * The following options are supported:
  *   Node::REPAIR - May attempt to automatically repair the problem.
  *
  * This method returns an array with detected problems.
  * Every element has the following properties:
  *
  *  * level - problem level.
  *  * message - A human-readable string describing the issue.
  *  * node - A reference to the problematic node.
  *
  * The level means:
  *   1 - The issue was repaired (only happens if REPAIR was turned on)
  *   2 - An inconsequential issue
  *   3 - A severe issue.
  *
  * @param int $options
  *
  * @return array
  */
 function validate($options = 0)
 {
     $repair = $options & self::REPAIR;
     $warnings = parent::validate($options);
     $values = $this->getParts();
     foreach ($values as $key => $value) {
         if (empty($value)) {
             $warnings[] = ['level' => $repair ? 3 : 1, 'message' => 'Invalid value for ' . $key . ' in ' . $this->name, 'node' => $this];
             if ($repair) {
                 unset($values[$key]);
             }
         }
     }
     if (!isset($values['FREQ'])) {
         $warnings[] = ['level' => $repair ? 3 : 1, 'message' => 'FREQ is required in ' . $this->name, 'node' => $this];
         if ($repair) {
             $this->parent->remove($this);
         }
     }
     if ($repair) {
         $this->setValue($values);
     }
     return $warnings;
 }