ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Indirect.php
Go to the documentation of this file.
1<?php
2
4
5use Exception;
10
12{
19 private static function a1Format($a1fmt): bool
20 {
21 $a1fmt = Functions::flattenSingleValue($a1fmt);
22 if ($a1fmt === null) {
24 }
25 if (is_string($a1fmt)) {
26 throw new Exception(Functions::VALUE());
27 }
28
29 return (bool) $a1fmt;
30 }
31
37 private static function validateAddress($cellAddress): string
38 {
39 $cellAddress = Functions::flattenSingleValue($cellAddress);
40 if (!is_string($cellAddress) || !$cellAddress) {
41 throw new Exception(Functions::REF());
42 }
43
44 return $cellAddress;
45 }
46
63 public static function INDIRECT($cellAddress, $a1fmt, Cell $pCell)
64 {
65 try {
66 $a1 = self::a1Format($a1fmt);
67 $cellAddress = self::validateAddress($cellAddress);
68 } catch (Exception $e) {
69 return $e->getMessage();
70 }
71
72 [$cellAddress, $pSheet, $sheetName] = Helpers::extractWorksheet($cellAddress, $pCell);
73
74 [$cellAddress1, $cellAddress2, $cellAddress] = Helpers::extractCellAddresses($cellAddress, $a1, $pCell->getWorkSheet(), $sheetName);
75
76 if (
77 (!preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellAddress1, $matches)) ||
78 (($cellAddress2 !== null) && (!preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellAddress2, $matches)))
79 ) {
80 return Functions::REF();
81 }
82
83 return self::extractRequiredCells($pSheet, $cellAddress);
84 }
85
92 private static function extractRequiredCells(?Worksheet $pSheet, string $cellAddress)
93 {
94 return Calculation::getInstance($pSheet !== null ? $pSheet->getParent() : null)
95 ->extractCellRange($cellAddress, $pSheet, false);
96 }
97}
An exception for terminatinating execution or to throw for unit testing.
static getInstance(?Spreadsheet $spreadsheet=null)
Get an instance of this class.
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649
static extractCellAddresses(string $cellAddress, bool $a1, Worksheet $sheet, string $sheetName='')
Definition: Helpers.php:38
static extractWorksheet(string $cellAddress, Cell $pCell)
Definition: Helpers.php:60
static extractRequiredCells(?Worksheet $pSheet, string $cellAddress)
Extract range values.
Definition: Indirect.php:92
static a1Format($a1fmt)
Determine whether cell address is in A1 (true) or R1C1 (false) format.
Definition: Indirect.php:19
static validateAddress($cellAddress)
Convert cellAddress to string, verify not null string.
Definition: Indirect.php:37
static INDIRECT($cellAddress, $a1fmt, Cell $pCell)
INDIRECT.
Definition: Indirect.php:63