ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PhpOffice\PhpSpreadsheet\Cell\DataValidator Class Reference

Validate a cell value according to its validation rules. More...

+ Collaboration diagram for PhpOffice\PhpSpreadsheet\Cell\DataValidator:

Public Member Functions

 isValid (Cell $cell)
 Does this cell contain valid value? More...
 

Private Member Functions

 isValueInList (Cell $cell)
 Does this cell contain valid value, based on list? More...
 

Detailed Description

Validate a cell value according to its validation rules.

Definition at line 12 of file DataValidator.php.

Member Function Documentation

◆ isValid()

PhpOffice\PhpSpreadsheet\Cell\DataValidator::isValid ( Cell  $cell)

Does this cell contain valid value?

Parameters
Cell$cellCell to check the value
Returns
bool

Definition at line 21 of file DataValidator.php.

References PhpOffice\PhpSpreadsheet\Cell\Cell\getDataValidation(), PhpOffice\PhpSpreadsheet\Cell\Cell\getValue(), PhpOffice\PhpSpreadsheet\Cell\Cell\hasDataValidation(), PhpOffice\PhpSpreadsheet\Cell\DataValidator\isValueInList(), and PhpOffice\PhpSpreadsheet\Cell\DataValidation\TYPE_LIST.

22  {
23  if (!$cell->hasDataValidation()) {
24  return true;
25  }
26 
27  $cellValue = $cell->getValue();
28  $dataValidation = $cell->getDataValidation();
29 
30  if (!$dataValidation->getAllowBlank() && ($cellValue === null || $cellValue === '')) {
31  return false;
32  }
33 
34  // TODO: write check on all cases
35  switch ($dataValidation->getType()) {
37  return $this->isValueInList($cell);
38  }
39 
40  return false;
41  }
isValueInList(Cell $cell)
Does this cell contain valid value, based on list?
+ Here is the call graph for this function:

◆ isValueInList()

PhpOffice\PhpSpreadsheet\Cell\DataValidator::isValueInList ( Cell  $cell)
private

Does this cell contain valid value, based on list?

Parameters
Cell$cellCell to check the value
Returns
bool

Definition at line 50 of file DataValidator.php.

References $result, PhpOffice\PhpSpreadsheet\Cell\Cell\getCoordinate(), PhpOffice\PhpSpreadsheet\Cell\Cell\getDataValidation(), PhpOffice\PhpSpreadsheet\Calculation\Calculation\getInstance(), PhpOffice\PhpSpreadsheet\Cell\Cell\getValue(), PhpOffice\PhpSpreadsheet\Cell\Cell\getWorksheet(), and PhpOffice\PhpSpreadsheet\Calculation\Functions\NA().

Referenced by PhpOffice\PhpSpreadsheet\Cell\DataValidator\isValid().

51  {
52  $cellValue = $cell->getValue();
53  $dataValidation = $cell->getDataValidation();
54 
55  $formula1 = $dataValidation->getFormula1();
56  if (!empty($formula1)) {
57  // inline values list
58  if ($formula1[0] === '"') {
59  return in_array(strtolower($cellValue), explode(',', strtolower(trim($formula1, '"'))), true);
60  } elseif (strpos($formula1, ':') > 0) {
61  // values list cells
62  $matchFormula = '=MATCH(' . $cell->getCoordinate() . ', ' . $formula1 . ', 0)';
63  $calculation = Calculation::getInstance($cell->getWorksheet()->getParent());
64 
65  try {
66  $result = $calculation->calculateFormula($matchFormula, $cell->getCoordinate(), $cell);
67 
68  return $result !== Functions::NA();
69  } catch (Exception $ex) {
70  return false;
71  }
72  }
73  }
74 
75  return true;
76  }
$result
static getInstance(?Spreadsheet $spreadsheet=null)
Get an instance of this class.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: