| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * The MIT License (MIT) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Copyright (c) 2015 zepi | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a copy | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * of this software and associated documentation files (the "Software"), to deal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * in the Software without restriction, including without limitation the rights | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * copies of the Software, and to permit persons to whom the Software is | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * furnished to do so, subject to the following conditions: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * The above copyright notice and this permission notice shall be included in | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * all copies or substantial portions of the Software. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * THE SOFTWARE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * The ModuleManager manages all modules in the framework. Please do | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  * not create an instance of the module manager. Use the framework to get  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * the ModuleManager instance. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * @package Zepi\Turbo\Manager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * @author Matthias Zobrist <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  * @copyright Copyright (c) 2015 zepi | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | namespace Zepi\Turbo\Manager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | use \Zepi\Turbo\Framework; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | use \Zepi\Turbo\Backend\ObjectBackendAbstract; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | use \Zepi\Turbo\Exception; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | use \Zepi\Turbo\Module\ModuleAbstract; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  * The ModuleManager manages all modules in the framework. Please do | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  * not create an instance of the module manager. Use the framework to get  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  * the ModuleManager instance. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  * @author Matthias Zobrist <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  * @copyright Copyright (c) 2015 zepi | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | class ModuleManager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * @var Framework | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     protected $framework; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @var \Zepi\Turbo\Backend\ObjectBackendAbstract | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     protected $moduleObjectBackend; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     protected $moduleDirectories = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     protected $activatedModules = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     protected $modules = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * Constructs the object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * @param \Zepi\Turbo\Framework $framework | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @param \Zepi\Turbo\Backend\ObjectBackendAbstract $moduleObjectBackend | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     public function __construct(Framework $framework, ObjectBackendAbstract $moduleObjectBackend) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $this->framework = $framework; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         $this->moduleObjectBackend = $moduleObjectBackend; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * Initializes the module system. Loads the activated modules from the  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * object backend and loads all modules. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     public function initializeModuleSystem() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         $activatedModules = $this->moduleObjectBackend->loadObject(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         if (!is_array($activatedModules)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |             $activatedModules = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         $this->activatedModules = $activatedModules; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         foreach ($this->activatedModules as $activatedModule) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |             $this->initializeModule($activatedModule['path']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      * Adds a directory as module directory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |      * @param string $directory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |      * @param string $excludePattern | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |      * @return boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     public function registerModuleDirectory($directory, $excludePattern = '/\/tests\//') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         if (!isset($this->moduleDirectories[$directory])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |             $this->moduleDirectories[$directory] = $excludePattern; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |              | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |             return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |      * Returns all activated modules. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     public function getModules() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |         return $this->modules; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |      * Returns the module for the given module namespace or false,  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |      * if the module wasn't initialized. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |      * @param string $namespace | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |      * @return ModuleAbstract|boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |     public function getModule($namespace) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         if (!isset($this->modules[$namespace])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |         return $this->modules[$namespace]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |      * Searches and activates the module with the given  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |      * namespace. The register method of the module will  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |      * be executed. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |      * @param string $namespace | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |      * @param boolean $activateDependencies | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |      * @return boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |      * @throws Zepi\Turbo\Exception Can not find the module "$namespace". | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |     public function activateModule($namespace, $activateDependencies = false) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |         $namespace = Framework::prepareNamespace($namespace); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |         // If the module already is activated we won't activate it again | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |         if (isset($this->activatedModules[$namespace])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |             return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         // Search the path for the module and initialize it | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |         $path = $this->searchModulePath($namespace); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |         if ($path === false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |             throw new Exception('Can not find the module "' . $namespace . '".'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |         // Get the version | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |         $moduleProperties = $this->parseModuleJson($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |         $version = $moduleProperties->module->version; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |         $module = $this->initializeModule($path, $activateDependencies); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |         $module->activate($version, 0); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |         // Save the path in the activated modules array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |         $this->activatedModules[$namespace] = array('version' => $version, 'path' => $path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |         $this->saveActivatedModules(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |      * Deactivates an activated module. The deregister method | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |      * of the module will be executed. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |      * @param string $namespace | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |      * @return boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |     public function deactivateModule($namespace) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |         $namespace = Framework::prepareNamespace($namespace); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |         // If the module isn't activated we have nothing to deactivate | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |         if (!isset($this->activatedModules[$namespace])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |         // Load the module to deactivate it | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |         $namespace = Framework::prepareNamespace($namespace); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |         $module = $this->getModule($namespace); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |         // If the module isn't initialized it isn't active | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |         if ($module === false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |         // Deactivate the module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |         $module->deactivate(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |         // Remove the module and save the module cache | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |         unset($this->activatedModules[$namespace]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |         unset($this->modules[$namespace]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |         $this->saveActivatedModules(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |      * Searches the module for the given class name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |      * @param string $className | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |      * @return boolean|Module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |     public function getModuleByClassName($className) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |         $longest = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |         $foundModule = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |         $className = Framework::prepareClassName($className); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |         foreach ($this->modules as $moduleNamespace => $module) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |             $moduleNamespace = Framework::prepareNamespace($moduleNamespace); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |             $sameNamespace = strpos($className, $moduleNamespace); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |             $length = strlen($moduleNamespace); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |             if ($sameNamespace !== false && $length > $longest) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |                 $longest = $length; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |                 $foundModule = $module; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |         return $foundModule; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |      * Iterates trough the modules and activates each of the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |      * modules. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |     public function reactivateModules() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |         foreach ($this->modules as $module) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |             $moduleProperties = $this->parseModuleJson($module->getDirectory()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |             $version = $moduleProperties->module->version; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |             $this->activateModule($moduleProperties->module->namespace, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |             $module->activate($version, $version); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |      * Returns an object with the properties for the given path. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |      * @param string $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |      * @return \stdClass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |     public function getModuleProperties($path) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |         return $this->parseModuleJson($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |      * Returns an object with the properties of the module from | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |      * the Module.json file in the given path. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |      * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |      * @param string $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |      * @return \stdClass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |      * @throws Zepi\Turbo\Exception Cannot find Module.json in the path "$path". | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |     protected function parseModuleJson($path) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |         if (!file_exists($path . '/Module.json')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |             throw new Exception('Cannot find Module.json in the path "' . $path . '".'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |         $moduleProperties = json_decode(file_get_contents($path . '/Module.json')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |         return $moduleProperties; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |      * Returns the namespace for the module in the given path. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |      * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |      * @param string $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |      * @throws Zepi\Turbo\Exception The namespace is not set in the module properties for the Module in "$path". | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |     protected function getNamespaceFromModuleJson($path) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  |         $moduleProperties = $this->parseModuleJson($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |         if (!isset($moduleProperties->module->namespace)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |             throw new Exception('The namespace is not set in the module properties for the module in "' . $path . '".'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |         return Framework::prepareNamespace($moduleProperties->module->namespace); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  |      * Initializes the module. This creates an new Module object if the  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  |      * given module path is valid. The function returns the initialized  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  |      * module or false, if the module can't be initialized. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |      * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  |      * @param string $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  |      * @param boolean $activateDependencies | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |      * @return ModuleAbstract | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  |      * @throws Zepi\Turbo\Exception The module "$path" is not valid | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  |     protected function initializeModule($path, $activateDependencies = false) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |         $moduleNamespace = $this->getNamespaceFromModuleJson($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |         $module = $this->getModule($moduleNamespace); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  |         // If the module is already initialized, return it | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |         if ($module instanceof ModuleAbstract) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  |             return $module; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  |         // Try to find and load the module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  |         if (!file_exists($path . '/Module.php')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  |             throw new Exception('The module "' . $path . '" is not valid!'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  |         // Look for dependencies and warn the user or activate the dependencies | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  |         $this->handleModuleDependencies($moduleNamespace, $path, $activateDependencies); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  |         // Load the module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  |         require_once($path . '/Module.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  |         $moduleClassName = Framework::prepareClassName($moduleNamespace . 'Module'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 |  |  |         // Initialize the module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 |  |  |         $module = new $moduleClassName($this->framework, $moduleNamespace, $path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 |  |  |         $this->modules[$moduleNamespace] = $module; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 377 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 378 |  |  |         $module->initialize(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 379 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 380 |  |  |         return $module; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 381 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 382 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 383 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 384 |  |  |      * Loads the Module.json and checks it for dependencies. If the module has | 
            
                                                                                                            
                            
            
                                    
            
            
                | 385 |  |  |      * dependencies the function will verify the modules and activate them | 
            
                                                                                                            
                            
            
                                    
            
            
                | 386 |  |  |      * if the parameter $activateDependencies is set to true. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 387 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 388 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 389 |  |  |      * @param string $moduleNamespace | 
            
                                                                                                            
                            
            
                                    
            
            
                | 390 |  |  |      * @param string $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 391 |  |  |      * @param boolean $activateDependencies | 
            
                                                                                                            
                            
            
                                    
            
            
                | 392 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 393 |  |  |     protected function handleModuleDependencies($moduleNamespace, $path, $activateDependencies) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 394 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 395 |  |  |         $moduleProperties = $this->parseModuleJson($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 396 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 397 |  |  |         // If the ini file has no dependencies we have nothing to do... | 
            
                                                                                                            
                            
            
                                    
            
            
                | 398 |  |  |         if (!isset($moduleProperties->dependencies) || count($moduleProperties->dependencies) === 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 399 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 400 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 401 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 402 |  |  |         foreach ($moduleProperties->dependencies as $type => $dependencies) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 403 |  |  |             switch ($type) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 404 |  |  |                 case 'required': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 405 |  |  |                     $this->handleRequiredDependencies($moduleNamespace, $dependencies, $activateDependencies); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 406 |  |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 407 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 408 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 409 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 410 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 411 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 412 |  |  |      * Handles all required dependencies. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 413 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 414 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 415 |  |  |      * @param string $moduleNamespace | 
            
                                                                                                            
                            
            
                                    
            
            
                | 416 |  |  |      * @param array $dependencies | 
            
                                                                                                            
                            
            
                                    
            
            
                | 417 |  |  |      * @param boolean $activateDependencies | 
            
                                                                                                            
                            
            
                                    
            
            
                | 418 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 419 |  |  |      * @throws Zepi\Turbo\Exception Can not activate the module "$moduleNamespace". The module requires the module "$dependencyModuleNamespace" which isn't activated. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 420 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 421 |  |  |     protected function handleRequiredDependencies($moduleNamespace, $dependencies, $activateDependencies) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 422 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 423 |  |  |         foreach ($dependencies as $dependencyModuleNamespace => $version) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 424 |  |  |             $dependencyModuleNamespace = Framework::prepareNamespace($dependencyModuleNamespace); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 425 |  |  |              | 
            
                                                                                                            
                            
            
                                    
            
            
                | 426 |  |  |             $module = $this->getModule($dependencyModuleNamespace); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 427 |  |  |             if ($module === false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 428 |  |  |                 if ($activateDependencies) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 429 |  |  |                     $this->activateModule($dependencyModuleNamespace, $activateDependencies); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 430 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 431 |  |  |                     throw new Exception('Can not activate the module "' . $moduleNamespace . '". The module requires the module "' . $dependencyModuleNamespace . '" which isn\'t activated.'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 432 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 433 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 434 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 435 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 436 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 437 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 438 |  |  |      * Iterates over the available module directories and searches the  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 439 |  |  |      * target namespace in the module directories. If the namespace is  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 440 |  |  |      * found the function return the path to the module. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 441 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 442 |  |  |      * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 443 |  |  |      * @param string $namespace | 
            
                                                                                                            
                            
            
                                    
            
            
                | 444 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 445 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 446 |  |  |     protected function searchModulePath($namespace) | 
            
                                                                        
                            
            
                                    
            
            
                | 447 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 448 |  |  |         $targetPath = false; | 
            
                                                                        
                            
            
                                    
            
            
                | 449 |  |  |          | 
            
                                                                        
                            
            
                                    
            
            
                | 450 |  |  |         // Iterate trough the module directories | 
            
                                                                        
                            
            
                                    
            
            
                | 451 |  |  |         foreach ($this->moduleDirectories as $directory => $excludePattern) { | 
            
                                                                        
                            
            
                                    
            
            
                | 452 |  |  |             $recursiveDirectoryIterator = new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS); | 
            
                                                                        
                            
            
                                    
            
            
                | 453 |  |  |             $iterator = new \RecursiveIteratorIterator($recursiveDirectoryIterator); | 
            
                                                                        
                            
            
                                    
            
            
                | 454 |  |  |             $regexIterator = new \RegexIterator($iterator, '/^.+\/Module\.json$/i'); | 
            
                                                                        
                            
            
                                    
            
            
                | 455 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 456 |  |  |             foreach ($regexIterator as $item) { | 
            
                                                                        
                            
            
                                    
            
            
                | 457 |  |  |                 // Ignore modules which are located inside a tests directory | 
            
                                                                        
                            
            
                                    
            
            
                | 458 |  |  |                 if ($excludePattern !== false && preg_match($excludePattern, $item->getPath())) { | 
            
                                                                        
                            
            
                                    
            
            
                | 459 |  |  |                     continue; | 
            
                                                                        
                            
            
                                    
            
            
                | 460 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 461 |  |  |                  | 
            
                                                                        
                            
            
                                    
            
            
                | 462 |  |  |                 $moduleNamespace = $this->getNamespaceFromModuleJson($item->getPath()); | 
            
                                                                        
                            
            
                                    
            
            
                | 463 |  |  |                  | 
            
                                                                        
                            
            
                                    
            
            
                | 464 |  |  |                 if ($moduleNamespace === $namespace) { | 
            
                                                                        
                            
            
                                    
            
            
                | 465 |  |  |                     $targetPath = $item->getPath(); | 
            
                                                                        
                            
            
                                    
            
            
                | 466 |  |  |                     break 2; | 
            
                                                                        
                            
            
                                    
            
            
                | 467 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 468 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 469 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 470 |  |  |          | 
            
                                                                        
                            
            
                                    
            
            
                | 471 |  |  |         return $targetPath; | 
            
                                                                        
                            
            
                                    
            
            
                | 472 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 473 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 474 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 475 |  |  |      * Saves the activated modules in the object backend. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 476 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 477 |  |  |      * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 478 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 479 |  |  |     protected function saveActivatedModules() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 480 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 481 |  |  |         $this->moduleObjectBackend->saveObject($this->activatedModules); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 482 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 483 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 484 |  |  |  |