‪TYPO3CMS  10.4
ArrayBrowser.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 
31 {
35  public ‪$expAll = false;
36 
42  public ‪$depthKeys = [];
43 
50  public ‪$searchKeys = [];
51 
58  public ‪$regexMode = 0;
59 
65  public ‪$searchKeysToo = true;
66 
70  protected ‪$uriBuilder;
71 
77  protected ‪$route;
78 
79  public function ‪__construct(‪Route ‪$route = null)
80  {
81  $this->route = ‪$route;
82  $this->uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
83  }
84 
96  public function ‪tree($array, $positionKey)
97  {
98  ‪$output = '<ul class="list-tree text-monospace">';
99  if ($positionKey) {
100  $positionKey .= '.';
101  }
102  foreach ($array as $key => $value) {
103  $key = (string)$key;
104  $depth = $positionKey . $key;
105  if (is_object($value) && !$value instanceof \Traversable) {
106  $value = (array)$value;
107  }
108  $isArray = is_iterable($value);
109  $isResult = (bool)$this->searchKeys[$depth];
110  $isExpanded = $isArray && (!empty($this->‪depthKeys[$depth]) || ‪$this->expAll);
111  ‪$output .= '<li' . ($isResult ? ' class="active"' : '') . '>';
112  ‪$output .= '<span class="list-tree-group">';
113  if ($isArray && !$this->expAll && $this->route) {
114  $goto = 'a' . substr(md5($depth), 0, 6);
115  ‪$output .= '<a class="list-tree-control' . ($isExpanded ? ' list-tree-control-open' : ' list-tree-control-closed') . '" id="' . $goto . '" href="' . htmlspecialchars((string)$this->uriBuilder->buildUriFromRoute($this->route->getOption('_identifier'), ['node' => [rawurldecode($depth) => $isExpanded ? 0 : 1]]) . '#' . $goto) . '"><i class="fa"></i></a> ';
116  }
117  ‪$output .= '<span class="list-tree-label">' . htmlspecialchars((string)$key) . '</span>';
118  if (!$isArray) {
119  ‪$output .= ' = <span class="list-tree-value">' . htmlspecialchars((string)$value) . '</span>';
120  }
121  ‪$output .= '</span>';
122  if ($isExpanded) {
123  ‪$output .= $this->‪tree(
124  $value,
125  $depth
126  );
127  }
128  ‪$output .= '</li>';
129  }
130  ‪$output .= '</ul>';
131  return ‪$output;
132  }
133 
144  public function ‪getSearchKeys($keyArr, $depth_in, $searchString, $keyArray)
145  {
146  if ($depth_in) {
147  $depth_in .= '.';
148  }
149  foreach ($keyArr as $key => $value) {
150  $depth = $depth_in . $key;
151  $deeper = is_array($keyArr[$key]);
152  if ($this->regexMode) {
153  if (
154  is_scalar($keyArr[$key]) && preg_match('/' . $searchString . '/', (string)$keyArr[$key])
155  || $this->searchKeysToo && preg_match('/' . $searchString . '/', (string)$key)
156  ) {
157  $this->searchKeys[$depth] = 1;
158  }
159  } else {
160  if (
161  is_scalar($keyArr[$key]) && stripos((string)$keyArr[$key], $searchString) !== false
162  || $this->searchKeysToo && stripos((string)$key, $searchString) !== false
163  ) {
164  $this->searchKeys[$depth] = 1;
165  }
166  }
167  if ($deeper) {
168  $cS = count($this->searchKeys);
169  $keyArray = $this->‪getSearchKeys($keyArr[$key], $depth, $searchString, $keyArray);
170  if ($cS != count($this->searchKeys)) {
171  $keyArray[$depth] = 1;
172  }
173  }
174  }
175  return $keyArray;
176  }
177 
185  public function ‪depthKeys($arr, $settings)
186  {
187  $tsbrArray = [];
188  foreach ($arr as $theK => $theV) {
189  $theKeyParts = explode('.', (string)$theK);
190  $depth = '';
191  $c = count($theKeyParts);
192  $a = 0;
193  foreach ($theKeyParts as $p) {
194  $a++;
195  $depth .= ($depth ? '.' : '') . $p;
196  $tsbrArray[$depth] = $c == $a ? $theV : 1;
197  }
198  }
199  // Modify settings
200  foreach ($tsbrArray as $theK => $theV) {
201  if ($theV) {
202  $settings[$theK] = 1;
203  } else {
204  unset($settings[$theK]);
205  }
206  }
207  return $settings;
208  }
209 }
‪TYPO3\CMS\Backend\View\ArrayBrowser\$searchKeys
‪array $searchKeys
Definition: ArrayBrowser.php:47
‪TYPO3\CMS\Backend\View\ArrayBrowser\depthKeys
‪array depthKeys($arr, $settings)
Definition: ArrayBrowser.php:178
‪TYPO3\CMS\Backend\View
Definition: ArrayBrowser.php:18
‪TYPO3\CMS\Backend\View\ArrayBrowser\$expAll
‪bool $expAll
Definition: ArrayBrowser.php:34
‪TYPO3\CMS\Backend\View\ArrayBrowser\$regexMode
‪int $regexMode
Definition: ArrayBrowser.php:54
‪TYPO3\CMS\Backend\Routing\Route
Definition: Route.php:24
‪TYPO3\CMS\Backend\View\ArrayBrowser\$route
‪Route null $route
Definition: ArrayBrowser.php:70
‪TYPO3\CMS\Backend\View\ArrayBrowser\$depthKeys
‪array $depthKeys
Definition: ArrayBrowser.php:40
‪TYPO3\CMS\Backend\View\ArrayBrowser
Definition: ArrayBrowser.php:31
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Backend\View\ArrayBrowser\tree
‪string tree($array, $positionKey)
Definition: ArrayBrowser.php:89
‪TYPO3\CMS\Backend\View\ArrayBrowser\__construct
‪__construct(Route $route=null)
Definition: ArrayBrowser.php:72
‪$output
‪$output
Definition: annotationChecker.php:119
‪TYPO3\CMS\Backend\View\ArrayBrowser\$searchKeysToo
‪bool $searchKeysToo
Definition: ArrayBrowser.php:60
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\View\ArrayBrowser\getSearchKeys
‪array getSearchKeys($keyArr, $depth_in, $searchString, $keyArray)
Definition: ArrayBrowser.php:137
‪TYPO3\CMS\Backend\View\ArrayBrowser\$uriBuilder
‪UriBuilder $uriBuilder
Definition: ArrayBrowser.php:64