[TASK] Update php-cs-fixer to 2.5.0
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Be / Security / IfAuthenticatedViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Be\Security;
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
17 /**
18 * This view helper implements an ifAuthenticated/else condition for BE users/groups.
19 *
20 * = Examples =
21 *
22 * <code title="Basic usage">
23 * <f:be.security.ifAuthenticated>
24 * This is being shown whenever a BE user is logged in
25 * </f:be.security.ifAuthenticated>
26 * </code>
27 * <output>
28 * Everything inside the <f:be.ifAuthenticated> tag is being displayed if you are authenticated with any BE user account.
29 * </output>
30 *
31 * <code title="IfAuthenticated / then / else">
32 * <f:be.security.ifAuthenticated>
33 * <f:then>
34 * This is being shown in case you have access.
35 * </f:then>
36 * <f:else>
37 * This is being displayed in case you do not have access.
38 * </f:else>
39 * </f:be.security.ifAuthenticated>
40 * </code>
41 * <output>
42 * Everything inside the "then" tag is displayed if you have access.
43 * Otherwise, everything inside the "else"-tag is displayed.
44 * </output>
45 *
46 * @api
47 */
48 class IfAuthenticatedViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper
49 {
50 /**
51 * This method decides if the condition is TRUE or FALSE. It can be overridden in extending viewhelpers to adjust functionality.
52 *
53 * @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
54 * @return bool
55 */
56 protected static function evaluateCondition($arguments = null)
57 {
58 return isset($GLOBALS['BE_USER']) && $GLOBALS['BE_USER']->user['uid'] > 0;
59 }
60
61 /**
62 * @return mixed
63 */
64 public function render()
65 {
66 if (static::evaluateCondition($this->arguments)) {
67 return $this->renderThenChild();
68 }
69 return $this->renderElseChild();
70 }
71 }