1
|
|
|
<?php |
2
|
|
|
namespace Mouf\Html\Utils\WebLibraryManager; |
3
|
|
|
|
4
|
|
|
use Mouf\Validator\MoufStaticValidatorInterface; |
5
|
|
|
use Mouf\Composer\ComposerService; |
6
|
|
|
use Mouf\Validator\MoufValidatorResult; |
7
|
|
|
use Mouf\MoufManager; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* This validator is in charge of checking that "component" packages have matching weblibraries |
11
|
|
|
* declared in Mouf. |
12
|
|
|
* |
13
|
|
|
* @author David Négrier |
14
|
|
|
*/ |
15
|
|
|
class WebLibraryManagerValidator implements MoufStaticValidatorInterface { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Runs the validation of the class. |
19
|
|
|
* Returns a MoufValidatorResult explaining the result. |
20
|
|
|
* |
21
|
|
|
* @return MoufValidatorResult |
22
|
|
|
*/ |
23
|
|
|
static function validateClass() { |
|
|
|
|
24
|
|
|
$composerService = new ComposerService(); |
25
|
|
|
$packages = $composerService->getLocalPackagesOrderedByDependencies(); |
26
|
|
|
|
27
|
|
|
$componentViolations = array(); |
28
|
|
|
$moufManager = MoufManager::getMoufManager(); |
29
|
|
|
|
30
|
|
|
foreach ($packages as $package) { |
31
|
|
|
/* @var $package PackageInterface */ |
32
|
|
|
if ($package->getType() == "component") { |
33
|
|
|
$extra = $package->getExtra(); |
34
|
|
|
|
35
|
|
|
if (isset($extra['component']['name'])) { |
36
|
|
|
$packageName = $extra['component']['name']; |
37
|
|
|
} else { |
38
|
|
|
$packageName = explode('/', $package->getName())[1]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
if (!$moufManager->has("component.".$packageName)) { |
42
|
|
|
$componentViolations[] = $packageName; |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if (!$componentViolations) { |
|
|
|
|
48
|
|
|
return new MoufValidatorResult(MoufValidatorResult::SUCCESS, "<b>WebLibraryManager: </b>No missing WebLibrary for Bower or Components packages."); |
49
|
|
|
} else { |
50
|
|
|
return new MoufValidatorResult(MoufValidatorResult::ERROR, "<b>WebLibraryManager: </b>Missing matching WebLibrary for package(s) ".implode(', ', $componentViolations). |
51
|
|
|
"<div><a href='".MOUF_URL."assetsIntegration/fixAll' class='btn btn-success'>Click here to create all web-libraries matching these packages</a></div>"); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.