tablepress
/
libraries
/
vendor
/
PhpSpreadsheet
/
Style
/
ConditionalFormatting
/
Wizard
/
Expression.php
Expression.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/Expression.php
| 1 | <?php |
| 2 | |
| 3 | namespace TablePress\PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\Wizard; |
| 4 | |
| 5 | use TablePress\PhpOffice\PhpSpreadsheet\Exception; |
| 6 | use TablePress\PhpOffice\PhpSpreadsheet\Style\Conditional; |
| 7 | use TablePress\PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\Wizard; |
| 8 | |
| 9 | /** |
| 10 | * @method Expression formula(string $expression) |
| 11 | */ |
| 12 | class Expression extends WizardAbstract implements WizardInterface |
| 13 | { |
| 14 | protected string $expression; |
| 15 | |
| 16 | public function __construct(string $cellRange) |
| 17 | { |
| 18 | parent::__construct($cellRange); |
| 19 | } |
| 20 | |
| 21 | public function expression(string $expression): self |
| 22 | { |
| 23 | $expression = $this->validateOperand($expression, Wizard::VALUE_TYPE_FORMULA); |
| 24 | $this->expression = $expression; |
| 25 | |
| 26 | return $this; |
| 27 | } |
| 28 | |
| 29 | public function getConditional(): Conditional |
| 30 | { |
| 31 | /** @var string[] */ |
| 32 | $expression = $this->adjustConditionsForCellReferences([$this->expression]); |
| 33 | |
| 34 | $conditional = new Conditional(); |
| 35 | $conditional->setConditionType(Conditional::CONDITION_EXPRESSION); |
| 36 | $conditional->setConditions($expression); |
| 37 | $conditional->setStyle($this->getStyle()); |
| 38 | $conditional->setStopIfTrue($this->getStopIfTrue()); |
| 39 | |
| 40 | return $conditional; |
| 41 | } |
| 42 | |
| 43 | public static function fromConditional(Conditional $conditional, string $cellRange = 'A1'): WizardInterface |
| 44 | { |
| 45 | if ($conditional->getConditionType() !== Conditional::CONDITION_EXPRESSION) { |
| 46 | throw new Exception('Conditional is not an Expression CF Rule conditional'); |
| 47 | } |
| 48 | |
| 49 | $wizard = new self($cellRange); |
| 50 | $wizard->style = $conditional->getStyle(); |
| 51 | $wizard->stopIfTrue = $conditional->getStopIfTrue(); |
| 52 | $wizard->expression = self::reverseAdjustCellRef((string) ($conditional->getConditions()[0]), $cellRange); |
| 53 | |
| 54 | return $wizard; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @param string[] $arguments |
| 59 | */ |
| 60 | public function __call(string $methodName, array $arguments): self |
| 61 | { |
| 62 | if ($methodName !== 'formula') { |
| 63 | throw new Exception('Invalid Operation for Expression CF Rule Wizard'); |
| 64 | } |
| 65 | |
| 66 | $this->expression(...$arguments); |
| 67 | |
| 68 | return $this; |
| 69 | } |
| 70 | } |
| 71 |