[!!!][TASK] Rewrite install tool
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / FolderStructure / RootNode.php
1 <?php
2 namespace TYPO3\CMS\Install\FolderStructure;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 use TYPO3\CMS\Install\Status;
28
29 /**
30 * Root node of structure
31 */
32 class RootNode extends DirectoryNode implements RootNodeInterface {
33
34 /**
35 * Implement constructor
36 *
37 * @param array $structure Given structure
38 * @param NodeInterface $parent Must be NULL for RootNode
39 * @throws Exception\RootNodeException
40 * @throws Exception\InvalidArgumentException
41 */
42 public function __construct(array $structure, NodeInterface $parent = NULL) {
43 if (!is_null($parent)) {
44 throw new \TYPO3\CMS\Install\FolderStructure\Exception\RootNodeException(
45 'Root node must not have parent',
46 1366140117
47 );
48 }
49
50 if (!isset($structure['name'])
51 || ($this->isWindowsOs() && substr($structure['name'], 1, 2) !== ':/')
52 || (!$this->isWindowsOs() && substr($structure['name'], 0, 1) !== '/')
53 ) {
54 throw new \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException(
55 'Root node expects absolute path as name',
56 1366141329
57 );
58 }
59 $this->name = $structure['name'];
60
61 if (isset($structure['targetPermission'])) {
62 $this->targetPermission = $structure['targetPermission'];
63 }
64
65 if (array_key_exists('children', $structure)) {
66 $this->createChildren($structure['children']);
67 }
68 }
69
70 /**
71 * Get own status and status of child objects - Root node gives error status if not exists
72 *
73 * @return array<\TYPO3\CMS\Install\Status\StatusInterface>
74 */
75 public function getStatus() {
76 $result = array();
77 if (!$this->exists()) {
78 $status = new Status\ErrorStatus();
79 $status->setTitle($this->getAbsolutePath() . ' does not exist');
80 $result[] = $status;
81 } else {
82 $result[] = $this->getSelfStatus();
83 }
84 $result = array_merge($result, $this->getChildrenStatus());
85 return $result;
86 }
87
88 /**
89 * Root node does not call parent, but returns own name only
90 *
91 * @return string Absolute path
92 */
93 public function getAbsolutePath() {
94 return $this->name;
95 }
96 }
97 ?>