TYPO3 CMS  TYPO3_6-2
LinkNode.php
Go to the documentation of this file.
1 <?php
3 
18 
22 class LinkNode extends AbstractNode implements NodeInterface {
23 
27  protected $target = '';
28 
36  public function __construct(array $structure, NodeInterface $parent = NULL) {
37  if (is_null($parent)) {
38  throw new \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException(
39  'Link node must have parent',
40  1380485700
41  );
42  }
43  $this->parent = $parent;
44 
45  // Ensure name is a single segment, but not a path like foo/bar or an absolute path /foo
46  if (strstr($structure['name'], '/') !== FALSE) {
47  throw new \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException(
48  'File name must not contain forward slash',
49  1380546061
50  );
51  }
52  $this->name = $structure['name'];
53 
54  if (isset($structure['target']) && strlen($structure['target']) > 0) {
55  $this->target = $structure['target'];
56  }
57  }
58 
67  public function getStatus() {
68  if ($this->isWindowsOs()) {
69  $status = new Status\InfoStatus();
70  $status->setTitle($this->getRelativePathBelowSiteRoot() . ' should be a link, but this support is incomplete for Windows.');
71  $status->setMessage(
72  'This node is not handled for Windows OS and should be checked manually.'
73  );
74  return array($status);
75  }
76 
77  if (!$this->exists()) {
78  $status = new Status\ErrorStatus();
79  $status->setTitle($this->getRelativePathBelowSiteRoot() . ' should be a link, but it does not exist');
80  $status->setMessage('Links cannot be fixed by this system');
81  return array($status);
82  }
83 
84  if (!$this->isLink()) {
85  $status = new Status\WarningStatus();
86  $status->setTitle('Path ' . $this->getRelativePathBelowSiteRoot() . ' is not a link');
87  $type = @filetype($this->getAbsolutePath());
88  if ($type) {
89  $status->setMessage(
90  'The target ' . $this->getRelativePathBelowSiteRoot() . ' should be a link,' .
91  ' but is of type ' . $type . '. This cannot be fixed automatically. Please investigate.'
92  );
93  } else {
94  $status->setMessage(
95  'The target ' . $this->getRelativePathBelowSiteRoot() . ' should be a file,' .
96  ' but is of unknown type, probably because an upper level directory does not exist. Please investigate.'
97  );
98  }
99  return array($status);
100  }
101 
102  if (!$this->isTargetCorrect()) {
103  $status = new Status\ErrorStatus();
104  $status->setTitle($this->getRelativePathBelowSiteRoot() . ' is a link, but link target is not as specified');
105  $status->setMessage(
106  'Link target should be ' . $this->getTarget() . ' but is ' . $this->getCurrentTarget()
107  );
108  return array($status);
109  }
110 
111  $status = new Status\OkStatus();
112  $message = 'Is a link';
113  if ($this->getTarget() !== '') {
114  $message .= ' and correctly points to target ' . $this->getTarget();
115  }
116  $status->setTitle($this->getRelativePathBelowSiteRoot());
117  $status->setMessage($message);
118  return array($status);
119  }
120 
128  public function fix() {
129  return array();
130  }
131 
137  protected function getTarget() {
138  return $this->target;
139  }
140 
147  protected function isLink() {
148  if (!$this->exists()) {
149  throw new \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException(
150  'Link does not exist',
151  1380556246
152  );
153  }
154  return @is_link($this->getAbsolutePath());
155  }
156 
163  protected function isTargetCorrect() {
164  if (!$this->exists()) {
165  throw new \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException(
166  'Link does not exist',
167  1380556245
168  );
169  }
170  if (!$this->isLink()) {
171  throw new \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException(
172  'Node is not a link',
173  1380556247
174  );
175  }
176 
177  $result = FALSE;
178  $expectedTarget = $this->getTarget();
179  if (empty($expectedTarget)) {
180  $result = TRUE;
181  } else {
182  $actualTarget = $this->getCurrentTarget();
183  if ($expectedTarget === rtrim($actualTarget, '/')) {
184  $result = TRUE;
185  }
186  }
187  return $result;
188  }
189 
195  protected function getCurrentTarget() {
196  return readlink($this->getAbsolutePath());
197  }
198 
199 }
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.