[BUGFIX] Fix isMissing called on Null error
[Packages/TYPO3.CMS.git] / typo3 / sysext / linkvalidator / Classes / Linktype / FileLinktype.php
1 <?php
2 namespace TYPO3\CMS\Linkvalidator\Linktype;
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\Core\Resource\Exception\FileDoesNotExistException;
18 use TYPO3\CMS\Core\Resource\Exception\FolderDoesNotExistException;
19 use TYPO3\CMS\Core\Resource\ResourceFactory;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 /**
23 * This class provides Check File Links plugin implementation
24 */
25 class FileLinktype extends AbstractLinktype
26 {
27 /**
28 * Type fetching method, based on the type that softRefParserObj returns
29 *
30 * @param array $value Reference properties
31 * @param string $type Current type
32 * @param string $key Validator hook name
33 * @return string fetched type
34 */
35 public function fetchType($value, $type, $key)
36 {
37 if (strpos(strtolower($value['tokenValue']), 'file:') === 0) {
38 $type = 'file';
39 }
40 return $type;
41 }
42
43 /**
44 * Checks a given URL + /path/filename.ext for validity
45 *
46 * @param string $url Url to check
47 * @param array $softRefEntry The soft reference entry which builds the context of the url
48 * @param \TYPO3\CMS\Linkvalidator\LinkAnalyzer $reference Parent instance
49 * @return bool TRUE on success or FALSE on error
50 */
51 public function checkLink($url, $softRefEntry, $reference)
52 {
53 $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
54 try {
55 $file = $resourceFactory->retrieveFileOrFolderObject($url);
56 } catch (FileDoesNotExistException $e) {
57 return false;
58 } catch (FolderDoesNotExistException $e) {
59 return false;
60 }
61
62 return ($file !== null) ? !$file->isMissing() : false;
63 }
64
65 /**
66 * Generate the localized error message from the error params saved from the parsing
67 *
68 * @param array $errorParams All parameters needed for the rendering of the error message
69 * @return string Validation error message
70 */
71 public function getErrorMessage($errorParams)
72 {
73 return $this->getLanguageService()->getLL('list.report.filenotexisting');
74 }
75
76 /**
77 * Construct a valid Url for browser output
78 *
79 * @param array $row Broken link record
80 * @return string Parsed broken url
81 */
82 public function getBrokenUrl($row)
83 {
84 return GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . $row['url'];
85 }
86 }