1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright (c) 2013-2015 David Negrier |
4
|
|
|
* |
5
|
|
|
* See the file LICENSE.txt for copying permission. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Mouf\Html\Renderer\Twig; |
9
|
|
|
|
10
|
|
|
use Mouf\Installer\PackageInstallerInterface; |
11
|
|
|
use Mouf\MoufManager; |
12
|
|
|
use Mouf\Actions\InstallUtils; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* An installer class |
16
|
|
|
*/ |
17
|
|
|
class MoufTwigEnvironmentInstaller2 implements PackageInstallerInterface |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
public static function install(MoufManager $moufManager) |
21
|
|
|
{ |
22
|
|
|
// Let's create the instances. |
23
|
|
|
$twigLoaderFileSystem = InstallUtils::getOrCreateInstance('twigLoaderFileSystem', 'Twig_Loader_Filesystem', $moufManager); |
24
|
|
|
$twigEnvironment = InstallUtils::getOrCreateInstance('twigEnvironment', 'Mouf\\Html\\Renderer\\Twig\\MoufTwigEnvironment', $moufManager); |
25
|
|
|
$twigDebugExtension = InstallUtils::getOrCreateInstance('twigDebugExtension', 'Twig_Extension_Debug', $moufManager); |
26
|
|
|
$moufTwigExtension = InstallUtils::getOrCreateInstance('moufTwigExtension', 'Mouf\\Html\\Renderer\\Twig\\MoufTwigExtension', $moufManager); |
27
|
|
|
$twigCacheFileSystem = InstallUtils::getOrCreateInstance('twigCacheFileSystem', 'Twig_Cache_Filesystem', $moufManager); |
28
|
|
|
|
29
|
|
|
// Let's bind instances together. |
30
|
|
|
$twigLoaderFileSystem->getConstructorArgumentProperty('paths')->setValue('return ROOT_PATH;'); |
31
|
|
|
$twigLoaderFileSystem->getConstructorArgumentProperty('paths')->setOrigin("php"); |
32
|
|
|
|
33
|
|
|
$twigEnvironment->getConstructorArgumentProperty('loader')->setValue($twigLoaderFileSystem); |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
$twigEnvironment->getConstructorArgumentProperty('options')->setValue('return array(\'debug\' => DEBUG, \'auto_reload\' => true);'); |
37
|
|
|
$twigEnvironment->getConstructorArgumentProperty('options')->setOrigin("php"); |
38
|
|
|
|
39
|
|
|
if (!$twigEnvironment->getSetterProperty('setExtensions')->isValueSet()) { |
40
|
|
|
$twigEnvironment->getSetterProperty('setExtensions')->setValue(array(0 => $moufTwigExtension, 1 => $twigDebugExtension, )); |
41
|
|
|
} |
42
|
|
|
if (!$twigEnvironment->getSetterProperty('setCache')->isValueSet()) { |
43
|
|
|
$twigEnvironment->getSetterProperty('setCache')->setValue($twigCacheFileSystem); |
44
|
|
|
} |
45
|
|
View Code Duplication |
if (!$moufTwigExtension->getConstructorArgumentProperty('container')->isValueSet()) { |
|
|
|
|
46
|
|
|
$moufTwigExtension->getConstructorArgumentProperty('container')->setValue('return $container;'); |
47
|
|
|
$moufTwigExtension->getConstructorArgumentProperty('container')->setOrigin("php"); |
48
|
|
|
} |
49
|
|
View Code Duplication |
if (!$twigCacheFileSystem->getConstructorArgumentProperty('directory')->isValueSet()) { |
|
|
|
|
50
|
|
|
$twigCacheFileSystem->getConstructorArgumentProperty('directory')->setValue('// If we are running on a Unix environment, let\'s prepend the cache with the user id of the PHP process. |
51
|
|
|
// This way, we can avoid rights conflicts. |
52
|
|
|
if (function_exists(\'posix_geteuid\')) { |
53
|
|
|
$posixGetuid = posix_geteuid(); |
54
|
|
|
} else { |
55
|
|
|
$posixGetuid = \'\'; |
56
|
|
|
} |
57
|
|
|
return rtrim(sys_get_temp_dir(), \'/\\\\\').\'/mouftwigtemplatemain_\'.$posixGetuid.str_replace(":", "", ROOT_PATH);'); |
58
|
|
|
$twigCacheFileSystem->getConstructorArgumentProperty('directory')->setOrigin("php"); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// Let's rewrite the MoufComponents.php file to save the component |
62
|
|
|
$moufManager->rewriteMouf(); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
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.