Completed
Push — master ( 7f2d14...7fc8f2 )
by Fabien
02:11
created

ExtensionManagementUtility::siteRelPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
namespace Fab\Vidi\Utility;
3
4
/*
5
 * This file is part of the Fab/Vidi project under GPLv2 or later.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.md file that was distributed with this source code.
9
 */
10
11
use TYPO3\CMS\Core\Core\Environment;
12
13
/**
14
 * Extension Management functions
15
 *
16
 * This class is never instantiated, rather the methods inside is called as functions like
17
 * \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('my_extension');
18
 */
19
class ExtensionManagementUtility
20
{
21
    /**
22
     * Returns the relative path to the extension as measured from the public web path
23
     * If the extension is not loaded the function will die with an error message
24
     * Useful for images and links from the frontend
25
     *
26
     * @param string $key Extension key
27
     * @return string
28
     */
29
    public static function siteRelPath($key)
30
    {
31
        return self::stripPathSitePrefix(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($key));
32
    }
33
34
    /**
35
     * Strip first part of a path, equal to the length of public web path including trailing slash
36
     *
37
     * @param string $path
38
     * @return string
39
     * @internal
40
     */
41
    public static function stripPathSitePrefix($path)
42
    {
43
        return substr($path, strlen(Environment::getPublicPath() . '/'));
44
    }
45
46
}
47