| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Simple configuration container handling basic options parsing nad providing convenient methods. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 4 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 5 |  |  | class CodeReviewConfig { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 7 |  |  | 	const T_PLUGINS_ALL = 0; | 
            
                                                                        
                            
            
                                    
            
            
                | 8 |  |  | 	const T_PLUGINS_ACTIVE = 1; | 
            
                                                                        
                            
            
                                    
            
            
                | 9 |  |  | 	const T_PLUGINS_INACTIVE = 2; | 
            
                                                                        
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  | 	 * @var array | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | 	protected $options = array(); | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  | 	 * @param array $options | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 | 3 |  | 	public function __construct(array $options = array()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 | 3 |  | 		$this->options = (array)$options; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 21 | 3 |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  | 	 * @param $key | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  | 	 * @return mixed | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	public function __get($key) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 		return $this->options[$key]; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 29 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  | 	 * @param      $key | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  | 	 * @param null $default | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  | 	 * @return null | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 2 |  | 	public function getOption($key, $default = null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 2 |  | 		return isset($this->options[$key]) ? $this->options[$key] : $default; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 38 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  | 	 * @param $key | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  | 	 * @param $value | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	public function __set($key, $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		$this->options[$key] = $value; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 46 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  | 	 * @param $type | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  | 	 * @return array | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 1 |  | 	public function getPluginIds($type) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 1 |  | 		$pluginsDirs = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 1 |  | 		$config = code_review::getConfig(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		switch ($type) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 1 |  | 			case self::T_PLUGINS_INACTIVE: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 1 |  | 				$pluginsDirs = $this->getPluginIds(self::T_PLUGINS_ALL); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 1 |  | 				$actives = call_user_func($config['plugins_getter'], 'active'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 1 |  | 				foreach ($actives as $plugin) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 1 |  | 					if ($plugin instanceof ElggPlugin) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 						$pluginsDirs = array_diff($pluginsDirs, array($plugin->getID())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 					} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 1 |  | 						$pluginsDirs = array_diff($pluginsDirs, array($plugin)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 1 |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 1 |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 1 |  | 			case self::T_PLUGINS_ACTIVE: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 				$pluginsDirs = call_user_func($config['plugins_getter'], 'active'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 				foreach ($pluginsDirs as $key => $plugin) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 					if ($plugin instanceof ElggPlugin) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 						$pluginsDirs[$key] = $plugin->getID(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 1 |  | 			case self::T_PLUGINS_ALL: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 1 |  | 				$pluginsDirs = code_review::getPluginDirsInDir($config['pluginspath']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 1 |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 1 |  | 		return $pluginsDirs; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 83 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  | 	/* | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  | 	 * Shorthand methods | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  | 	 * @param array $vars | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 	public function parseInput(array $vars) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 		//sanitize provided path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 		$subPath = elgg_extract('subpath', $vars, '/'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 		$subPath = trim($subPath, '/\\'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 		$subPath = str_replace('\\', '/', $subPath); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 		$subPath = str_replace('..', '', $subPath); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 		$subPath = $subPath . '/'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 		$this->subPath = $subPath; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 		$this->maxVersion = elgg_extract('version', $vars); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 		$this->includeDisabledPlugins = elgg_extract('include_disabled_plugins', $vars, false); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 		$this->findDeprecatedFunctions = elgg_extract('find_deprecated_functions', $vars, true); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 		$this->findPrivateFunctions = elgg_extract('find_private_functions', $vars, true); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 		$this->fixProblems = elgg_extract('fix_problems', $vars); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 107 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  | 	 * @return bool | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 	public function isFixProblemsEnabled() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 		return (bool)$this->getOption('fixProblems', false); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 114 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  | 	 * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 	public function getMaxVersion() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 		if (!$this->maxVersion) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 			//TODO decouple Elgg core dependency | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 			return elgg_get_version(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 		return $this->maxVersion; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 125 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  | 	 * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 	public function getSubPath() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 		return (string)$this->subPath; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 132 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  | 	 * @return bool | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 | 2 |  | 	public function isIncludeDisabledPluginsEnabled() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 | 2 |  | 		return (bool)$this->getOption('includeDisabledPlugins', false); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 139 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  | 	 * @return bool | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 | 2 |  | 	public function isSkipInactivePluginsEnabled() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 | 2 |  | 		return !$this->isIncludeDisabledPluginsEnabled(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 146 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  | 	 * @return bool | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 	public function isDeprecatedFunctionsTestEnabled() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 		return (bool)$this->getOption('findDeprecatedFunctions', true); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 153 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  | 	 * @return bool | 
            
                                                                        
                            
            
                                    
            
            
                | 157 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 	public function isPrivateFunctionsTestEnabled() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 		return (bool)$this->getOption('findPrivateFunctions', true); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 160 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 161 |  |  | } | 
            
                        
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.