Completed
Pull Request — master (#165)
by Paul
03:21
created

AppFileLocator::getAppPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of the PPI Framework.
4
 *
5
 * @copyright  Copyright (c) 2012 Paul Dragoonis <[email protected]>
6
 * @license    http://opensource.org/licenses/mit-license.php MIT
7
 *
8
 * @link       http://www.ppi.io
9
 */
10
11
namespace PPI\Framework\Config;
12
13
use PPI\Framework\Module\ModuleManager;
14
15
/**
16
 * AppFileLocator uses ModuleManager to locate resources in modules.
17
 *
18
 * @author     Paul Dragoonis <[email protected]>
19
 * @author     Vítor Brandão <[email protected]>
20
 */
21
class AppFileLocator extends FileLocator
22
{
23
    protected $moduleManager;
24
    protected $path;
25
26
    /**
27
     * Constructor.
28
     *
29
     * @param ModuleManager $moduleManager A ModuleManager instance
30
     * @param null|string   $path          The path the global resource directory
31
     * @param array         $paths         An array of paths where to look for resources
32
     */
33
    public function __construct(ModuleManager $moduleManager, $path = null, array $paths = array())
34
    {
35
        $this->moduleManager = $moduleManager;
36
        if (null !== $path) {
37
            $this->path = $path;
38
            $paths[]    = $path;
39
        }
40
41
        parent::__construct($paths);
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function locate($file, $currentPath = null, $first = true)
48
    {
49
        if ('@' === $file[0]) {
50
            return $this->moduleManager->locateResource($file, $this->path, $first);
51
        }
52
53
        return parent::locate($file, $currentPath, $first);
54
    }
55
56
    /**
57
     * Returns the path to the app directory.
58
     *
59
     * @return string The path to the app directory.
60
     */
61
    public function getAppPath()
62
    {
63
        return $this->path;
64
    }
65
66
    /**
67
     * Returns an array of paths to modules.
68
     *
69
     * @return array An array of paths to each loaded module
70
     */
71 View Code Duplication
    public function getModulesPath()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
72
    {
73
        $paths = array();
74
        foreach ($this->moduleManager->getLoadedModules(true) as $module) {
75
            $paths[$module->getName()] = $module->getPath();
76
        }
77
78
        return $paths;
79
    }
80
}
81