forked from pablodip/PablodipModuleBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleNameParser.php
More file actions
62 lines (53 loc) · 1.61 KB
/
Copy pathModuleNameParser.php
File metadata and controls
62 lines (53 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/*
* This file is part of the PablodipModuleBundle package.
*
* (c) Pablo Díez <pablodip@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Pablodip\ModuleBundle\Module;
use Symfony\Component\HttpKernel\KernelInterface;
/**
* Converts a short notation "PablodipBlogModuleBundle:Blog" to
* the full class: "Pablodip\PablodipBlogModuleBundle\Module\BlogModule".
*
* @author Pablo Díez <pablodip@gmail.com>
*/
class ModuleNameParser implements ModuleNameParserInterface
{
/**
* Constructor.
*
* @param KernelInterface $kernel A KernelInterface instance.
*/
public function __construct(KernelInterface $kernel)
{
$this->kernel = $kernel;
}
/**
* {@inheritdoc}
*/
public function parse($module)
{
if (2 !== count($parts = explode(':', $module))) {
throw new \InvalidArgumentException(sprintf('The "%s" module is not a valid a:b module string.', $module));
}
list($bundle, $module) = $parts;
$module = str_replace('/', '\\', $module);
$class = null;
$logs = array();
foreach ($this->kernel->getBundle($bundle, false) as $b) {
$try = $b->getNamespace().'\\Module\\'.$module.'Module';
if (class_exists($try)) {
$class = $try;
break;
}
}
if (null === $class) {
throw new \InvalidArgumentException(sprintf('Unable to find module "%s:%s".', $bundle, $module));
}
return $class;
}
}