TYPO3  7.6
install/Classes/View/JsonView.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Install\View;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 use TYPO3\CMS\Install\Status\Exception as StatusException;
20 
24 class JsonView extends AbstractView
25 {
29  public function render()
30  {
31  $renderedData = $this->variables;
32  if (isset($renderedData['status']) && is_array($renderedData['status'])) {
33  try {
34  $renderedData['status'] = $this->transformStatusMessagesToArray($renderedData['status']);
35  } catch (StatusException $e) {
36  $renderedData['status'] = array(array(
37  'severity' => 'error',
38  'title' => htmlspecialchars($e->getMessage())
39  ));
40  }
41  }
42 
43  return $renderedData;
44  }
45 
53  protected function transformStatusMessagesToArray(array $statusArray = array())
54  {
55  $result = array();
56  foreach ($statusArray as $status) {
57  if (!$status instanceof StatusInterface) {
58  throw new StatusException(
59  'Object must implement StatusInterface',
60  1381059600
61  );
62  }
63  $result[] = $this->transformStatusToArray($status);
64  }
65  return $result;
66  }
67 
75  public function transformStatusToArray(StatusInterface $status)
76  {
77  $arrayStatus = array();
78  $arrayStatus['severity'] = htmlspecialchars($status->getSeverity());
79  $arrayStatus['title'] = htmlspecialchars($status->getTitle());
80  $arrayStatus['message'] = htmlspecialchars($status->getMessage());
81  return $arrayStatus;
82  }
83 }