| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * ownCloud - Richdocuments App | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @author Victor Dubiniuk | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @copyright 2015 Victor Dubiniuk [email protected] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * This file is licensed under the Affero General Public License version 3 or | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * later. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace OCA\Richdocuments; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use OCA\Richdocuments\AppInfo\Application; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use \OCP\IConfig; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | class AppConfig { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	private $defaults = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 		'wopi_url' => 'https://localhost:9980', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 		'watermark_text' => '{userId}', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 		'watermark_allGroupsList' => [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 		'watermark_allTagsList' => [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 		'watermark_linkTagsList' => [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 	]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	const WATERMARK_APP_NAMESPACE = 'files'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	const APP_SETTING_TYPES = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 			'watermark_allGroupsList' => 'array', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 			'watermark_allTagsList' => 'array', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 			'watermark_linkTagsList' => 'array' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	/** @var IConfig */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	private $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	public function __construct(IConfig $config) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 		$this->config = $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	public function getAppNamespace($key) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		if (strpos($key, 'watermark_') === 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 			return self::WATERMARK_APP_NAMESPACE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 		return Application::APPNAME; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 	 * Get a value by key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 	 * @param string $key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	public function getAppValue($key) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		$defaultValue = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		if (array_key_exists($key, $this->defaults)){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 			$defaultValue = $this->defaults[$key]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		return $this->config->getAppValue($this->getAppNamespace($key), $key, $defaultValue); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	 * @param $key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	 * @return array | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 66 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  | 	public function getAppValueArray($key) { | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  | 		$value = $this->config->getAppValue($this->getAppNamespace($key), $key, []); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  | 		if (self::APP_SETTING_TYPES[$key] === 'array') { | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  | 			$value = $value !== '' ? explode(',', $value) : []; | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  | 		return $value; | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 	 * Set a value by key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	 * @param string $key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 	 * @param string $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 	 * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 	public function setAppValue($key, $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 		$this->config->setAppValue($this->getAppNamespace($key), $key, $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	 * Get all app settings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	 * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 	public function getAppSettings() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 		$result = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 		$keys = $this->config->getAppKeys(Application::APPNAME); | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 92 |  | View Code Duplication | 		foreach ($keys as $key) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 			$value = $this->getAppValueArray($key); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 			$value = $value === 'yes' ? true : $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 			$result[$key] = $value === 'no' ? false : $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 		$keys = $this->config->getAppKeys(self::WATERMARK_APP_NAMESPACE); | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 99 |  | View Code Duplication | 		foreach ($keys as $key) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 			if (strpos($key, 'watermark_') === 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 				$value = $this->getAppValueArray($key); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 				$value = $value === 'yes' ? true : $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 				$result[$key] = $value === 'no' ? false : $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 		return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 109 |  |  |  } | 
            
                                                        
            
                                    
            
            
                | 110 |  |  |  | 
            
                        
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: