wpdatatables
/
lib
/
phpoffice
/
phpspreadsheet
/
src
/
PhpSpreadsheet
/
Writer
/
Xls
/
ConditionalHelper.php
ConditionalHelper.php in wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin 6.5.1.7, at lib/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xls/ConditionalHelper.php
| 1 | <?php |
| 2 | |
| 3 | namespace PhpOffice\PhpSpreadsheet\Writer\Xls; |
| 4 | |
| 5 | use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; |
| 6 | use PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\Wizard; |
| 7 | |
| 8 | class ConditionalHelper |
| 9 | { |
| 10 | /** |
| 11 | * Formula parser. |
| 12 | * |
| 13 | * @var Parser |
| 14 | */ |
| 15 | protected $parser; |
| 16 | |
| 17 | /** |
| 18 | * @var mixed |
| 19 | */ |
| 20 | protected $condition; |
| 21 | |
| 22 | /** |
| 23 | * @var string |
| 24 | */ |
| 25 | protected $cellRange; |
| 26 | |
| 27 | /** |
| 28 | * @var null|string |
| 29 | */ |
| 30 | protected $tokens; |
| 31 | |
| 32 | /** |
| 33 | * @var int |
| 34 | */ |
| 35 | protected $size; |
| 36 | |
| 37 | public function __construct(Parser $parser) |
| 38 | { |
| 39 | $this->parser = $parser; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @param mixed $condition |
| 44 | */ |
| 45 | public function processCondition($condition, string $cellRange): void |
| 46 | { |
| 47 | $this->condition = $condition; |
| 48 | $this->cellRange = $cellRange; |
| 49 | |
| 50 | if (is_int($condition) || is_float($condition)) { |
| 51 | $this->size = ($condition <= 65535 ? 3 : 0x0000); |
| 52 | $this->tokens = pack('Cv', 0x1E, $condition); |
| 53 | } else { |
| 54 | try { |
| 55 | $formula = Wizard\WizardAbstract::reverseAdjustCellRef((string) $condition, $cellRange); |
| 56 | $this->parser->parse($formula); |
| 57 | $this->tokens = $this->parser->toReversePolish(); |
| 58 | $this->size = strlen($this->tokens ?? ''); |
| 59 | } catch (PhpSpreadsheetException $e) { |
| 60 | // In the event of a parser error with a formula value, we set the expression to ptgInt + 0 |
| 61 | $this->tokens = pack('Cv', 0x1E, 0); |
| 62 | $this->size = 3; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | public function tokens(): ?string |
| 68 | { |
| 69 | return $this->tokens; |
| 70 | } |
| 71 | |
| 72 | public function size(): int |
| 73 | { |
| 74 | return $this->size; |
| 75 | } |
| 76 | } |
| 77 |