45c900d7a0d247ee7d67c61910fc9aeee98796f3
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / ViewHelpers / File / ExistsViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Install\ViewHelpers\File;
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 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
18 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
19
20 /**
21 * Simple view helper to check if given file is a regular file
22 *
23 * = Examples =
24 *
25 * <code title="Default">
26 * <f:file.exists file="Absolute-path" />
27 * </code>
28 *
29 * <output>
30 * TRUE or FALSE
31 * </output>
32 *
33 * @internal
34 */
35 class ExistsViewHelper extends AbstractViewHelper
36 {
37 /**
38 * Check if given file is a regular file
39 *
40 * @param string $file Absolute path
41 * @return bool
42 */
43 public function render($file)
44 {
45 return static::renderStatic(
46 array(
47 'file' => $file,
48 ),
49 $this->buildRenderChildrenClosure(),
50 $this->renderingContext
51 );
52 }
53
54 /**
55 * @param array $arguments
56 * @param \Closure $renderChildrenClosure
57 * @param RenderingContextInterface $renderingContext
58 *
59 * @return bool
60 */
61 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
62 {
63 $file = $arguments['file'];
64
65 $result = false;
66 if (file_exists($file) && is_file($file)) {
67 $result = true;
68 }
69 return $result;
70 }
71 }