PathExpander::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Knp\RadBundle\Filesystem;
4
5
use Symfony\Component\HttpKernel\KernelInterface;
6
7
class PathExpander
8
{
9
    private $kernel;
10
11
    public function __construct(KernelInterface $kernel)
12
    {
13
        $this->kernel = $kernel;
14
    }
15
16
    /**
17
     * Expands the given path if needed (i.e bundle resource path)
18
     *
19
     * @param string $path The path to expand
20
     *
21
     * @return string The expanded path
22
     */
23
    public function expand($path)
24
    {
25
        if (0 !== strpos($path, '@')) {
26
            return $path;
27
        }
28
29
        list($bundleName, $relPath) = explode('/', substr($path, 1), 2);
30
31
        $bundle = $this->kernel->getBundle($bundleName);
32
33
        return sprintf('%s/%s', $bundle->getPath(), $relPath);
34
    }
35
}
36