WebLibraryManagerInstaller   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 42
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B install() 0 35 6
1
<?php
2
/*
3
 * Copyright (c) 2013-2014 David Negrier
4
 * 
5
 * See the file LICENSE.txt for copying permission.
6
 */
7
8
namespace Mouf\Html\Utils\WebLibraryManager;
9
10
use Mouf\Installer\PackageInstallerInterface;
11
use Mouf\MoufManager;
12
use Mouf\Html\Renderer\RendererUtils;
13
14
/**
15
 * An installer class for the WebLibraryManager library.
16
 */
17
class WebLibraryManagerInstaller implements PackageInstallerInterface {
18
19
	/**
20
	 * (non-PHPdoc)
21
	 * @see \Mouf\Installer\PackageInstallerInterface::install()
22
	 */
23
	public static function install(MoufManager $moufManager) {
24
		// Let's create the instances
25
		if (!$moufManager->instanceExists("defaultWebLibraryManager")) {
26
			$defaultWebLibraryManager = $moufManager->createInstance("Mouf\\Html\\Utils\\WebLibraryManager\\WebLibraryManager");
27
			$defaultWebLibraryManager->setName("defaultWebLibraryManager");
28
			
29
			if (!$moufManager->instanceExists("rootUrlInlineWebLibrary")) {
30
				if (!$moufManager->instanceExists("rootUrlJsFile")) {
31
					$rootUrlJsFile = $moufManager->createInstance("Mouf\\Html\\HtmlElement\\HtmlFromFile");
32
					$rootUrlJsFile->setName("rootUrlJsFile");
33
					$rootUrlJsFile->getProperty("fileName")->setValue("vendor/mouf/html.utils.weblibrarymanager/javascript/rootUrl.php");
34
				} else {
35
					$rootUrlJsFile = $moufManager->getInstanceDescriptor("rootUrlJsFile");
36
				}
37
			
38
				$rootUrl = $moufManager->createInstance("Mouf\\Html\\Utils\\WebLibraryManager\\InlineWebLibrary");
39
				$rootUrl->setName("rootUrlInlineWebLibrary");
40
				$rootUrl->getProperty("jsElement")->setValue($rootUrlJsFile);
41
			
42
				$defaultWebLibraryManager->getProperty("webLibraries")->setValue(array($rootUrl));
43
			}
44
		} else {
45
			$defaultWebLibraryManager = $moufManager->getInstanceDescriptor('defaultWebLibraryManager');
46
		}
47
48
		if ($moufManager->has("defaultRenderer") && $defaultWebLibraryManager->getConstructorArgumentProperty("renderer")->getValue() === null) {
49
			$defaultWebLibraryManager->getConstructorArgumentProperty("renderer")->setValue($moufManager->getInstanceDescriptor('defaultRenderer'));
50
		}
51
		
52
		
53
		RendererUtils::createPackageRenderer($moufManager, "mouf/html.utils.weblibrarymanager");
54
		
55
		// Let's rewrite the MoufComponents.php file to save the component
56
		$moufManager->rewriteMouf();
57
	}
58
}
59