Completed
Push — fetcher_factories ( 10a56f...fd93ea )
by David
13:44
created

MoufExplorerUrlProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 42
c 2
b 0
f 0
wmc 4
lcom 0
cbo 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getUrlsList() 0 19 3
A getExpirationTag() 0 4 1
1
<?php
2
3
namespace Mouf\Mvc\Splash\Services;
4
5
use Mouf\MoufManager;
6
7
/**
8
 * This class scans the Mouf container in order to find all UrlProviderInterface instances.
9
 * Use it to discover instances.
10
 */
11
class MoufExplorerUrlProvider implements UrlProviderInterface
12
{
13
    /**
14
     * Returns the list of URLs that can be accessed, and the function/method that should be called when the URL is called.
15
     *
16
     * @param string $instanceName The identifier for this object in the container.
17
     *
18
     * @return SplashRoute[]
19
     */
20
    public function getUrlsList($instanceName)
21
    {
22
        $moufManager = MoufManager::getMoufManager();
23
        $instanceNames = $moufManager->findInstances('Mouf\\Mvc\\Splash\\Services\\UrlProviderInterface');
24
25
        $urls = array();
26
27
        foreach ($instanceNames as $instanceName) {
28
            $urlProvider = $moufManager->getInstance($instanceName);
29
            /* @var $urlProvider UrlProviderInterface */
30
            if ($urlProvider === $this) {
31
                continue;
32
            }
33
            $tmpUrlList = $urlProvider->getUrlsList($instanceName);
34
            $urls = array_merge($urls, $tmpUrlList);
35
        }
36
37
        return $urls;
38
    }
39
40
    /**
41
     * Returns a unique tag representing the list of SplashRoutes returned.
42
     * If the tag changes, the cache is flushed by Splash.
43
     *
44
     * Important! This must be quick to compute.
45
     *
46
     * @return mixed
47
     */
48
    public function getExpirationTag() : string
49
    {
50
        return filemtime(__DIR__.'/../../../../../../../../mouf/MoufComponents.php');
51
    }
52
}
53