Completed
Push — master ( bb1af9...9932b7 )
by Lukas
77:15 queued 63:44
created
apps/user_ldap/lib/Proxy.php 2 patches
Indentation   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -35,170 +35,170 @@
 block discarded – undo
35 35
 use OCA\User_LDAP\User\Manager;
36 36
 
37 37
 abstract class Proxy {
38
-	static private $accesses = array();
39
-	private $ldap = null;
40
-
41
-	/** @var \OCP\ICache|null */
42
-	private $cache;
43
-
44
-	/**
45
-	 * @param ILDAPWrapper $ldap
46
-	 */
47
-	public function __construct(ILDAPWrapper $ldap) {
48
-		$this->ldap = $ldap;
49
-		$memcache = \OC::$server->getMemCacheFactory();
50
-		if($memcache->isAvailable()) {
51
-			$this->cache = $memcache->create();
52
-		}
53
-	}
54
-
55
-	/**
56
-	 * @param string $configPrefix
57
-	 */
58
-	private function addAccess($configPrefix) {
59
-		static $ocConfig;
60
-		static $fs;
61
-		static $log;
62
-		static $avatarM;
63
-		static $userMap;
64
-		static $groupMap;
65
-		static $db;
66
-		static $coreUserManager;
67
-		static $coreNotificationManager;
68
-		if($fs === null) {
69
-			$ocConfig = \OC::$server->getConfig();
70
-			$fs       = new FilesystemHelper();
71
-			$log      = new LogWrapper();
72
-			$avatarM  = \OC::$server->getAvatarManager();
73
-			$db       = \OC::$server->getDatabaseConnection();
74
-			$userMap  = new UserMapping($db);
75
-			$groupMap = new GroupMapping($db);
76
-			$coreUserManager = \OC::$server->getUserManager();
77
-			$coreNotificationManager = \OC::$server->getNotificationManager();
78
-		}
79
-		$userManager =
80
-			new Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(), $db,
81
-				$coreUserManager, $coreNotificationManager);
82
-		$connector = new Connection($this->ldap, $configPrefix);
83
-		$access = new Access($connector, $this->ldap, $userManager, new Helper(\OC::$server->getConfig()));
84
-		$access->setUserMapper($userMap);
85
-		$access->setGroupMapper($groupMap);
86
-		self::$accesses[$configPrefix] = $access;
87
-	}
88
-
89
-	/**
90
-	 * @param string $configPrefix
91
-	 * @return mixed
92
-	 */
93
-	protected function getAccess($configPrefix) {
94
-		if(!isset(self::$accesses[$configPrefix])) {
95
-			$this->addAccess($configPrefix);
96
-		}
97
-		return self::$accesses[$configPrefix];
98
-	}
99
-
100
-	/**
101
-	 * @param string $uid
102
-	 * @return string
103
-	 */
104
-	protected function getUserCacheKey($uid) {
105
-		return 'user-'.$uid.'-lastSeenOn';
106
-	}
107
-
108
-	/**
109
-	 * @param string $gid
110
-	 * @return string
111
-	 */
112
-	protected function getGroupCacheKey($gid) {
113
-		return 'group-'.$gid.'-lastSeenOn';
114
-	}
115
-
116
-	/**
117
-	 * @param string $id
118
-	 * @param string $method
119
-	 * @param array $parameters
120
-	 * @param bool $passOnWhen
121
-	 * @return mixed
122
-	 */
123
-	abstract protected function callOnLastSeenOn($id, $method, $parameters, $passOnWhen);
124
-
125
-	/**
126
-	 * @param string $id
127
-	 * @param string $method
128
-	 * @param array $parameters
129
-	 * @return mixed
130
-	 */
131
-	abstract protected function walkBackends($id, $method, $parameters);
132
-
133
-	/**
134
-	 * @param string $id
135
-	 * @return Access
136
-	 */
137
-	abstract public function getLDAPAccess($id);
138
-
139
-	/**
140
-	 * Takes care of the request to the User backend
141
-	 * @param string $id
142
-	 * @param string $method string, the method of the user backend that shall be called
143
-	 * @param array $parameters an array of parameters to be passed
144
-	 * @param bool $passOnWhen
145
-	 * @return mixed, the result of the specified method
146
-	 */
147
-	protected function handleRequest($id, $method, $parameters, $passOnWhen = false) {
148
-		$result = $this->callOnLastSeenOn($id,  $method, $parameters, $passOnWhen);
149
-		if($result === $passOnWhen) {
150
-			$result = $this->walkBackends($id, $method, $parameters);
151
-		}
152
-		return $result;
153
-	}
154
-
155
-	/**
156
-	 * @param string|null $key
157
-	 * @return string
158
-	 */
159
-	private function getCacheKey($key) {
160
-		$prefix = 'LDAP-Proxy-';
161
-		if($key === null) {
162
-			return $prefix;
163
-		}
164
-		return $prefix.md5($key);
165
-	}
166
-
167
-	/**
168
-	 * @param string $key
169
-	 * @return mixed|null
170
-	 */
171
-	public function getFromCache($key) {
172
-		if($this->cache === null) {
173
-			return null;
174
-		}
175
-
176
-		$key = $this->getCacheKey($key);
177
-		$value = $this->cache->get($key);
178
-		if ($value === null) {
179
-			return null;
180
-		}
181
-
182
-		return json_decode(base64_decode($value));
183
-	}
184
-
185
-	/**
186
-	 * @param string $key
187
-	 * @param mixed $value
188
-	 */
189
-	public function writeToCache($key, $value) {
190
-		if($this->cache === null) {
191
-			return;
192
-		}
193
-		$key   = $this->getCacheKey($key);
194
-		$value = base64_encode(json_encode($value));
195
-		$this->cache->set($key, $value, 2592000);
196
-	}
197
-
198
-	public function clearCache() {
199
-		if($this->cache === null) {
200
-			return;
201
-		}
202
-		$this->cache->clear($this->getCacheKey(null));
203
-	}
38
+    static private $accesses = array();
39
+    private $ldap = null;
40
+
41
+    /** @var \OCP\ICache|null */
42
+    private $cache;
43
+
44
+    /**
45
+     * @param ILDAPWrapper $ldap
46
+     */
47
+    public function __construct(ILDAPWrapper $ldap) {
48
+        $this->ldap = $ldap;
49
+        $memcache = \OC::$server->getMemCacheFactory();
50
+        if($memcache->isAvailable()) {
51
+            $this->cache = $memcache->create();
52
+        }
53
+    }
54
+
55
+    /**
56
+     * @param string $configPrefix
57
+     */
58
+    private function addAccess($configPrefix) {
59
+        static $ocConfig;
60
+        static $fs;
61
+        static $log;
62
+        static $avatarM;
63
+        static $userMap;
64
+        static $groupMap;
65
+        static $db;
66
+        static $coreUserManager;
67
+        static $coreNotificationManager;
68
+        if($fs === null) {
69
+            $ocConfig = \OC::$server->getConfig();
70
+            $fs       = new FilesystemHelper();
71
+            $log      = new LogWrapper();
72
+            $avatarM  = \OC::$server->getAvatarManager();
73
+            $db       = \OC::$server->getDatabaseConnection();
74
+            $userMap  = new UserMapping($db);
75
+            $groupMap = new GroupMapping($db);
76
+            $coreUserManager = \OC::$server->getUserManager();
77
+            $coreNotificationManager = \OC::$server->getNotificationManager();
78
+        }
79
+        $userManager =
80
+            new Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(), $db,
81
+                $coreUserManager, $coreNotificationManager);
82
+        $connector = new Connection($this->ldap, $configPrefix);
83
+        $access = new Access($connector, $this->ldap, $userManager, new Helper(\OC::$server->getConfig()));
84
+        $access->setUserMapper($userMap);
85
+        $access->setGroupMapper($groupMap);
86
+        self::$accesses[$configPrefix] = $access;
87
+    }
88
+
89
+    /**
90
+     * @param string $configPrefix
91
+     * @return mixed
92
+     */
93
+    protected function getAccess($configPrefix) {
94
+        if(!isset(self::$accesses[$configPrefix])) {
95
+            $this->addAccess($configPrefix);
96
+        }
97
+        return self::$accesses[$configPrefix];
98
+    }
99
+
100
+    /**
101
+     * @param string $uid
102
+     * @return string
103
+     */
104
+    protected function getUserCacheKey($uid) {
105
+        return 'user-'.$uid.'-lastSeenOn';
106
+    }
107
+
108
+    /**
109
+     * @param string $gid
110
+     * @return string
111
+     */
112
+    protected function getGroupCacheKey($gid) {
113
+        return 'group-'.$gid.'-lastSeenOn';
114
+    }
115
+
116
+    /**
117
+     * @param string $id
118
+     * @param string $method
119
+     * @param array $parameters
120
+     * @param bool $passOnWhen
121
+     * @return mixed
122
+     */
123
+    abstract protected function callOnLastSeenOn($id, $method, $parameters, $passOnWhen);
124
+
125
+    /**
126
+     * @param string $id
127
+     * @param string $method
128
+     * @param array $parameters
129
+     * @return mixed
130
+     */
131
+    abstract protected function walkBackends($id, $method, $parameters);
132
+
133
+    /**
134
+     * @param string $id
135
+     * @return Access
136
+     */
137
+    abstract public function getLDAPAccess($id);
138
+
139
+    /**
140
+     * Takes care of the request to the User backend
141
+     * @param string $id
142
+     * @param string $method string, the method of the user backend that shall be called
143
+     * @param array $parameters an array of parameters to be passed
144
+     * @param bool $passOnWhen
145
+     * @return mixed, the result of the specified method
146
+     */
147
+    protected function handleRequest($id, $method, $parameters, $passOnWhen = false) {
148
+        $result = $this->callOnLastSeenOn($id,  $method, $parameters, $passOnWhen);
149
+        if($result === $passOnWhen) {
150
+            $result = $this->walkBackends($id, $method, $parameters);
151
+        }
152
+        return $result;
153
+    }
154
+
155
+    /**
156
+     * @param string|null $key
157
+     * @return string
158
+     */
159
+    private function getCacheKey($key) {
160
+        $prefix = 'LDAP-Proxy-';
161
+        if($key === null) {
162
+            return $prefix;
163
+        }
164
+        return $prefix.md5($key);
165
+    }
166
+
167
+    /**
168
+     * @param string $key
169
+     * @return mixed|null
170
+     */
171
+    public function getFromCache($key) {
172
+        if($this->cache === null) {
173
+            return null;
174
+        }
175
+
176
+        $key = $this->getCacheKey($key);
177
+        $value = $this->cache->get($key);
178
+        if ($value === null) {
179
+            return null;
180
+        }
181
+
182
+        return json_decode(base64_decode($value));
183
+    }
184
+
185
+    /**
186
+     * @param string $key
187
+     * @param mixed $value
188
+     */
189
+    public function writeToCache($key, $value) {
190
+        if($this->cache === null) {
191
+            return;
192
+        }
193
+        $key   = $this->getCacheKey($key);
194
+        $value = base64_encode(json_encode($value));
195
+        $this->cache->set($key, $value, 2592000);
196
+    }
197
+
198
+    public function clearCache() {
199
+        if($this->cache === null) {
200
+            return;
201
+        }
202
+        $this->cache->clear($this->getCacheKey(null));
203
+    }
204 204
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	public function __construct(ILDAPWrapper $ldap) {
48 48
 		$this->ldap = $ldap;
49 49
 		$memcache = \OC::$server->getMemCacheFactory();
50
-		if($memcache->isAvailable()) {
50
+		if ($memcache->isAvailable()) {
51 51
 			$this->cache = $memcache->create();
52 52
 		}
53 53
 	}
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 		static $db;
66 66
 		static $coreUserManager;
67 67
 		static $coreNotificationManager;
68
-		if($fs === null) {
68
+		if ($fs === null) {
69 69
 			$ocConfig = \OC::$server->getConfig();
70 70
 			$fs       = new FilesystemHelper();
71 71
 			$log      = new LogWrapper();
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 * @return mixed
92 92
 	 */
93 93
 	protected function getAccess($configPrefix) {
94
-		if(!isset(self::$accesses[$configPrefix])) {
94
+		if (!isset(self::$accesses[$configPrefix])) {
95 95
 			$this->addAccess($configPrefix);
96 96
 		}
97 97
 		return self::$accesses[$configPrefix];
@@ -145,8 +145,8 @@  discard block
 block discarded – undo
145 145
 	 * @return mixed, the result of the specified method
146 146
 	 */
147 147
 	protected function handleRequest($id, $method, $parameters, $passOnWhen = false) {
148
-		$result = $this->callOnLastSeenOn($id,  $method, $parameters, $passOnWhen);
149
-		if($result === $passOnWhen) {
148
+		$result = $this->callOnLastSeenOn($id, $method, $parameters, $passOnWhen);
149
+		if ($result === $passOnWhen) {
150 150
 			$result = $this->walkBackends($id, $method, $parameters);
151 151
 		}
152 152
 		return $result;
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 	 */
159 159
 	private function getCacheKey($key) {
160 160
 		$prefix = 'LDAP-Proxy-';
161
-		if($key === null) {
161
+		if ($key === null) {
162 162
 			return $prefix;
163 163
 		}
164 164
 		return $prefix.md5($key);
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 	 * @return mixed|null
170 170
 	 */
171 171
 	public function getFromCache($key) {
172
-		if($this->cache === null) {
172
+		if ($this->cache === null) {
173 173
 			return null;
174 174
 		}
175 175
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 	 * @param mixed $value
188 188
 	 */
189 189
 	public function writeToCache($key, $value) {
190
-		if($this->cache === null) {
190
+		if ($this->cache === null) {
191 191
 			return;
192 192
 		}
193 193
 		$key   = $this->getCacheKey($key);
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 	}
197 197
 
198 198
 	public function clearCache() {
199
-		if($this->cache === null) {
199
+		if ($this->cache === null) {
200 200
 			return;
201 201
 		}
202 202
 		$this->cache->clear($this->getCacheKey(null));
Please login to merge, or discard this patch.